init go project

This commit is contained in:
MahnoKropotkinvich 2024-12-23 13:53:56 +08:00
parent 94df4a656f
commit add3c91903
2 changed files with 37 additions and 0 deletions

34
config.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
)
// 配置结构体
type Config struct {
Server struct {
Timeout int `yaml:"timeout"`
StartCommand string `yaml:"start_command"`
Address string `yaml:"address"`
} `yaml:"server"`
}
// 全局配置变量
var config Config
// 加载配置文件
func loadConfig(filePath string) error {
data, err := ioutil.ReadFile(filePath)
if err != nil {
getLogger().Errorf("Failed to read config file: %v", err)
return err
}
if err := yaml.Unmarshal(data, &config); err != nil {
getLogger().Errorf("Failed to unmarshal config: %v", err)
return err
}
getLogger().Info("Configuration loaded successfully")
return nil
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module minimcd
go 1.23.4