Skip to content
Permalink
Browse files

refactor: adapt to changes of modules

  • Loading branch information...
aofei committed Jun 7, 2019
1 parent 960fa02 commit 77bc01db6d759c0dc174c7c328ee6278954dabe9
Showing with 87 additions and 118 deletions.
  1. +30 −15 cfg/cfg.go
  2. +4 −7 config.toml
  3. +2 −2 go.mod
  4. +47 −74 go.sum
  5. +4 −4 handlers/handlers.go
  6. +0 −16 main.go
@@ -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 (
@@ -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.
@@ -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"`
}
)

@@ -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",
@@ -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
}
@@ -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 go.mod
@@ -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
)

0 comments on commit 77bc01d

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