config重构
This commit is contained in:
1 parent
0810383afc
commit
5f873914e0
14 files changed
+134
-208
No files matched your search
+9
-8
@@ -11,8 +11,6 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"go-admin/app/admin/router"
|
||||
"go-admin/app/jobs"
|
||||
"go-admin/common/database"
|
||||
@@ -59,6 +57,7 @@ func setup() {
|
||||
|
||||
//1. 读取配置
|
||||
config.Setup(configYml)
|
||||
go config.Watch()
|
||||
//2. 设置日志
|
||||
global.Logger.Logger = logger.SetupLogger(config.LoggerConfig.Path, "bus")
|
||||
global.JobLogger.Logger = logger.SetupLogger(config.LoggerConfig.Path, "job")
|
||||
@@ -74,7 +73,9 @@ func setup() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
if viper.GetString("settings.application.mode") == string(tools.ModeProd) {
|
||||
defer config.Stop()
|
||||
|
||||
if config.ApplicationConfig.Mode == tools.ModeProd.String() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
engine := global.Cfg.GetEngine()
|
||||
@@ -92,7 +93,7 @@ func run() error {
|
||||
}
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port,
|
||||
Addr: fmt.Sprintf("%s:%d", config.ApplicationConfig.Host, config.ApplicationConfig.Port),
|
||||
Handler: global.Cfg.GetEngine(),
|
||||
}
|
||||
go func() {
|
||||
@@ -125,11 +126,11 @@ func run() error {
|
||||
fmt.Println(tools.Red(string(global.LogoContent)))
|
||||
tip()
|
||||
fmt.Println(tools.Green("Server run at:"))
|
||||
fmt.Printf("- Local: http://localhost:%s/ \r\n", config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Network: http://%s:%s/ \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Local: http://localhost:%d/ \r\n", config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Network: http://%s:%d/ \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
|
||||
fmt.Println(tools.Green("Swagger run at:"))
|
||||
fmt.Printf("- Local: http://localhost:%s/swagger/index.html \r\n", config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Network: http://%s:%s/swagger/index.html \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Local: http://localhost:%d/swagger/index.html \r\n", config.ApplicationConfig.Port)
|
||||
fmt.Printf("- Network: http://%s:%d/swagger/index.html \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
|
||||
fmt.Printf("%s Enter Control + C Shutdown Server \r\n", tools.GetCurrentTimeStr())
|
||||
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
||||
quit := make(chan os.Signal)
|
||||
|
||||
@@ -10,7 +10,7 @@ require (
|
||||
github.com/casbin/gorm-adapter/v3 v3.0.2
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-admin-team/go-admin-core v1.2.2
|
||||
github.com/go-admin-team/go-admin-core v1.2.3-0.20201208071849-612a1666b9cc
|
||||
github.com/go-redis/redis/v7 v7.4.0
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
|
||||
@@ -79,9 +79,11 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
|
||||
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
|
||||
github.com/bsm/redislock v0.5.0 h1:ODM11/cbuUXQqLgZWK6XQnufaTjsBE2UcwBc2EAFNDA=
|
||||
github.com/bsm/redislock v0.5.0/go.mod h1:qagqKlV+xiLy26iV34Y3zRPxRcJjQYbV7pZfWFeSZ8M=
|
||||
@@ -100,6 +102,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
|
||||
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
|
||||
@@ -150,7 +154,10 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
|
||||
github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE=
|
||||
@@ -164,6 +171,7 @@ github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pF
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc=
|
||||
github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w=
|
||||
@@ -180,8 +188,8 @@ github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f h1:8l4Aw3Jmx
|
||||
github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f/go.mod h1:Dcsy1kii/xFyNad5JqY/d0GO5mu91sungp5xotbm3Yk=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-acme/lego/v3 v3.4.0/go.mod h1:xYbLDuxq3Hy4bMUT1t9JIuz6GWIWb3m5X+TeTHYaT7M=
|
||||
github.com/go-admin-team/go-admin-core v1.2.2 h1:TMR5ga2vTQGRMR+zZ9XrOO2Zpvl5+AOFN4bnfJfimKw=
|
||||
github.com/go-admin-team/go-admin-core v1.2.2/go.mod h1:F+wumLm6Tw9Y9usOy45vdvQ9kbbCgSJKseKWzjvd/BQ=
|
||||
github.com/go-admin-team/go-admin-core v1.2.3-0.20201208071849-612a1666b9cc h1:YBC0JH9g2GAQP7ods+LHLYMJb+UtCoxiOoaS5J7cBt0=
|
||||
github.com/go-admin-team/go-admin-core v1.2.3-0.20201208071849-612a1666b9cc/go.mod h1:6uyaucbKIaL5KoGcYZVDgfMwJupT4lUWksgxST33TWs=
|
||||
github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
@@ -264,6 +272,9 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
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=
|
||||
@@ -272,6 +283,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
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=
|
||||
@@ -426,6 +439,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
@@ -490,9 +504,11 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg=
|
||||
github.com/micro/go-micro/v2 v2.9.1 h1:+S9koIrNWARjpP6k2TZ7kt0uC9zUJtNXzIdZTZRms7Q=
|
||||
github.com/micro/go-micro/v2 v2.9.1/go.mod h1:x55ZM3Puy0FyvvkR3e0ha0xsE9DFwfPSUMWAIbFY0SY=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM=
|
||||
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
@@ -556,8 +572,10 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
|
||||
github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
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/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
@@ -824,11 +842,13 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -947,6 +967,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98
|
||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
@@ -955,7 +977,12 @@ google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ij
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
|
||||
google.golang.org/grpc/examples v0.0.0-20201207231033-bce1fdfad97e/go.mod h1:Ly7ZA/ARzg8fnPU9TyZIxoz33sEUuWX7txiqs8lPTgE=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@@ -963,6 +990,11 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
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 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/AlecAivazis/survey.v1 v1.8.5 h1:QoEEmn/d5BbuPIL2qvXwzJdttFFhRQFkaq+tEKb7SMI=
|
||||
gopkg.in/AlecAivazis/survey.v1 v1.8.5/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
|
||||
@@ -4,70 +4,6 @@ import (
|
||||
"go-admin/cmd"
|
||||
)
|
||||
|
||||
// @title go-admin API
|
||||
// @version 1.0.1
|
||||
// @description 基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档
|
||||
// @description 添加qq群: 74520518 进入技术交流群 请备注,谢谢!
|
||||
// @license.name MIT
|
||||
// @license.url https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md
|
||||
|
||||
// @securityDefinitions.apikey Bearer
|
||||
// @in header
|
||||
// @name Authorization
|
||||
|
||||
//func main() {
|
||||
// configName := "settings"
|
||||
//
|
||||
//
|
||||
// config.InitConfig(configName)
|
||||
//
|
||||
// gin.SetMode(gin.DebugMode)
|
||||
// log.Println(config.DatabaseConfig.Port)
|
||||
//
|
||||
// err := gorm.AutoMigrate(orm.Eloquent)
|
||||
// if err != nil {
|
||||
// log.Fatalln("数据库初始化失败 err: %v", err)
|
||||
// }
|
||||
//
|
||||
// if config.ApplicationConfig.IsInit {
|
||||
// if err := models.InitDb(); err != nil {
|
||||
// log.Fatal("数据库基础数据初始化失败!")
|
||||
// } else {
|
||||
// config.SetApplicationIsInit()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// r := router.InitRouter()
|
||||
//
|
||||
// defer orm.Eloquent.Close()
|
||||
//
|
||||
// srv := &http.Server{
|
||||
// Addr: config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port,
|
||||
// Handler: r,
|
||||
// }
|
||||
//
|
||||
// go func() {
|
||||
// // 服务连接
|
||||
// if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
// log.Fatalf("listen: %s\n", err)
|
||||
// }
|
||||
// }()
|
||||
// log.Println("Server Run ", config.ApplicationConfig.Host+":"+config.ApplicationConfig.Port)
|
||||
// log.Println("Enter Control + C Shutdown Server")
|
||||
// // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
||||
// quit := make(chan os.Signal)
|
||||
// signal.Notify(quit, os.Interrupt)
|
||||
// <-quit
|
||||
// log.Println("Shutdown Server ...")
|
||||
//
|
||||
// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
// defer cancel()
|
||||
// if err := srv.Shutdown(ctx); err != nil {
|
||||
// log.Fatal("Server Shutdown:", err)
|
||||
// }
|
||||
// log.Println("Server exiting")
|
||||
//}
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Crc32Hash 用于32张分表
|
||||
@@ -22,3 +25,15 @@ func Crc8Hash(src string) string {
|
||||
sum := crc32.ChecksumIEEE([]byte(src)) % 8
|
||||
return strconv.Itoa(int(sum))
|
||||
}
|
||||
|
||||
// e.g. DB.Scopes(DynamicTable(Crc32Hash, "test", "小圈圈")).Find(&tests)
|
||||
// DynamicTable 设置动态表名scope params: f 分表计算函数 baseTable 基础表名 fieldValue 参与分表字段
|
||||
func DynamicTable(f func(string) string, baseTable, fieldValue string) func(db *gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Table(fmt.Sprintf("%s_%s", baseTable, f(fieldValue)))
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSubTable(f func(string) string) {
|
||||
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Application struct {
|
||||
ReadTimeout int
|
||||
WriterTimeout int
|
||||
Host string
|
||||
Port string
|
||||
Port int64
|
||||
Name string
|
||||
JwtSecret string
|
||||
Mode string
|
||||
@@ -14,18 +12,4 @@ type Application struct {
|
||||
EnableDP bool
|
||||
}
|
||||
|
||||
func InitApplication(cfg *viper.Viper) *Application {
|
||||
return &Application{
|
||||
ReadTimeout: cfg.GetInt("readTimeout"),
|
||||
WriterTimeout: cfg.GetInt("writerTimeout"),
|
||||
Host: cfg.GetString("host"),
|
||||
Port: cfg.GetString("port"),
|
||||
Name: cfg.GetString("name"),
|
||||
JwtSecret: cfg.GetString("jwtSecret"),
|
||||
Mode: cfg.GetString("mode"),
|
||||
DemoMsg: cfg.GetString("demoMsg"),
|
||||
EnableDP: cfg.GetBool("enabledp"),
|
||||
}
|
||||
}
|
||||
|
||||
var ApplicationConfig = new(Application)
|
||||
+70
-59
@@ -2,83 +2,94 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"github.com/go-admin-team/go-admin-core/config"
|
||||
"github.com/go-admin-team/go-admin-core/config/source/file"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// 数据库配置项
|
||||
var cfgDatabase *viper.Viper
|
||||
var (
|
||||
ExtendConfig interface{}
|
||||
)
|
||||
|
||||
// 应用配置项
|
||||
var cfgApplication *viper.Viper
|
||||
// Settings 兼容原先的配置结构
|
||||
type Settings struct {
|
||||
Settings Config `yaml:"settings"`
|
||||
}
|
||||
|
||||
// Token配置项
|
||||
var cfgJwt *viper.Viper
|
||||
// Config 配置集合
|
||||
type Config struct {
|
||||
Application *Application `yaml:"application"`
|
||||
Ssl *Ssl `yaml:"ssl"`
|
||||
Logger *Logger `yaml:"logger"`
|
||||
Jwt *Jwt `yaml:"jwt"`
|
||||
Database *Database `yaml:"database"`
|
||||
Gen *Gen `yaml:"gen"`
|
||||
Extend interface{} `yaml:"extend"`
|
||||
}
|
||||
|
||||
// Log配置项
|
||||
var cfgLogger *viper.Viper
|
||||
var (
|
||||
_watch config.Watcher
|
||||
_cfg *Settings
|
||||
)
|
||||
|
||||
// Ssl配置项 非必须
|
||||
var cfgSsl *viper.Viper
|
||||
|
||||
// 代码生成配置项 非必须
|
||||
var cfgGen *viper.Viper
|
||||
|
||||
//载入配置文件
|
||||
// Setup 载入配置文件
|
||||
func Setup(path string) {
|
||||
viper.SetConfigFile(path)
|
||||
content, err := ioutil.ReadFile(path)
|
||||
c, err := config.NewConfig()
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
|
||||
log.Fatal(fmt.Sprintf("New config object fail: %s", err.Error()))
|
||||
}
|
||||
|
||||
//Replace environment variables
|
||||
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
|
||||
err = c.Load(
|
||||
file.NewSource(
|
||||
file.WithPath(path),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Parse config file fail: %s", err.Error()))
|
||||
log.Fatal(fmt.Sprintf("Load config source fail: %s", err.Error()))
|
||||
}
|
||||
|
||||
cfgDatabase = viper.Sub("settings.database")
|
||||
if cfgDatabase == nil {
|
||||
panic("No found settings.database in the configuration")
|
||||
_cfg = &Settings{Config{
|
||||
Application: ApplicationConfig,
|
||||
Ssl: SslConfig,
|
||||
Logger: LoggerConfig,
|
||||
Jwt: JwtConfig,
|
||||
Database: DatabaseConfig,
|
||||
Gen: GenConfig,
|
||||
Extend: ExtendConfig,
|
||||
}}
|
||||
err = c.Scan(_cfg)
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Scan config fail: %s", err.Error()))
|
||||
}
|
||||
DatabaseConfig = InitDatabase(cfgDatabase)
|
||||
|
||||
cfgApplication = viper.Sub("settings.application")
|
||||
if cfgApplication == nil {
|
||||
panic("No found settings.application in the configuration")
|
||||
_watch, err = c.Watch()
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Watch config source fail: %s", err.Error()))
|
||||
}
|
||||
ApplicationConfig = InitApplication(cfgApplication)
|
||||
}
|
||||
|
||||
cfgJwt = viper.Sub("settings.jwt")
|
||||
if cfgJwt == nil {
|
||||
panic("No found settings.jwt in the configuration")
|
||||
// Watch 配置监听, 重载时报错,不影响运行
|
||||
func Watch() {
|
||||
for {
|
||||
v, err := _watch.Next()
|
||||
if err != nil {
|
||||
if err.Error() != "watch stopped" {
|
||||
log.Println(fmt.Sprintf("Next config fail: %s", err.Error()))
|
||||
}
|
||||
break
|
||||
}
|
||||
err = v.Scan(_cfg)
|
||||
if err != nil {
|
||||
log.Println(fmt.Sprintf("Scan config fail: %s", err.Error()))
|
||||
break
|
||||
}
|
||||
fmt.Println(DatabaseConfig)
|
||||
}
|
||||
JwtConfig = InitJwt(cfgJwt)
|
||||
}
|
||||
|
||||
cfgLogger = viper.Sub("settings.logger")
|
||||
if cfgLogger == nil {
|
||||
panic("No found settings.logger in the configuration")
|
||||
}
|
||||
LoggerConfig = InitLog(cfgLogger)
|
||||
|
||||
cfgSsl = viper.Sub("settings.ssl")
|
||||
if cfgSsl == nil {
|
||||
// Ssl不是系统强制要求的配置,默认可以不用配置,将设置为关闭状态
|
||||
fmt.Println("warning config not found settings.ssl in the configuration")
|
||||
SslConfig = new(Ssl)
|
||||
SslConfig.Enable = false
|
||||
} else {
|
||||
SslConfig = InitSsl(cfgSsl)
|
||||
}
|
||||
|
||||
cfgGen = viper.Sub("settings.gen")
|
||||
if cfgGen == nil {
|
||||
panic("No found settings.gen")
|
||||
// Stop 停止监听
|
||||
func Stop() {
|
||||
err := _watch.Stop()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
GenConfig = InitGen(cfgGen)
|
||||
}
|
||||
@@ -1,19 +1,8 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Database struct {
|
||||
Driver string
|
||||
Source string
|
||||
}
|
||||
|
||||
func InitDatabase(cfg *viper.Viper) *Database {
|
||||
|
||||
db := &Database{
|
||||
Driver: cfg.GetString("driver"),
|
||||
Source: cfg.GetString("source"),
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
var DatabaseConfig = new(Database)
|
||||
@@ -1,17 +1,8 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Gen struct {
|
||||
DBName string
|
||||
FrontPath string
|
||||
}
|
||||
|
||||
func InitGen(cfg *viper.Viper) *Gen {
|
||||
return &Gen{
|
||||
DBName: cfg.GetString("dbname"),
|
||||
FrontPath: cfg.GetString("frontpath"),
|
||||
}
|
||||
}
|
||||
|
||||
var GenConfig = new(Gen)
|
||||
@@ -1,19 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Jwt struct {
|
||||
Secret string
|
||||
Timeout int64
|
||||
}
|
||||
|
||||
func InitJwt(cfg *viper.Viper) *Jwt {
|
||||
return &Jwt{
|
||||
Secret: cfg.GetString("secret"),
|
||||
Timeout: cfg.GetInt64("timeout"),
|
||||
}
|
||||
}
|
||||
|
||||
var JwtConfig = new(Jwt)
|
||||
@@ -1,7 +1,5 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Logger struct {
|
||||
Path string
|
||||
Level string
|
||||
@@ -12,16 +10,4 @@ type Logger struct {
|
||||
EnabledJOB bool `default:"false"`
|
||||
}
|
||||
|
||||
func InitLog(cfg *viper.Viper) *Logger {
|
||||
return &Logger{
|
||||
Path: cfg.GetString("path"),
|
||||
Level: cfg.GetString("level"),
|
||||
Stdout: cfg.GetBool("stdout"),
|
||||
EnabledBUS: cfg.GetBool("enabledbus"),
|
||||
EnabledREQ: cfg.GetBool("enabledreq"),
|
||||
EnabledDB: cfg.GetBool("enableddb"),
|
||||
EnabledJOB: cfg.GetBool("enabledjob"),
|
||||
}
|
||||
}
|
||||
|
||||
var LoggerConfig = new(Logger)
|
||||
@@ -1,7 +1,5 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Ssl struct {
|
||||
KeyStr string
|
||||
Pem string
|
||||
@@ -9,13 +7,4 @@ type Ssl struct {
|
||||
Domain string
|
||||
}
|
||||
|
||||
func InitSsl(cfg *viper.Viper) *Ssl {
|
||||
return &Ssl{
|
||||
KeyStr: cfg.GetString("key"),
|
||||
Pem: cfg.GetString("pem"),
|
||||
Enable: cfg.GetBool("enable"),
|
||||
Domain: cfg.GetString("domain"),
|
||||
}
|
||||
}
|
||||
|
||||
var SslConfig = new(Ssl)
|
||||
@@ -11,3 +11,7 @@ const (
|
||||
Mysql = "mysql" //mysql数据库标识
|
||||
Sqlite = "sqlite3" //sqlite
|
||||
)
|
||||
|
||||
func (e Mode) String() string {
|
||||
return string(e)
|
||||
}
|
||||
@@ -72,7 +72,6 @@ func Start() {
|
||||
func Stop(ctx context.Context) {
|
||||
quit := make(chan os.Signal)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
<-quit
|
||||
fmt.Printf("%s Shutdown Server ... \r\n", tools.GetCurrentTimeStr())
|
||||
err := _server.Shutdown(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user