From 4b032dabcadc99e230a8ce01c6a95af283e6aab7 Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:03:17 +0800 Subject: [PATCH] refactor: use fiber drop-in replace gin --- cache/base.go | 5 +- consts/context.go | 9 ++++ controllers/v1/ping.go | 6 +-- controllers/v1/statistic.go | 9 ++-- flag/do.go | 11 ++--- go.mod | 36 ++++++-------- go.sum | 95 +++++++++---------------------------- logging/init.go | 2 +- logging/logger.go | 34 ------------- main.go | 34 +++++-------- middlewares/cors.go | 19 ++++---- middlewares/logger.go | 31 ++++++++++++ middlewares/session.go | 15 ------ middlewares/tracing.go | 21 ++++++++ prestart/do.go | 10 ++++ routes/base.go | 59 ++++++++++++----------- routes/router.go | 28 +++++------ task/run.go | 3 +- task/status/request.go | 1 + util/web/bearer.go | 13 ++--- util/web/response.go | 32 ++++++------- util/web/token.go | 4 +- 22 files changed, 213 insertions(+), 264 deletions(-) create mode 100644 consts/context.go create mode 100644 middlewares/logger.go delete mode 100644 middlewares/session.go create mode 100644 middlewares/tracing.go diff --git a/cache/base.go b/cache/base.go index 2ad2442..f613467 100644 --- a/cache/base.go +++ b/cache/base.go @@ -15,9 +15,10 @@ var Collection *cache.Cache // DataFilePath 是缓存记录文件地址 var DataFilePath = filepath.Join(util.MustGetExecDir(), "cache.data") -// init 用于初始化缓存驱动 -func init() { +// LoadFromDisk 用于初始化缓存驱动 +func LoadFromDisk() { defer zap.L().Sync() + Collection = cache.New(5*time.Minute, 10*time.Minute) zap.L().Debug("[cache] 加载缓存文件...") if err := Collection.LoadFile(DataFilePath); err != nil { diff --git a/consts/context.go b/consts/context.go new file mode 100644 index 0000000..0c744de --- /dev/null +++ b/consts/context.go @@ -0,0 +1,9 @@ +package consts + +// ContextKey is a type of context key +type ContextKey string + +const ( + // ContextKeyRequestID is a context key for request id + ContextKeyRequestID ContextKey = "request_id" +) diff --git a/controllers/v1/ping.go b/controllers/v1/ping.go index 858be58..ff62d1b 100644 --- a/controllers/v1/ping.go +++ b/controllers/v1/ping.go @@ -1,12 +1,12 @@ package v1 import ( - "github.com/gin-gonic/gin" + "github.com/gofiber/fiber/v2" "github.com/hitokoto-osc/Moe/util/web" ) // Ping is a controller func that impl a Pong response, // intended to notify the client that server is ok -func Ping(c *gin.Context) { - web.Success(c, map[string]interface{}{}) +func Ping(c *fiber.Ctx) error { + return web.Success(c, map[string]interface{}{}) } diff --git a/controllers/v1/statistic.go b/controllers/v1/statistic.go index 0996349..91bf365 100644 --- a/controllers/v1/statistic.go +++ b/controllers/v1/statistic.go @@ -1,21 +1,20 @@ package v1 import ( - "github.com/gin-gonic/gin" + "github.com/gofiber/fiber/v2" "github.com/hitokoto-osc/Moe/cache" "github.com/hitokoto-osc/Moe/task/status/types" "github.com/hitokoto-osc/Moe/util/web" ) // Statistic 是用于返回统计分析结果的控制器 -func Statistic(c *gin.Context) { +func Statistic(c *fiber.Ctx) error { data, ok := cache.GetStatusData() if !ok { - web.Fail(c, map[string]interface{}{}, -1) - return + return web.Fail(c, map[string]interface{}{}, -1) } if data.DownServer == nil { data.DownServer = make([]types.DownServerData, 0) } - web.Success(c, data) + return web.Success(c, data) } diff --git a/flag/do.go b/flag/do.go index fd14480..b20e93b 100644 --- a/flag/do.go +++ b/flag/do.go @@ -1,11 +1,8 @@ package flag -import ( - pflag "github.com/spf13/pflag" -) +import "github.com/spf13/pflag" -// Parse params -func Parse() { +func init() { // Register Flag mapping registerVersionFlag() registerHelpFlag() @@ -14,8 +11,10 @@ func Parse() { // Parse Flag pflag.Parse() +} - // Handle Flag event +// Do is a func will be called at init, registering the drivers of program +func Do() { handleVersionFlag() handleHelpFlag() } diff --git a/go.mod b/go.mod index 806139d..e3ca38d 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.21 require ( github.com/Masterminds/semver/v3 v3.2.1 + github.com/bytedance/sonic v1.10.1 github.com/cockroachdb/errors v1.11.1 - github.com/gin-contrib/cors v1.4.0 - github.com/gin-contrib/requestid v0.0.6 - github.com/gin-contrib/sessions v0.0.5 - github.com/gin-gonic/gin v1.9.1 github.com/go-resty/resty/v2 v2.7.0 github.com/go-sql-driver/mysql v1.7.1 + github.com/gofiber/contrib/fiberzap/v2 v2.1.0 + github.com/gofiber/fiber/v2 v2.49.1 + github.com/google/uuid v1.3.1 github.com/jmoiron/sqlx v1.3.5 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/spf13/pflag v1.0.5 @@ -20,56 +20,48 @@ require ( ) require ( - github.com/gorilla/sessions v1.2.1 // indirect github.com/mattn/go-isatty v0.0.19 // indirect golang.org/x/net v0.15.0 // indirect ) require ( - github.com/bytedance/sonic v1.10.1 // indirect + github.com/andybalholm/brotli v1.0.5 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/getsentry/sentry-go v0.24.0 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.15.3 // indirect - github.com/goccy/go-json v0.10.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/google/uuid v1.3.1 // indirect - github.com/gorilla/context v1.1.1 // indirect - github.com/gorilla/securecookie v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/leodido/go-urn v1.2.4 // indirect + github.com/lib/pq v1.10.3 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.49.0 // indirect + github.com/valyala/tcplisten v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.5.0 // indirect - golang.org/x/crypto v0.13.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.13.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a0df3df..8df7b03 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -80,46 +82,22 @@ github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0X github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/getsentry/sentry-go v0.24.0 h1:02b7qEmJ56EHGe9KFgjArjU/vG/aywm7Efgu+iPc01Y= github.com/getsentry/sentry-go v0.24.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= -github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= -github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= -github.com/gin-contrib/requestid v0.0.6 h1:mGcxTnHQ45F6QU5HQRgQUDsAfHprD3P7g2uZ4cSZo9o= -github.com/gin-contrib/requestid v0.0.6/go.mod h1:9i4vKATX/CdggbkY252dPVasgVucy/ggBeELXuQztm4= -github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE= -github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= -github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= -github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= -github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= -github.com/go-playground/validator/v10 v10.15.3 h1:S+sSpunYjNPDuXkWbK+x+bA7iXiW296KG4dL3X7xUZo= -github.com/go-playground/validator/v10 v10.15.3/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/gofiber/contrib/fiberzap/v2 v2.1.0 h1:/OcgX6NdhLL6Sjo6tYNk4rG4smc+ZqXlvZ+V2IDXjY0= +github.com/gofiber/contrib/fiberzap/v2 v2.1.0/go.mod h1:xhIemBHzGPXm38QpzOhS0JA+AvLIRCgx5Wxqg1IFXSs= +github.com/gofiber/fiber/v2 v2.49.1 h1:0W2DRWevSirc8pJl4o8r8QejDR8TV6ZUCawHxwbIdOk= +github.com/gofiber/fiber/v2 v2.49.1/go.mod h1:nPUeEBUeeYGgwbDm59Gp7vS8MDyScL6ezr/Np9A13WU= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -147,7 +125,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -159,10 +136,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -178,18 +153,11 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= -github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -198,50 +166,43 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= +github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg= github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= @@ -253,9 +214,10 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= @@ -273,25 +235,24 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.49.0 h1:9FdvCpmxB74LH4dPb7IJ1cOSsluR07XG3I1txXWwJpE= +github.com/valyala/fasthttp v1.49.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -317,10 +278,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -443,8 +401,7 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -605,10 +562,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -617,9 +570,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/logging/init.go b/logging/init.go index 5440527..b0e35c7 100644 --- a/logging/init.go +++ b/logging/init.go @@ -27,7 +27,7 @@ func buildConfig(isDebug bool) zap.Config { } // 统一配置 c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - c.EncoderConfig.EncodeCaller = zapcore.FullCallerEncoder + c.EncoderConfig.EncodeCaller = zapcore.ShortCallerEncoder c.EncoderConfig.EncodeDuration = zapcore.MillisDurationEncoder c.OutputPaths = []string{"stdout"} diff --git a/logging/logger.go b/logging/logger.go index b308b61..023007a 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -1,8 +1,6 @@ package logging import ( - "context" - "github.com/gin-gonic/gin" "go.uber.org/zap" ) @@ -18,35 +16,3 @@ func GetLogger() *zap.Logger { func setZapGlobalLogger() { zap.ReplaceGlobals(logger) } - -// NewContext add some fields to logger and set it to gin.Context -func NewContext(ctx context.Context, fields ...zap.Field) { - if ctx == nil { - logger.Panic("context is nil") - } - gctx, ok := ctx.(*gin.Context) - if !ok { - logger.Panic("context is not *gin.Context") - } - gctx.Set(loggerKey, WithContext(ctx).With(fields...)) -} - -// WithContext return a logger from gin.Context or global logger -func WithContext(ctx context.Context) *zap.Logger { - if ctx == nil { - return logger - } - gctx, ok := ctx.(*gin.Context) - if !ok { - return logger - } - l, ok := gctx.Get(loggerKey) - if !ok { - return logger - } - ctxLogger, ok := l.(*zap.Logger) - if !ok { - return logger - } - return ctxLogger -} diff --git a/main.go b/main.go index cc45733..c43701b 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,15 @@ package main import ( - "encoding/gob" - "github.com/hitokoto-osc/Moe/logging" - "go.uber.org/zap" - "runtime" - - "github.com/gin-gonic/gin" + "github.com/gofiber/fiber/v2" "github.com/hitokoto-osc/Moe/config" - "github.com/hitokoto-osc/Moe/database" "github.com/hitokoto-osc/Moe/flag" + "github.com/hitokoto-osc/Moe/logging" "github.com/hitokoto-osc/Moe/prestart" "github.com/hitokoto-osc/Moe/routes" - "github.com/hitokoto-osc/Moe/task/status" - "github.com/hitokoto-osc/Moe/task/status/types" + "go.uber.org/zap" + "runtime" + "github.com/spf13/viper" ) @@ -28,14 +24,9 @@ var ( Version = "development" ) -var r *gin.Engine +var app *fiber.App func init() { - // TODO: 用更好的方法修复缓存读写问题 - gob.Register([]database.APIRecord{}) - gob.Register(types.GeneratedData{}) - gob.Register(status.TDownServerList{}) - // Global set build information config.BuildTag = BuildTag config.BuildTime = BuildTime @@ -43,23 +34,22 @@ func init() { config.Version = Version // Parse Flag - flag.Parse() + flag.Do() if config.Debug { logging.GetLogger().Info("Debug mode enabled.") } +} +func main() { + defer zap.L().Sync() // Init Drivers prestart.Do() // init Web Server - r = routes.InitWebServer() -} - -func main() { - defer zap.L().Sync() + app = routes.InitWebServer() // start Server - if err := r.Run(":" + viper.GetString("server.port")); err != nil { + if err := app.Listen(":" + viper.GetString("server.port")); err != nil { zap.L().Fatal("无法启动服务器", zap.Error(err)) } } diff --git a/middlewares/cors.go b/middlewares/cors.go index d2b59cf..b7fddad 100644 --- a/middlewares/cors.go +++ b/middlewares/cors.go @@ -1,16 +1,19 @@ package middlewares import ( - "github.com/gin-contrib/cors" - "github.com/gin-gonic/gin" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) // Cors is a middleware func that solve the issue of CORS response -func Cors() gin.HandlerFunc { - config := cors.DefaultConfig() - config.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"} - config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Cookie"} - config.AllowOrigins = []string{"*"} - config.AllowCredentials = true +func Cors() fiber.Handler { + config := cors.Config{ + AllowOrigins: "*", + AllowMethods: "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS", + AllowHeaders: "Origin, Content-Length, Content-Type, Accept, Cookie", + AllowCredentials: true, + ExposeHeaders: "", + MaxAge: 0, + } return cors.New(config) } diff --git a/middlewares/logger.go b/middlewares/logger.go new file mode 100644 index 0000000..6f2a9a7 --- /dev/null +++ b/middlewares/logger.go @@ -0,0 +1,31 @@ +package middlewares + +import ( + "github.com/gofiber/contrib/fiberzap/v2" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/log" + "github.com/hitokoto-osc/Moe/logging" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +// Logger is a middleware that logs the request and response +func Logger() fiber.Handler { + logger := logging.GetLogger().WithOptions(zap.AddCallerSkip(2)) + cfg := fiberzap.Config{ + Logger: logger, + Fields: []string{"latency", "status", "method", "url"}, + FieldsFunc: func(c *fiber.Ctx) []zap.Field { + return []zap.Field{ + zap.String("request_id", c.Locals("request_id").(string)), + } + }, + Levels: []zapcore.Level{zapcore.ErrorLevel, zapcore.WarnLevel, zapcore.DebugLevel}, + } + fn := fiberzap.New(cfg) + log.SetLogger(fiberzap.NewLogger(fiberzap.LoggerConfig{ + SetLogger: logger, + ExtraKeys: []string{"request_id"}, + })) + return fn +} diff --git a/middlewares/session.go b/middlewares/session.go deleted file mode 100644 index 0d59011..0000000 --- a/middlewares/session.go +++ /dev/null @@ -1,15 +0,0 @@ -package middlewares - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/cookie" - "github.com/gin-gonic/gin" -) - -// Session is a middleware func that register a session driver by Cookie -func Session(secret string) gin.HandlerFunc { - store := cookie.NewStore([]byte(secret)) - //Also set Secure: true if using SSL, you should though - store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"}) - return sessions.Sessions("ncm-session", store) -} diff --git a/middlewares/tracing.go b/middlewares/tracing.go new file mode 100644 index 0000000..0204fe0 --- /dev/null +++ b/middlewares/tracing.go @@ -0,0 +1,21 @@ +package middlewares + +import ( + "context" + "github.com/gofiber/fiber/v2" + "github.com/google/uuid" + "github.com/hitokoto-osc/Moe/consts" +) + +// Tracing is a middleware func that set tracing id to request header +func Tracing() fiber.Handler { + return func(ctx *fiber.Ctx) error { + tracingID := uuid.NewString() + ctx.Set("X-Request-ID", tracingID) + ctx.Locals("request_id", tracingID) + // set tracing id to user context + c := context.WithValue(ctx.UserContext(), consts.ContextKeyRequestID, tracingID) + ctx.SetUserContext(c) + return ctx.Next() + } +} diff --git a/prestart/do.go b/prestart/do.go index cb77cd9..526b86c 100644 --- a/prestart/do.go +++ b/prestart/do.go @@ -1,12 +1,22 @@ package prestart import ( + "encoding/gob" + "github.com/hitokoto-osc/Moe/cache" "github.com/hitokoto-osc/Moe/database" "github.com/hitokoto-osc/Moe/task" + "github.com/hitokoto-osc/Moe/task/status" + "github.com/hitokoto-osc/Moe/task/status/types" ) // Do is a func will be called at init, registering the drivers of program func Do() { + // TODO: 用更好的方法修复缓存读写问题 + gob.Register([]database.APIRecord{}) + gob.Register(types.GeneratedData{}) + gob.Register(status.TDownServerList{}) + + cache.LoadFromDisk() initConfigDriver() database.InitDB() task.Run() diff --git a/routes/base.go b/routes/base.go index 81a11e2..d8f7431 100644 --- a/routes/base.go +++ b/routes/base.go @@ -1,41 +1,42 @@ package routes import ( - "github.com/gin-contrib/requestid" - "github.com/gin-gonic/gin" - "github.com/hitokoto-osc/Moe/config" + "github.com/bytedance/sonic" + "github.com/cockroachdb/errors" + "github.com/gofiber/fiber/v2" + recoverMiddleware "github.com/gofiber/fiber/v2/middleware/recover" "github.com/hitokoto-osc/Moe/middlewares" "github.com/hitokoto-osc/Moe/util/web" ) // InitWebServer is a web server register, implemented by gin -func InitWebServer() *gin.Engine { - if config.Debug { - gin.SetMode(gin.DebugMode) - } else { - gin.SetMode(gin.ReleaseMode) - } - r := gin.Default() - - // load middleware - r.Use(requestid.New()) - r.Use(middlewares.Cors()) - - // 404 - r.NoRoute(func(context *gin.Context) { - context.Status(404) - web.Fail(context, nil, 404) - return - }) - - // 405 - r.NoMethod(func(context *gin.Context) { - context.Status(405) - web.Fail(context, nil, 405) - return +func InitWebServer() *fiber.App { + app := fiber.New(fiber.Config{ + Prefork: false, + ServerHeader: "Moe", + AppName: "@hitokoto/Moe", + ErrorHandler: func(ctx *fiber.Ctx, err error) error { + var e *fiber.Error + code := fiber.StatusInternalServerError + if errors.As(err, &e) { + code = e.Code + } + err = web.Fail(ctx, nil, code) + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return nil + }, + JSONEncoder: sonic.Marshal, + JSONDecoder: sonic.Unmarshal, }) + // middleware + app.Use(middlewares.Tracing()) + app.Use(middlewares.Logger()) + app.Use(recoverMiddleware.New()) + app.Use(middlewares.Cors()) // setup routes - setupRoutes(r) - return r + setupRoutes(app) + return app } diff --git a/routes/router.go b/routes/router.go index 2eebc2f..cd1ebe6 100644 --- a/routes/router.go +++ b/routes/router.go @@ -1,31 +1,27 @@ package routes import ( - "github.com/hitokoto-osc/Moe/logging" + "github.com/gofiber/fiber/v2" "runtime" - "github.com/gin-gonic/gin" "github.com/hitokoto-osc/Moe/config" apiV1 "github.com/hitokoto-osc/Moe/controllers/v1" - "github.com/hitokoto-osc/Moe/middlewares" "github.com/hitokoto-osc/Moe/util/web" - "github.com/spf13/viper" ) var osInfo = runtime.GOOS + " " + runtime.GOARCH -func setupRoutes(r *gin.Engine) { - logger := logging.GetLogger() - defer logger.Sync() +func setupRoutes(app *fiber.App) { + //logger := logging.GetLogger() - if !viper.IsSet("server.secret") { - logger.Fatal("[web] can't start server because of the secret is not set.") - } - r.Use(middlewares.Session(viper.GetString("server.secret"))) + //if !viper.IsSet("server.secret") { + // logger.Fatal("[web] can't start server because of the secret is not set.") + //} + //r.Use(middlewares.Session(viper.GetString("server.secret"))) // Setup router - r.GET("/", func(context *gin.Context) { - web.Success(context, map[string]interface{}{ + app.Get("/", func(ctx *fiber.Ctx) error { + return web.Success(ctx, map[string]interface{}{ "build_info": map[string]interface{}{ "version": config.Version, "commit_hash": config.BuildTag, @@ -51,14 +47,14 @@ func setupRoutes(r *gin.Engine) { }) }) - v1 := r.Group("/v1") + v1 := app.Group("/v1") { // protected routes // protected := r.Group("/api/v1", middlewares.AuthByMasterKey()) // { // } // common routes - v1.GET("/ping", apiV1.Ping) - v1.GET("/statistic", apiV1.Statistic) + v1.Get("/ping", apiV1.Ping) + v1.Get("/statistic", apiV1.Statistic) } } diff --git a/task/run.go b/task/run.go index c186f5c..75feeea 100644 --- a/task/run.go +++ b/task/run.go @@ -2,7 +2,6 @@ package task import ( "github.com/hitokoto-osc/Moe/logging" - "reflect" "time" "github.com/hitokoto-osc/Moe/task/status" @@ -17,7 +16,7 @@ func Run() { func taskLoop(t time.Duration, task func()) { logger := logging.GetLogger() for { - logger.Sugar().Debug("[taskLoop] 等待 %v 后执行 %s...", t, reflect.TypeOf(task).Name()) + logger.Sugar().Debugf("[taskLoop] 等待 %v 后执行 task...", t) logger.Sync() time.Sleep(t) task() diff --git a/task/status/request.go b/task/status/request.go index ccfd906..33e2862 100644 --- a/task/status/request.go +++ b/task/status/request.go @@ -59,6 +59,7 @@ func performRequest(records []database.APIRecord) (data []types.APIStatusRespons func requestServerAPI(url string) (data types.APIStatusResponseData, err error) { client := resty.New() client. + SetLogger(logging.GetLogger().Sugar()). // 设置重试逻辑 SetRetryCount(2). // 重试次数 SetRetryWaitTime(200 * time.Millisecond). diff --git a/util/web/bearer.go b/util/web/bearer.go index ea0371a..acb621e 100644 --- a/util/web/bearer.go +++ b/util/web/bearer.go @@ -2,18 +2,15 @@ package web import ( "encoding/base64" - "github.com/hitokoto-osc/Moe/logging" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/log" "go.uber.org/zap" "strings" - - "github.com/gin-gonic/gin" ) // ParseBearerTokenFromHeader is a func that parse bearer token in authorization header -func ParseBearerTokenFromHeader(ctx *gin.Context) (token string, ok bool) { - logger := logging.WithContext(ctx) - defer logger.Sync() - authorization := ctx.GetHeader("Authorization") +func ParseBearerTokenFromHeader(ctx *fiber.Ctx) (token string, ok bool) { + authorization := ctx.Get("Authorization") // parse authorization if authorization == "" || !strings.HasPrefix(authorization, "Bearer ") { ok = false @@ -23,7 +20,7 @@ func ParseBearerTokenFromHeader(ctx *gin.Context) (token string, ok bool) { // base64 decode buffer, err := base64.StdEncoding.DecodeString(token) if err != nil { - logger.Error("无法解析 Authorization 头部的 Bearer Token", zap.Error(err)) + log.Error("无法解析 Authorization 头部的 Bearer Token", zap.Error(err)) ok = false return } diff --git a/util/web/response.go b/util/web/response.go index 235ee7c..3d68445 100644 --- a/util/web/response.go +++ b/util/web/response.go @@ -1,40 +1,38 @@ package web import ( + "github.com/gofiber/fiber/v2" "time" - - "github.com/gin-contrib/requestid" - "github.com/gin-gonic/gin" ) var errorMessageMap = map[int]string{ - 400: "Bad request.", - 401: "Unauthorized.", - 404: "Not found specific route/file.", - 403: "Forbidden.", - 405: "Method not permitted.", - 500: "Server error. If occurs frequently, please contact the author.", - 503: "service Unavailable.", + fiber.StatusBadRequest: "Bad request.", + fiber.StatusUnauthorized: "Unauthorized.", + fiber.StatusNotFound: "Not found specific route/file.", + fiber.StatusForbidden: "Forbidden.", + fiber.StatusMethodNotAllowed: "Method not permitted.", + fiber.StatusInternalServerError: "Server error. If occurs frequently, please contact the author.", + fiber.StatusServiceUnavailable: "service Unavailable.", // Custom Error -1: "The Status Data is not found. Please try again later.", } // Success is a func that do the common situation of responding successful formation -func Success(ctx *gin.Context, data interface{}) { - ctx.JSON(200, map[string]interface{}{ +func Success(ctx *fiber.Ctx, data interface{}) error { + return ctx.Status(fiber.StatusOK).JSON(map[string]interface{}{ "code": 200, "message": "ok", "data": data, - "request_id": requestid.Get(ctx), + "request_id": ctx.Locals("request_id"), "ts": time.Now().UnixNano() / 1e6, }) } // Fail is a func that do the common situation of responding failed formation -func Fail(ctx *gin.Context, data interface{}, code int) { +func Fail(ctx *fiber.Ctx, data interface{}, code int) error { var status int if code <= 0 { - status = 200 + status = fiber.StatusOK } else { status = code } @@ -42,11 +40,11 @@ func Fail(ctx *gin.Context, data interface{}, code int) { if !ok { msg = "Unknown status code, please contact author." } - ctx.JSON(status, map[string]interface{}{ + return ctx.Status(status).JSON(map[string]interface{}{ "code": code, "message": msg, "data": data, - "request_id": requestid.Get(ctx), + "request_id": ctx.Locals("request_id"), "ts": time.Now().UnixNano() / 1e6, }) } diff --git a/util/web/token.go b/util/web/token.go index 568bc3d..2225a22 100644 --- a/util/web/token.go +++ b/util/web/token.go @@ -1,12 +1,12 @@ package web import ( - "github.com/gin-gonic/gin" + "github.com/gofiber/fiber/v2" "github.com/spf13/viper" ) // ValidTokenByContext is a func that verify the authorization by bearer token -func ValidTokenByContext(ctx *gin.Context) (ok bool) { +func ValidTokenByContext(ctx *fiber.Ctx) (ok bool) { ok = false masterKey := viper.GetString("server.auth.master_key") token, isOk := ParseBearerTokenFromHeader(ctx)