Browse Source

Merge pull request #188 from kris-nova/master

feat(bypass-init): Adding compile time init() function bypass mechanism
pull/198/head
gwuhaolin 5 years ago committed by GitHub
parent
commit
e8d36e4519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      configure/liveconfig.go

16
configure/liveconfig.go

@ -82,7 +82,15 @@ var defaultConf = ServerCfg{ @@ -82,7 +82,15 @@ var defaultConf = ServerCfg{
}},
}
var Config = viper.New()
var (
Config = viper.New()
// BypassInit can be used to bypass the init() function by setting this
// value to True at compile time.
//
// go build -ldflags "-X 'github.com/gwuhaolin/livego/configure.BypassInit=true'" -o livego main.go
BypassInit string = ""
)
func initLog() {
if l, err := log.ParseLevel(Config.GetString("level")); err == nil {
@ -92,6 +100,12 @@ func initLog() { @@ -92,6 +100,12 @@ func initLog() {
}
func init() {
if BypassInit == "" {
initDefault()
}
}
func initDefault() {
defer Init()
// Default config

Loading…
Cancel
Save