Skip to content

Commit b8da8a5

Browse files
authored
Merge pull request gwuhaolin#188 from kris-nova/master
feat(bypass-init): Adding compile time init() function bypass mechanism
2 parents d497ee2 + b2d69da commit b8da8a5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

configure/liveconfig.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ type ServerCfg struct {
6262
// default config
6363
var defaultConf = ServerCfg{
6464
ConfigFile: "livego.yaml",
65-
FLVArchive: false,
66-
RTMPNoAuth: false,
65+
FLVArchive: false,
66+
RTMPNoAuth: false,
6767
RTMPAddr: ":1935",
6868
HTTPFLVAddr: ":7001",
6969
HLSAddr: ":7002",
@@ -82,7 +82,15 @@ var defaultConf = ServerCfg{
8282
}},
8383
}
8484

85-
var Config = viper.New()
85+
var (
86+
Config = viper.New()
87+
88+
// BypassInit can be used to bypass the init() function by setting this
89+
// value to True at compile time.
90+
//
91+
// go build -ldflags "-X 'github.com/gwuhaolin/livego/configure.BypassInit=true'" -o livego main.go
92+
BypassInit string = ""
93+
)
8694

8795
func initLog() {
8896
if l, err := log.ParseLevel(Config.GetString("level")); err == nil {
@@ -92,6 +100,12 @@ func initLog() {
92100
}
93101

94102
func init() {
103+
if BypassInit == "" {
104+
initDefault()
105+
}
106+
}
107+
108+
func initDefault() {
95109
defer Init()
96110

97111
// Default config

0 commit comments

Comments
 (0)