mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
style: move flag parse to internal/base
This commit is contained in:
parent
cd141d7d37
commit
cf21e81016
@ -17,11 +17,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetMessageFormat 设置消息上报格式,默认为string
|
|
||||||
func SetMessageFormat(f string) {
|
|
||||||
base.PostFormat = f
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式
|
// ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式
|
||||||
func ToFormattedMessage(e []message.IMessageElement, groupID int64, isRaw ...bool) (r interface{}) {
|
func ToFormattedMessage(e []message.IMessageElement, groupID int64, isRaw ...bool) (r interface{}) {
|
||||||
if base.PostFormat == "string" {
|
if base.PostFormat == "string" {
|
||||||
|
@ -26,20 +26,22 @@ var currentPath = getCurrentPath()
|
|||||||
// DefaultConfigFile 默认配置文件路径
|
// DefaultConfigFile 默认配置文件路径
|
||||||
var DefaultConfigFile = path.Join(currentPath, "config.yml")
|
var DefaultConfigFile = path.Join(currentPath, "config.yml")
|
||||||
|
|
||||||
|
type Reconnect struct {
|
||||||
|
Disabled bool `yaml:"disabled"`
|
||||||
|
Delay uint `yaml:"delay"`
|
||||||
|
MaxTimes uint `yaml:"max-times"`
|
||||||
|
Interval int `yaml:"interval"`
|
||||||
|
}
|
||||||
|
|
||||||
// Config 总配置文件
|
// Config 总配置文件
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Account struct {
|
Account struct {
|
||||||
Uin int64 `yaml:"uin"`
|
Uin int64 `yaml:"uin"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
Encrypt bool `yaml:"encrypt"`
|
Encrypt bool `yaml:"encrypt"`
|
||||||
Status int32 `yaml:"status"`
|
Status int `yaml:"status"`
|
||||||
ReLogin struct {
|
ReLogin *Reconnect `yaml:"relogin"`
|
||||||
Disabled bool `yaml:"disabled"`
|
UseSSOAddress bool `yaml:"use-sso-address"`
|
||||||
Delay uint `yaml:"delay"`
|
|
||||||
MaxTimes uint `yaml:"max-times"`
|
|
||||||
Interval int `yaml:"interval"`
|
|
||||||
}
|
|
||||||
UseSSOAddress bool `yaml:"use-sso-address"`
|
|
||||||
} `yaml:"account"`
|
} `yaml:"account"`
|
||||||
|
|
||||||
Heartbeat struct {
|
Heartbeat struct {
|
||||||
|
@ -2,12 +2,23 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global/config"
|
"github.com/Mrs4s/go-cqhttp/global/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// flags
|
// command flags
|
||||||
|
var (
|
||||||
|
LittleC string // config file
|
||||||
|
LittleD bool // daemon
|
||||||
|
LittleH bool // help
|
||||||
|
LittleWD string // working directory
|
||||||
|
)
|
||||||
|
|
||||||
|
// config file flags
|
||||||
var (
|
var (
|
||||||
Debug bool // 是否开启 debug 模式
|
Debug bool // 是否开启 debug 模式
|
||||||
RemoveReplyAt bool // 是否删除reply后的at
|
RemoveReplyAt bool // 是否删除reply后的at
|
||||||
@ -16,32 +27,59 @@ var (
|
|||||||
SplitURL bool // 是否分割URL
|
SplitURL bool // 是否分割URL
|
||||||
ForceFragmented bool // 是否启用强制分片
|
ForceFragmented bool // 是否启用强制分片
|
||||||
SkipMimeScan bool // 是否跳过Mime扫描
|
SkipMimeScan bool // 是否跳过Mime扫描
|
||||||
|
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
|
||||||
|
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
|
||||||
|
FastStart bool // 是否为快速启动
|
||||||
|
|
||||||
PostFormat = "string" // 上报格式 string or array
|
PostFormat string // 上报格式 string or array
|
||||||
Proxy string // 存储 proxy_rewrite,用于设置代理
|
Proxy string // 存储 proxy_rewrite,用于设置代理
|
||||||
PasswordHash [16]byte // 存储QQ密码哈希供登录使用
|
PasswordHash [16]byte // 存储QQ密码哈希供登录使用
|
||||||
AccountToken []byte // 存储AccountToken供登录使用
|
AccountToken []byte // 存储 AccountToken 供登录使用
|
||||||
|
Reconnect *config.Reconnect // 重连配置
|
||||||
|
LogAging = time.Hour * 24 * 365 // 日志时效
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse parses flags from config file
|
// Parse parse flags
|
||||||
func Parse() {
|
func Parse() {
|
||||||
|
flag.StringVar(&LittleC, "c", config.DefaultConfigFile, "configuration filename")
|
||||||
|
flag.BoolVar(&LittleD, "d", false, "running as a daemon")
|
||||||
|
flag.BoolVar(&LittleH, "h", false, "this help")
|
||||||
|
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
|
||||||
|
d := flag.Bool("D", false, "debug mode")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
config.DefaultConfigFile = LittleC // cover config file
|
||||||
|
if *d {
|
||||||
|
Debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init read config from yml file
|
||||||
|
func Init() {
|
||||||
conf := config.Get()
|
conf := config.Get()
|
||||||
{ // bool config
|
{ // bool config
|
||||||
Debug = conf.Output.Debug
|
if conf.Output.Debug {
|
||||||
|
Debug = true
|
||||||
|
}
|
||||||
IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
|
IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
|
||||||
SplitURL = conf.Message.FixURL
|
SplitURL = conf.Message.FixURL
|
||||||
RemoveReplyAt = conf.Message.RemoveReplyAt
|
RemoveReplyAt = conf.Message.RemoveReplyAt
|
||||||
ExtraReplyData = conf.Message.ExtraReplyData
|
ExtraReplyData = conf.Message.ExtraReplyData
|
||||||
ForceFragmented = conf.Message.ForceFragment
|
ForceFragmented = conf.Message.ForceFragment
|
||||||
SkipMimeScan = conf.Message.SkipMimeScan
|
SkipMimeScan = conf.Message.SkipMimeScan
|
||||||
|
UseSSOAddress = conf.Account.UseSSOAddress
|
||||||
}
|
}
|
||||||
{ // string
|
{ // others
|
||||||
Proxy = conf.Message.ProxyRewrite
|
Proxy = conf.Message.ProxyRewrite
|
||||||
|
Reconnect = conf.Account.ReLogin
|
||||||
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
|
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
|
||||||
log.Warnf("post-format 配置错误, 将自动使用 string")
|
log.Warnf("post-format 配置错误, 将自动使用 string")
|
||||||
PostFormat = "string"
|
PostFormat = "string"
|
||||||
} else {
|
} else {
|
||||||
PostFormat = conf.Message.PostFormat
|
PostFormat = conf.Message.PostFormat
|
||||||
}
|
}
|
||||||
|
if conf.Output.LogAging > 0 {
|
||||||
|
LogAging = time.Hour * 24 * time.Duration(conf.Output.LogAging)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
109
main.go
109
main.go
@ -35,68 +35,42 @@ import (
|
|||||||
"github.com/Mrs4s/go-cqhttp/server"
|
"github.com/Mrs4s/go-cqhttp/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// 允许通过配置文件设置的状态列表
|
||||||
conf *config.Config
|
var allowStatus = [...]client.UserOnlineStatus{
|
||||||
isFastStart = false
|
client.StatusOnline, client.StatusAway, client.StatusInvisible, client.StatusBusy,
|
||||||
|
client.StatusListening, client.StatusConstellation, client.StatusWeather, client.StatusMeetSpring,
|
||||||
// 允许通过配置文件设置的状态列表
|
client.StatusTimi, client.StatusEatChicken, client.StatusLoving, client.StatusWangWang, client.StatusCookedRice,
|
||||||
allowStatus = [...]client.UserOnlineStatus{
|
client.StatusStudy, client.StatusStayUp, client.StatusPlayBall, client.StatusSignal, client.StatusStudyOnline,
|
||||||
client.StatusOnline, client.StatusAway, client.StatusInvisible, client.StatusBusy,
|
client.StatusGaming, client.StatusVacationing, client.StatusWatchingTV, client.StatusFitness,
|
||||||
client.StatusListening, client.StatusConstellation, client.StatusWeather, client.StatusMeetSpring,
|
}
|
||||||
client.StatusTimi, client.StatusEatChicken, client.StatusLoving, client.StatusWangWang, client.StatusCookedRice,
|
|
||||||
client.StatusStudy, client.StatusStayUp, client.StatusPlayBall, client.StatusSignal, client.StatusStudyOnline,
|
|
||||||
client.StatusGaming, client.StatusVacationing, client.StatusWatchingTV, client.StatusFitness,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := flag.String("c", config.DefaultConfigFile, "configuration filename")
|
|
||||||
d := flag.Bool("d", false, "running as a daemon")
|
|
||||||
h := flag.Bool("h", false, "this help")
|
|
||||||
wd := flag.String("w", "", "cover the working directory")
|
|
||||||
debug := flag.Bool("D", false, "debug mode")
|
|
||||||
flag.Parse()
|
|
||||||
// todo: maybe move flag to internal/base?
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case *h:
|
|
||||||
help()
|
|
||||||
case *d:
|
|
||||||
server.Daemon()
|
|
||||||
case *wd != "":
|
|
||||||
resetWorkDir(*wd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通过-c 参数替换 配置文件路径
|
|
||||||
config.DefaultConfigFile = *c
|
|
||||||
conf = config.Get()
|
|
||||||
if *debug {
|
|
||||||
conf.Output.Debug = true
|
|
||||||
}
|
|
||||||
base.Parse()
|
base.Parse()
|
||||||
if base.Debug {
|
switch {
|
||||||
log.SetReportCaller(true)
|
case base.LittleH:
|
||||||
|
help()
|
||||||
|
case base.LittleD:
|
||||||
|
server.Daemon()
|
||||||
|
case base.LittleWD != "":
|
||||||
|
resetWorkDir()
|
||||||
}
|
}
|
||||||
|
base.Init()
|
||||||
|
|
||||||
|
// todo: do all config parse in internal/base?
|
||||||
|
conf := config.Get()
|
||||||
|
|
||||||
rotateOptions := []rotatelogs.Option{
|
rotateOptions := []rotatelogs.Option{
|
||||||
rotatelogs.WithRotationTime(time.Hour * 24),
|
rotatelogs.WithRotationTime(time.Hour * 24),
|
||||||
}
|
}
|
||||||
|
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(base.LogAging))
|
||||||
if conf.Output.LogAging > 0 {
|
if base.LogForceNew {
|
||||||
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(time.Hour*24*time.Duration(conf.Output.LogAging)))
|
|
||||||
} else {
|
|
||||||
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(time.Hour*24*365*10))
|
|
||||||
}
|
|
||||||
if conf.Output.LogForceNew {
|
|
||||||
rotateOptions = append(rotateOptions, rotatelogs.ForceNewFile())
|
rotateOptions = append(rotateOptions, rotatelogs.ForceNewFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotateOptions...)
|
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotateOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("rotatelogs init err: %v", err)
|
log.Errorf("rotatelogs init err: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.AddHook(global.NewLocalHook(w, global.LogFormat{}, global.GetLogLevel(conf.Output.LogLevel)...))
|
log.AddHook(global.NewLocalHook(w, global.LogFormat{}, global.GetLogLevel(conf.Output.LogLevel)...))
|
||||||
|
|
||||||
mkCacheDir := func(path string, _type string) {
|
mkCacheDir := func(path string, _type string) {
|
||||||
@ -129,11 +103,12 @@ func main() {
|
|||||||
para.Hide(p)
|
para.Hide(p)
|
||||||
}
|
}
|
||||||
case "faststart":
|
case "faststart":
|
||||||
isFastStart = true
|
base.FastStart = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if terminal.RunningByDoubleClick() && !isFastStart {
|
|
||||||
|
if !base.FastStart && terminal.RunningByDoubleClick() {
|
||||||
err := terminal.NoMoreDoubleClick()
|
err := terminal.NoMoreDoubleClick()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("遇到错误: %v", err)
|
log.Errorf("遇到错误: %v", err)
|
||||||
@ -144,7 +119,7 @@ func main() {
|
|||||||
|
|
||||||
if (conf.Account.Uin == 0 || (conf.Account.Password == "" && !conf.Account.Encrypt)) && !global.PathExists("session.token") {
|
if (conf.Account.Uin == 0 || (conf.Account.Password == "" && !conf.Account.Encrypt)) && !global.PathExists("session.token") {
|
||||||
log.Warn("账号密码未配置, 将使用二维码登录.")
|
log.Warn("账号密码未配置, 将使用二维码登录.")
|
||||||
if !isFastStart {
|
if !base.FastStart {
|
||||||
log.Warn("将在 5秒 后继续.")
|
log.Warn("将在 5秒 后继续.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
@ -153,6 +128,7 @@ func main() {
|
|||||||
log.Info("当前版本:", base.Version)
|
log.Info("当前版本:", base.Version)
|
||||||
if base.Debug {
|
if base.Debug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
log.SetReportCaller(true)
|
||||||
log.Warnf("已开启Debug模式.")
|
log.Warnf("已开启Debug模式.")
|
||||||
log.Debugf("开发交流群: 192548878")
|
log.Debugf("开发交流群: 192548878")
|
||||||
}
|
}
|
||||||
@ -221,7 +197,7 @@ func main() {
|
|||||||
} else if len(conf.Account.Password) > 0 {
|
} else if len(conf.Account.Password) > 0 {
|
||||||
base.PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
base.PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
||||||
}
|
}
|
||||||
if !isFastStart {
|
if !base.FastStart {
|
||||||
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
@ -304,19 +280,19 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Warnf("Bot已离线: %v", e.Message)
|
log.Warnf("Bot已离线: %v", e.Message)
|
||||||
time.Sleep(time.Second * time.Duration(conf.Account.ReLogin.Delay))
|
time.Sleep(time.Second * time.Duration(base.Reconnect.Delay))
|
||||||
for {
|
for {
|
||||||
if conf.Account.ReLogin.Disabled {
|
if base.Reconnect.Disabled {
|
||||||
log.Warnf("未启用自动重连, 将退出.")
|
log.Warnf("未启用自动重连, 将退出.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if times > conf.Account.ReLogin.MaxTimes && conf.Account.ReLogin.MaxTimes != 0 {
|
if times > base.Reconnect.MaxTimes && base.Reconnect.MaxTimes != 0 {
|
||||||
log.Fatalf("Bot重连次数超过限制, 停止")
|
log.Fatalf("Bot重连次数超过限制, 停止")
|
||||||
}
|
}
|
||||||
times++
|
times++
|
||||||
if conf.Account.ReLogin.Interval > 0 {
|
if base.Reconnect.Interval > 0 {
|
||||||
log.Warnf("将在 %v 秒后尝试重连. 重连次数:%v/%v", conf.Account.ReLogin.Interval, times, conf.Account.ReLogin.MaxTimes)
|
log.Warnf("将在 %v 秒后尝试重连. 重连次数:%v/%v", base.Reconnect.Interval, times, base.Reconnect.MaxTimes)
|
||||||
time.Sleep(time.Second * time.Duration(conf.Account.ReLogin.Interval))
|
time.Sleep(time.Second * time.Duration(base.Reconnect.Interval))
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
@ -353,17 +329,17 @@ func main() {
|
|||||||
log.Infof("开始加载群列表...")
|
log.Infof("开始加载群列表...")
|
||||||
global.Check(cli.ReloadGroupList(), true)
|
global.Check(cli.ReloadGroupList(), true)
|
||||||
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
||||||
if conf.Account.Status >= int32(len(allowStatus)) || conf.Account.Status < 0 {
|
if uint(conf.Account.Status) >= uint(len(allowStatus)) {
|
||||||
conf.Account.Status = 0
|
conf.Account.Status = 0
|
||||||
}
|
}
|
||||||
cli.SetOnlineStatus(allowStatus[int(conf.Account.Status)])
|
cli.SetOnlineStatus(allowStatus[conf.Account.Status])
|
||||||
bot := coolq.NewQQBot(cli, conf)
|
bot := coolq.NewQQBot(cli, conf)
|
||||||
for _, m := range conf.Servers {
|
for _, m := range conf.Servers {
|
||||||
if h, ok := m["http"]; ok {
|
if h, ok := m["http"]; ok {
|
||||||
hc := new(config.HTTPServer)
|
hc := new(config.HTTPServer)
|
||||||
if err := h.Decode(hc); err != nil {
|
if err := h.Decode(hc); err != nil {
|
||||||
log.Warn("读取http配置失败 :", err)
|
log.Warn("读取http配置失败 :", err)
|
||||||
} else {
|
} else if !hc.Disabled {
|
||||||
go server.RunHTTPServerAndClients(bot, hc)
|
go server.RunHTTPServerAndClients(bot, hc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,7 +347,7 @@ func main() {
|
|||||||
sc := new(config.WebsocketServer)
|
sc := new(config.WebsocketServer)
|
||||||
if err := s.Decode(sc); err != nil {
|
if err := s.Decode(sc); err != nil {
|
||||||
log.Warn("读取正向Websocket配置失败 :", err)
|
log.Warn("读取正向Websocket配置失败 :", err)
|
||||||
} else {
|
} else if !sc.Disabled {
|
||||||
go server.RunWebSocketServer(bot, sc)
|
go server.RunWebSocketServer(bot, sc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,7 +355,7 @@ func main() {
|
|||||||
rc := new(config.WebsocketReverse)
|
rc := new(config.WebsocketReverse)
|
||||||
if err := c.Decode(rc); err != nil {
|
if err := c.Decode(rc); err != nil {
|
||||||
log.Warn("读取反向Websocket配置失败 :", err)
|
log.Warn("读取反向Websocket配置失败 :", err)
|
||||||
} else {
|
} else if !rc.Disabled {
|
||||||
go server.RunWebSocketClient(bot, rc)
|
go server.RunWebSocketClient(bot, rc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,7 +363,7 @@ func main() {
|
|||||||
pc := new(config.PprofServer)
|
pc := new(config.PprofServer)
|
||||||
if err := p.Decode(pc); err != nil {
|
if err := p.Decode(pc); err != nil {
|
||||||
log.Warn("读取pprof配置失败 :", err)
|
log.Warn("读取pprof配置失败 :", err)
|
||||||
} else {
|
} else if !pc.Disabled {
|
||||||
go server.RunPprofServer(pc)
|
go server.RunPprofServer(pc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,7 +371,7 @@ func main() {
|
|||||||
lc := new(config.LambdaServer)
|
lc := new(config.LambdaServer)
|
||||||
if err := p.Decode(lc); err != nil {
|
if err := p.Decode(lc); err != nil {
|
||||||
log.Warn("读取pprof配置失败 :", err)
|
log.Warn("读取pprof配置失败 :", err)
|
||||||
} else {
|
} else if !lc.Disabled {
|
||||||
go server.RunLambdaClient(bot, lc)
|
go server.RunLambdaClient(bot, lc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -455,7 +431,8 @@ Options:
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetWorkDir(wd string) {
|
func resetWorkDir() {
|
||||||
|
wd := base.LittleWD
|
||||||
args := make([]string, 0, len(os.Args))
|
args := make([]string, 0, len(os.Args))
|
||||||
for i := 1; i < len(os.Args); i++ {
|
for i := 1; i < len(os.Args); i++ {
|
||||||
if os.Args[i] == "-w" {
|
if os.Args[i] == "-w" {
|
||||||
@ -480,7 +457,7 @@ func resetWorkDir(wd string) {
|
|||||||
func newClient() *client.QQClient {
|
func newClient() *client.QQClient {
|
||||||
c := client.NewClientEmpty()
|
c := client.NewClientEmpty()
|
||||||
c.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
c.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
||||||
if !conf.Account.UseSSOAddress {
|
if !base.UseSSOAddress {
|
||||||
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -151,9 +151,6 @@ func checkAuth(req *http.Request, token string) int {
|
|||||||
|
|
||||||
// RunHTTPServerAndClients 启动HTTP服务器与HTTP上报客户端
|
// RunHTTPServerAndClients 启动HTTP服务器与HTTP上报客户端
|
||||||
func RunHTTPServerAndClients(bot *coolq.CQBot, conf *config.HTTPServer) {
|
func RunHTTPServerAndClients(bot *coolq.CQBot, conf *config.HTTPServer) {
|
||||||
if conf.Disabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
s = new(httpServer)
|
s = new(httpServer)
|
||||||
addr string
|
addr string
|
||||||
|
@ -14,9 +14,6 @@ import (
|
|||||||
|
|
||||||
// RunPprofServer 启动 pprof 性能分析服务器
|
// RunPprofServer 启动 pprof 性能分析服务器
|
||||||
func RunPprofServer(conf *config.PprofServer) {
|
func RunPprofServer(conf *config.PprofServer) {
|
||||||
if conf.Disabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addr := fmt.Sprintf("%s:%d", conf.Host, conf.Port)
|
addr := fmt.Sprintf("%s:%d", conf.Host, conf.Port)
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||||
|
@ -56,9 +56,6 @@ var upgrader = websocket.Upgrader{
|
|||||||
|
|
||||||
// RunWebSocketServer 运行一个正向WS server
|
// RunWebSocketServer 运行一个正向WS server
|
||||||
func RunWebSocketServer(b *coolq.CQBot, conf *config.WebsocketServer) {
|
func RunWebSocketServer(b *coolq.CQBot, conf *config.WebsocketServer) {
|
||||||
if conf.Disabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s := &webSocketServer{
|
s := &webSocketServer{
|
||||||
bot: b,
|
bot: b,
|
||||||
conf: conf,
|
conf: conf,
|
||||||
@ -82,9 +79,6 @@ func RunWebSocketServer(b *coolq.CQBot, conf *config.WebsocketServer) {
|
|||||||
|
|
||||||
// RunWebSocketClient 运行一个正向WS client
|
// RunWebSocketClient 运行一个正向WS client
|
||||||
func RunWebSocketClient(b *coolq.CQBot, conf *config.WebsocketReverse) {
|
func RunWebSocketClient(b *coolq.CQBot, conf *config.WebsocketReverse) {
|
||||||
if conf.Disabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c := &websocketClient{
|
c := &websocketClient{
|
||||||
bot: b,
|
bot: b,
|
||||||
conf: conf,
|
conf: conf,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user