about summary refs log tree commit diff
path: root/tools/nixery/server/builder/state.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-09-30T16·38+0100
committerVincent Ambo <github@tazj.in>2019-10-03T12·21+0100
commit61269175c046681711cf88370d220eb97cd621cf (patch)
tree5027172f72c2b36440279970afa2dcf0acccb557 /tools/nixery/server/builder/state.go
parent6e2b84f475fb302bf6d8a43c2f7497040ad82cac (diff)
refactor(server): Introduce a state type to carry runtime state
The state type contains things such as the bucket handle and Nixery's
configuration which need to be passed around in the builder.

This is only added for convenience.
Diffstat (limited to 'tools/nixery/server/builder/state.go')
-rw-r--r--tools/nixery/server/builder/state.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/nixery/server/builder/state.go b/tools/nixery/server/builder/state.go
new file mode 100644
index 000000000000..1c7f58821b6b
--- /dev/null
+++ b/tools/nixery/server/builder/state.go
@@ -0,0 +1,24 @@
+package builder
+
+import (
+	"cloud.google.com/go/storage"
+	"github.com/google/nixery/config"
+	"github.com/google/nixery/layers"
+)
+
+// State holds the runtime state that is carried around in Nixery and
+// passed to builder functions.
+type State struct {
+	Bucket *storage.BucketHandle
+	Cache  LocalCache
+	Cfg    config.Config
+	Pop    layers.Popularity
+}
+
+func NewState(bucket *storage.BucketHandle, cfg config.Config) State {
+	return State{
+		Bucket: bucket,
+		Cfg:    cfg,
+		Cache:  NewCache(),
+	}
+}