Skip to content
Permalink
Browse files

refactor: improve config management

  • Loading branch information...
aofei committed Aug 13, 2019
1 parent 0619834 commit 531b6671e6c81ab47a092c958abcb38520252b7e
Showing with 35 additions and 20 deletions.
  1. +22 −12 cfg/cfg.go
  2. +9 −4 config.toml
  3. +4 −4 handler/handler.go
@@ -24,22 +24,25 @@ var (
LoggerLevel string `mapstructure:"logger_level"`
}

// Goproxy is the Goproxy configuration items.
Goproxy struct {
// GoBinName is the name of the Go binary of the Goproxy.
GoBinName string `mapstructure:"go_bin_name"`
// Kodo is the Qiniu Cloud Kodo configuration items.
Kodo struct {
// Endpoint is the endpoint of the Qiniu Cloud Kodo.
Endpoint string `mapstructure:"endpoint"`

// KodoEndpoint is the endpoint of the Qiniu Cloud Kodo.
KodoEndpoint string `mapstructure:"kodo_endpoint"`
// AccessKey is the access key of the Qiniu Cloud Kodo.
AccessKey string `mapstructure:"access_key"`

// KodoAccessKey is the access key of the Qiniu Cloud Kodo.
KodoAccessKey string `mapstructure:"kodo_access_key"`
// SecretKey is the secret key of the Qiniu Cloud Kodo.
SecretKey string `mapstructure:"secret_key"`

// KodoSecretKey is the secret key of the Qiniu Cloud Kodo.
KodoSecretKey string `mapstructure:"kodo_secret_key"`
// BucketName is the bucket name of the Qiniu Cloud Kodo.
BucketName string `mapstructure:"bucket_name"`
}

// KodoBucketName is the bucket name of the Qiniu Cloud Kodo.
KodoBucketName string `mapstructure:"kodo_bucket_name"`
// Goproxy is the Goproxy configuration items.
Goproxy struct {
// GoBinName is the name of the Go binary of the Goproxy.
GoBinName string `mapstructure:"go_bin_name"`
}
)

@@ -71,6 +74,13 @@ func init() {
))
}

if err := mapstructure.Decode(m["kodo"], &Kodo); err != nil {
panic(fmt.Errorf(
"failed to decode kodo configuration items: %v",
err,
))
}

if err := mapstructure.Decode(m["goproxy"], &Goproxy); err != nil {
panic(fmt.Errorf(
"failed to decode goproxy configuration items: %v",
@@ -5,15 +5,20 @@ debug_mode = true
address = "localhost:8080"
minifier_enabled = true
gzip_enabled = true
coffer_enabled = true
i18n_enabled = true

# Zerolog
[zerolog]
logger_level = "debug"

# Qiniu Cloud Kodo
[kodo]
endpoint = "<ENDPOINT>"
access_key = "<ACCESS_KEY>"
secret_key = "<SECRET_KEY>"
bucket_name = "<BUCKET_NAME>"

# Goproxy
[goproxy]
go_bin_name = "go"
kodo_endpoint = "<KODO_ENDPOINT>"
kodo_access_key = "<KODO_ACCESS_KEY>"
kodo_secret_key = "<KODO_SECRET_KEY>"
kodo_bucket_name = "<KODO_BUCKET_NAME>"
@@ -29,10 +29,10 @@ func init() {
g := goproxy.New()
g.GoBinName = cfg.Goproxy.GoBinName
g.Cacher = &cacher.Kodo{
Endpoint: cfg.Goproxy.KodoEndpoint,
AccessKey: cfg.Goproxy.KodoAccessKey,
SecretKey: cfg.Goproxy.KodoSecretKey,
BucketName: cfg.Goproxy.KodoBucketName,
Endpoint: cfg.Kodo.Endpoint,
AccessKey: cfg.Kodo.AccessKey,
SecretKey: cfg.Kodo.SecretKey,
BucketName: cfg.Kodo.BucketName,
}

g.ErrorLogger = a.ErrorLogger

0 comments on commit 531b667

Please sign in to comment.
You can’t perform that action at this time.