Skip to content

Commit

Permalink
refactor: adapt to changes of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aofei committed Jun 7, 2019
1 parent 960fa02 commit 77bc01d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 118 deletions.
45 changes: 30 additions & 15 deletions cfg/cfg.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package cfg

import (
"errors"
"flag"
"fmt"
stdLog "log"
"strings"

"github.com/BurntSushi/toml"
"github.com/aofei/air"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

var (
Expand All @@ -20,21 +24,6 @@ var (
LoggerLevel string `mapstructure:"logger_level"`
}

// Qiniu is the Qiniu configuration items.
Qiniu struct {
// AccessKey is the access key of the Qiniu.
AccessKey string `mapstructure:"access_key"`

// SecretKey is the secret key of the Qiniu.
SecretKey string `mapstructure:"secret_key"`

// BucketName is the bucket name of the Qiniu.
BucketName string `mapstructure:"bucket_name"`

// BucketEndpoint is the bucket endpoint of the Qiniu.
BucketEndpoint string `mapstructure:"bucket_endpoint"`
}

// Goproxy is the Goproxy configuration items.
Goproxy struct {
// GoBinName is the name of the Go binary of the Goproxy.
Expand All @@ -48,6 +37,18 @@ var (
// SupportedSUMDBHosts is the supported checksum database host
// of the Goproxy.
SupportedSUMDBHosts []string `mapstructure:"supported_sumdb_hosts"`

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

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

// KodoSecretKey is the secret key of the Qiniu Cloud Kodo.
KodoSecretKey string `mapstructure:"kodo_secret_key"`

// KodoBucketName is the bucket name of the Qiniu Cloud Kodo.
KodoBucketName string `mapstructure:"kodo_bucket_name"`
}
)

Expand All @@ -70,6 +71,8 @@ func init() {
))
}

a.ErrorLogger = stdLog.New(&errorLogWriter{}, "", 0)

if err := mapstructure.Decode(m["zerolog"], &Zerolog); err != nil {
panic(fmt.Errorf(
"failed to decode zerolog configuration items: %v",
Expand Down Expand Up @@ -108,3 +111,15 @@ func init() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
}

// errorLogWriter is an error log writer.
type errorLogWriter struct{}

// Write implements the `io.Writer`.
func (elw *errorLogWriter) Write(b []byte) (int, error) {
log.Error().Err(errors.New(strings.TrimSuffix(string(b), "\n"))).
Str("app_name", a.AppName).
Msg("air error")

return len(b), nil
}
11 changes: 4 additions & 7 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ gzip_enabled = true
[zerolog]
logger_level = "debug"

# Qiniu
[qiniu]
access_key = "<ACCESS_KEY>"
secret_key = "<SECRET_KEY>"
bucket_name = "<BUCKET_NAME>"
bucket_endpoint = "<BUCKET_ENDPOINT>"

# Goproxy
[goproxy]
go_bin_name = "go"
max_go_bin_workers = 8
supported_sumdb_hosts = ["sum.golang.org"]
kodo_endponit = "<KODO_ENDPOINT>"
kodo_access_key = "<KODO_ACCESS_KEY>"
kodo_secret_key = "<KODO_SECRET_KEY>"
kodo_bucket_name = "<KODO_BUCKET_NAME>"
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/air-gases/logger v0.11.2
github.com/air-gases/redirector v0.11.2
github.com/aofei/air v0.11.2
github.com/goproxy/goproxy v0.0.0-20190605154510-cfa5347fd501
github.com/goproxy/goproxy v0.0.0-20190607185343-09c1d800c427
github.com/mitchellh/mapstructure v1.1.2
github.com/rs/zerolog v1.14.3
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 // indirect
google.golang.org/appengine v1.6.1 // indirect
)
Loading

0 comments on commit 77bc01d

Please sign in to comment.