You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/conf
Kevin Wan d935c83a54
feat: support baggage propagation in httpc (#2375)
* feat: support baggage propagation in httpc

* chore: use go 1.16

* chore: use go 1.16

* chore: use go ^1.16

* chore: remove deprecated
2 years ago
..
config.go feat: support baggage propagation in httpc (#2375) 2 years ago
config_test.go feat: support baggage propagation in httpc (#2375) 2 years ago
options.go fix golint issues in core/conf (#476) 4 years ago
properties.go feat: rename module from tal-tech to zeromicro (#1413) 3 years ago
properties_test.go feat: rename module from tal-tech to zeromicro (#1413) 3 years ago
readme.md Update readme.md 3 years ago

readme.md

How to use

  1. Define a config structure, like below:
type RestfulConf struct {
	Host         string        `json:",default=0.0.0.0"`
	Port         int
	LogMode      string        `json:",options=[file,console]"`
	Verbose      bool          `json:",optional"`
	MaxConns     int           `json:",default=10000"`
	MaxBytes     int64         `json:",default=1048576"`
	Timeout      time.Duration `json:",default=3s"`
	CpuThreshold int64         `json:",default=900,range=[0:1000]"`
}
  1. Write the yaml, toml or json config file:
  • yaml example
# most fields are optional or have default values
Port: 8080
LogMode: console
# you can use env settings
MaxBytes: ${MAX_BYTES}
  • toml example
# most fields are optional or have default values
Port = 8_080
LogMode = "console"
# you can use env settings
MaxBytes = "${MAX_BYTES}"
  1. Load the config from a file:
// exit on error
var config RestfulConf
conf.MustLoad(configFile, &config)

// or handle the error on your own
var config RestfulConf
if err := conf.Load(configFile, &config); err != nil {
  log.Fatal(err)
}

// enable reading from environments
var config RestfulConf
conf.MustLoad(configFile, &config, conf.UseEnv())