Skip to content

Commit

Permalink
Merge pull request gwuhaolin#188 from kris-nova/master
Browse files Browse the repository at this point in the history
feat(bypass-init): Adding compile time init() function bypass mechanism
  • Loading branch information
gwuhaolin authored Dec 9, 2021
2 parents f95d317 + 59394b0 commit e8d36e4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions configure/liveconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type ServerCfg struct {
// default config
var defaultConf = ServerCfg{
ConfigFile: "livego.yaml",
FLVArchive: false,
RTMPNoAuth: false,
FLVArchive: false,
RTMPNoAuth: false,
RTMPAddr: ":1935",
HTTPFLVAddr: ":7001",
HLSAddr: ":7002",
Expand All @@ -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 {
Expand All @@ -92,6 +100,12 @@ func initLog() {
}

func init() {
if BypassInit == "" {
initDefault()
}
}

func initDefault() {
defer Init()

// Default config
Expand Down

0 comments on commit e8d36e4

Please sign in to comment.