@@ -21,6 +21,8 @@ import (
2121 "zb.256lights.llc/pkg/zbstore"
2222)
2323
24+ // globalConfig is the set of configuration settings and persistent command-line flags.
25+ // More details at https://main--zb-docs.netlify.app/configuration
2426type globalConfig struct {
2527 Debug bool `json:"debug"`
2628 Directory zbstore.Directory `json:"storeDirectory"`
@@ -30,14 +32,16 @@ type globalConfig struct {
3032 TrustedPublicKeys []* zbstore.RealizationPublicKey `json:"trustedPublicKeys"`
3133}
3234
33- // defaultGlobalConfig returns
35+ // defaultGlobalConfig returns a [globalConfig] populated with default values based on OS,
36+ // but does not reference any environment variables.
3437func defaultGlobalConfig () * globalConfig {
3538 return & globalConfig {
3639 Directory : zbstore .DefaultDirectory (),
3740 StoreSocket : filepath .Join (defaultVarDir (), "server.sock" ),
3841 }
3942}
4043
44+ // mergeEnvironment copies environment variable values to [globalConfig] fields.
4145func (g * globalConfig ) mergeEnvironment () error {
4246 if dir := os .Getenv ("ZB_STORE_DIR" ); dir != "" {
4347 zbDir , err := zbstore .CleanDirectory (dir )
@@ -58,6 +62,9 @@ func (g *globalConfig) mergeEnvironment() error {
5862 return nil
5963}
6064
65+ // mergeFiles parses each path as JSON With Commas and Comments
66+ // and merges each into g.
67+ // Thus, later files in the paths sequence take precedence over earlier files.
6168func (g * globalConfig ) mergeFiles (paths iter.Seq [string ]) error {
6269 for path := range paths {
6370 huJSONData , err := os .ReadFile (path )
@@ -141,6 +148,9 @@ func (g *globalConfig) UnmarshalJSONFrom(in *jsontext.Decoder) error {
141148 }
142149}
143150
151+ // validate checks the configuration for any missing or semantically incorrect settings.
152+ // validate should be called after the configuration is complete,
153+ // because partial configurations may not pass validation.
144154func (g * globalConfig ) validate () error {
145155 if ! filepath .IsAbs (string (g .Directory )) {
146156 // The directory must be in the format of the local OS.
0 commit comments