Load the configuration on start

Signed-off-by: René Jochum <rene@jochum.dev>
master
René Jochum 2 years ago
parent b14ff18928
commit 216d5e8ba9

@ -6,7 +6,7 @@ vars:
GIT_COMMIT:
sh: git rev-parse HEAD
VERSION:
sh: if test -z "{{.GIT_TAG}}"; then echo "{{.GIT_COMMIT}}"; else echo "{{.GIT_TAG}}"; fi
sh: if test -z "{{.GIT_TAG}}"; then echo "{{.GIT_COMMIT}}"; elif test -n "{{.GIT_TAG}}"; then echo "{{.GIT_TAG}}"; else echo "dirty"; fi
tasks:
default:

@ -18,6 +18,10 @@ func main() {
micro.Server(httpServer.NewServer()),
)
if err := config.Load(); err != nil {
logger.Fatal(err)
}
if config.GetServerConfig().Env == config.EnvProd {
gin.SetMode(gin.ReleaseMode)
}

@ -2,11 +2,11 @@ package config
import (
"os"
"runtime/debug"
"strings"
"github.com/go-micro/plugins/v4/config/encoder/toml"
"github.com/go-micro/plugins/v4/config/encoder/yaml"
"github.com/go-micro/router/util"
"github.com/pkg/errors"
"go-micro.dev/v4/config"
"go-micro.dev/v4/config/reader"
@ -25,21 +25,6 @@ var _cfg *Config = &Config{
},
}
// goSafe will run func in goroutine safely, avoid crash from unexpected panic
func goSafe(fn func()) {
if fn == nil {
return
}
go func() {
defer func() {
if e := recover(); e != nil {
logger.Errorf("[panic]%v\n%s", e, debug.Stack())
}
}()
fn()
}()
}
// Load will load configurations and update it when changed
func Load() error {
var configor config.Config
@ -81,7 +66,7 @@ func Load() error {
if err != nil {
return errors.Wrap(err, "configor.Watch")
}
goSafe(func() {
util.GoSafe(func() {
for {
v, err := w.Next()
if err != nil {

Loading…
Cancel
Save