fix: Using to init function
This commit is contained in:
parent
9af72608db
commit
60694a8705
4 changed files with 17 additions and 21 deletions
|
@ -59,20 +59,20 @@ type Component struct {
|
|||
}
|
||||
|
||||
const (
|
||||
Chattings Category = "채팅"
|
||||
Generals Category = "일반"
|
||||
Chatting Category = "채팅"
|
||||
Generals Category = "일반"
|
||||
)
|
||||
|
||||
var commandMutex sync.Mutex
|
||||
var componentMutex sync.Mutex
|
||||
var Discommand *DiscommandStruct
|
||||
|
||||
func new() *DiscommandStruct {
|
||||
discommand := DiscommandStruct{
|
||||
func init() {
|
||||
Discommand = &DiscommandStruct{
|
||||
Commands: map[string]*Command{},
|
||||
Aliases: map[string]string{},
|
||||
Components: []*Component{},
|
||||
}
|
||||
return &discommand
|
||||
}
|
||||
|
||||
func (d *DiscommandStruct) LoadCommand(c *Command) {
|
||||
|
@ -124,5 +124,3 @@ func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.Inter
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
var Discommand *DiscommandStruct = new()
|
||||
|
|
|
@ -23,7 +23,7 @@ var LearnedDataListCommand *Command = &Command{
|
|||
DetailedDescription: &DetailedDescription{
|
||||
Usage: fmt.Sprintf("%s리스트", configs.Config.Bot.Prefix),
|
||||
},
|
||||
Category: Chattings,
|
||||
Category: Chatting,
|
||||
MessageRun: func(ctx *MsgContext) {
|
||||
learnedDataListRun(ctx.Session, ctx.Msg)
|
||||
},
|
||||
|
|
|
@ -26,12 +26,12 @@ type MuffinConfig struct {
|
|||
DBName string
|
||||
}
|
||||
|
||||
func loadConfig() *MuffinConfig {
|
||||
var Config *MuffinConfig
|
||||
|
||||
func init() {
|
||||
godotenv.Load()
|
||||
config := &MuffinConfig{Bot: botConfig{}, Train: trainConfig{}}
|
||||
setConfig(config)
|
||||
|
||||
return config
|
||||
setValues(config)
|
||||
}
|
||||
|
||||
func getRequiredValue(key string) string {
|
||||
|
@ -46,7 +46,7 @@ func getValue(key string) string {
|
|||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
func setConfig(config *MuffinConfig) {
|
||||
func setValues(config *MuffinConfig) {
|
||||
config.Bot.Prefix = getRequiredValue("BOT_PREFIX")
|
||||
config.Bot.Token = getRequiredValue("BOT_TOKEN")
|
||||
config.Bot.OwnerId = getRequiredValue("BOT_OWNER_ID")
|
||||
|
@ -56,5 +56,3 @@ func setConfig(config *MuffinConfig) {
|
|||
config.DatabaseURL = getRequiredValue("DATABASE_URL")
|
||||
config.DBName = getRequiredValue("DATABASE_NAME")
|
||||
}
|
||||
|
||||
var Config *MuffinConfig = loadConfig()
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
func connect() *mongo.Client {
|
||||
client, err := mongo.Connect(options.Client().ApplyURI(configs.Config.DatabaseURL))
|
||||
var Client *mongo.Client
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
Client, err = mongo.Connect(options.Client().ApplyURI(configs.Config.DatabaseURL))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
var Client *mongo.Client = connect()
|
||||
|
|
Loading…
Reference in a new issue