Copyright 2020 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Package dynconfig supports dynamic configuration for pkgsite services. Dynamic configuration is read from a file and can change over the lifetime of the process.
package dynconfig

import (
	
	
	
	
	
	

	
	
	
	
	
)
DynamicConfig holds configuration that can change over the lifetime of the process. It is loaded from a GCS file or other external source.
Fields can be added at any time, but removing or changing a field requires careful coordination with the config file contents.
Read reads dynamic configuration from the given location. Location may be of the form gs://bucket/object, denoting a GCS bucket. Otherwise it is interpreted as a filename.
func ( context.Context,  string) ( *DynamicConfig,  error) {
	defer derrors.Wrap(&, "dynconfig.Read(%q)", )

	log.Infof(, "reading dynamic config from %s", )
	var  io.ReadCloser
	if strings.HasPrefix(, "gs://") {
		 := strings.SplitN([5:], "/", 2)
		if len() != 2 {
			return nil, errors.New("bad GCS URL")
		}
		 := [0]
		 := [1]
		if  != nil {
			return nil, 
		}
		,  := storage.NewClient()
		if  != nil {
			return nil, 
		}
		defer .Close()
		,  = .Bucket().Object().NewReader()
		if  != nil {
			return nil, 
		}
	} else {
		,  = os.Open()
		if  != nil {
			return nil, 
		}
	}
	defer .Close()
	,  := ioutil.ReadAll()
	if  != nil {
		return nil, 
	}
	return Parse()
}
Parse parses yamlData as a YAML description of DynamicConfig.
func ( []byte) ( *DynamicConfig,  error) {
	defer derrors.Wrap(&, "dynconfig.Parse(data)")

	var  DynamicConfig
	if  := yaml.Unmarshal(, &);  != nil {
		return nil, 
	}
	return &, nil