7
0
gaore-common-sdk-go/sdk/utils/debug.go

37 lines
523 B
Go
Raw Normal View History

2020-08-06 12:15:51 +08:00
package utils
2020-08-06 15:41:02 +08:00
import (
"fmt"
"os"
"strings"
)
2020-08-06 12:15:51 +08:00
type Debug func(format string, v ...interface{})
var hookPrint = func(input string) {
fmt.Println(input)
}
2020-08-06 15:41:02 +08:00
var hookGetEnv = func() string {
return os.Getenv("DEBUG")
}
func Init(flag string) Debug {
enable := false
env := hookGetEnv()
parts := strings.Split(env, ",")
for _, part := range parts {
if part == flag {
enable = true
break
}
}
2020-08-06 12:15:51 +08:00
return func(format string, v ...interface{}) {
if enable {
hookPrint(fmt.Sprintf(format, v...))
}
}
}