first commit
This commit is contained in:
51
conf/env.go
Normal file
51
conf/env.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type botSettings struct {
|
||||
HTTPProxy string
|
||||
BotToken string
|
||||
MCServer string
|
||||
MCBotName string
|
||||
GroupID int64
|
||||
}
|
||||
|
||||
var (
|
||||
botSettingsInstance *botSettings
|
||||
)
|
||||
|
||||
func init() {
|
||||
godotenv.Load()
|
||||
http_proxy := os.Getenv("HTTP_PROXY")
|
||||
bot_token := os.Getenv("BOT_TOKEN")
|
||||
mc_server := os.Getenv("MC_SERVER")
|
||||
mc_bot_name := os.Getenv("MC_BOT_NAME")
|
||||
group_id_str := os.Getenv("GROUP_ID")
|
||||
|
||||
if http_proxy == "" || bot_token == "" || mc_server == "" || mc_bot_name == "" || group_id_str == "" {
|
||||
logrus.Panic("请检查环境变量是否设置正确")
|
||||
}
|
||||
|
||||
group_id, err := strconv.ParseInt(group_id_str, 10, 64)
|
||||
if err != nil {
|
||||
logrus.Panic("请检查环境变量是否设置正确")
|
||||
}
|
||||
|
||||
botSettingsInstance = &botSettings{
|
||||
HTTPProxy: http_proxy,
|
||||
BotToken: bot_token,
|
||||
MCServer: mc_server,
|
||||
MCBotName: mc_bot_name,
|
||||
GroupID: group_id,
|
||||
}
|
||||
}
|
||||
|
||||
func GetBotSettings() *botSettings {
|
||||
return botSettingsInstance
|
||||
}
|
Reference in New Issue
Block a user