mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 12:43:31 +08:00
env supported.
This commit is contained in:
parent
e2b6c3d607
commit
2670c84c8e
@ -15,7 +15,6 @@ type JsonConfig struct {
|
|||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||||
Proxy string `json:"proxy"`
|
|
||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
main.go
38
main.go
@ -18,6 +18,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -72,7 +73,34 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
console := bufio.NewReader(os.Stdin)
|
console := bufio.NewReader(os.Stdin)
|
||||||
conf := global.Load("config.json")
|
var conf *global.JsonConfig
|
||||||
|
if global.PathExists("config.json") || os.Getenv("UIN") == "" {
|
||||||
|
conf = global.Load("config.json")
|
||||||
|
} else if os.Getenv("UIN") != "" {
|
||||||
|
log.Infof("将从环境变量加载配置.")
|
||||||
|
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
||||||
|
pwd := os.Getenv("PASS")
|
||||||
|
post := os.Getenv("HTTP_POST")
|
||||||
|
conf = &global.JsonConfig{
|
||||||
|
Uin: uin,
|
||||||
|
Password: pwd,
|
||||||
|
HttpConfig: &global.GoCQHttpConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 5700,
|
||||||
|
PostUrls: map[string]string{},
|
||||||
|
},
|
||||||
|
WSConfig: &global.GoCQWebsocketConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 6700,
|
||||||
|
},
|
||||||
|
Debug: os.Getenv("DEBUG") == "true",
|
||||||
|
}
|
||||||
|
if post != "" {
|
||||||
|
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
||||||
|
}
|
||||||
|
}
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
err := global.DefaultConfig().Save("config.json")
|
err := global.DefaultConfig().Save("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,18 +108,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf.Uin == 0 || conf.Password == "" {
|
if conf.Uin == 0 || conf.Password == "" {
|
||||||
log.Fatal("请修改 config.json 以添加账号密码.")
|
log.Warnf("请修改 config.json 以添加账号密码.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if conf.Debug {
|
if conf.Debug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
log.Warnf("已开启Debug模式.")
|
log.Warnf("已开启Debug模式.")
|
||||||
}
|
}
|
||||||
if !global.PathExists("device.json") {
|
if !global.PathExists("device.json") {
|
||||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备,按 Enter 继续.")
|
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||||
_, _ = console.ReadString('\n')
|
|
||||||
client.GenRandomDevice()
|
client.GenRandomDevice()
|
||||||
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
||||||
log.Info("已生成设备信息并保存到 device.json 文件.")
|
log.Info("已生成设备信息并保存到 device.json 文件.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user