2021-07-04 20:55:34 +08:00
|
|
|
package utils
|
|
|
|
|
2021-07-07 20:27:05 +08:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
|
)
|
2021-07-04 20:55:34 +08:00
|
|
|
|
|
|
|
func MarshalToStringParam(param interface{}) string {
|
|
|
|
s, err := jsoniter.MarshalToString(param)
|
|
|
|
if err != nil {
|
|
|
|
return "{}"
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeResp(code int, msg string) map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"code": code,
|
|
|
|
"msg": msg,
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 20:27:05 +08:00
|
|
|
|
|
|
|
func GetEnvDefault(key, defVal string) string {
|
|
|
|
val, ex := os.LookupEnv(key)
|
|
|
|
if !ex {
|
|
|
|
return defVal
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|