-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : Optimize log printing interface #26
- Loading branch information
taotao
committed
May 21, 2024
1 parent
ccfc876
commit 076ed2f
Showing
10 changed files
with
229 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package driver | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"runtime" | ||
"strconv" | ||
|
||
"github.com/pojol/gobot/driver/factory" | ||
"github.com/pojol/gobot/driver/mock" | ||
"github.com/pojol/gobot/driver/openapi" | ||
"github.com/pojol/gobot/driver/utils" | ||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
const ( | ||
// Version of gobot driver | ||
Version = "v0.4.4" | ||
|
||
banner = ` | ||
__ __ | ||
/\ \ /\ \__ | ||
__ ___\ \ \____ ___\ \ ,_\ | ||
/'_ '\ / __'\ \ '__'\ / __'\ \ \ | ||
/\ \L\ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_ | ||
\ \____ \ \____/\ \_,__/\ \____/\ \__\ | ||
\/___L\ \/___/ \/___/ \/___/ \/__/ | ||
/\____/ | ||
\_/__/ %s | ||
` | ||
) | ||
|
||
func Run() { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
var buf [4096]byte | ||
n := runtime.Stack(buf[:], false) | ||
fmt.Println("panic:", string(buf[:n])) | ||
} | ||
}() | ||
|
||
f := utils.InitFlag() | ||
flag.Parse() | ||
if utils.ShowUseage() { | ||
return | ||
} | ||
|
||
fmt.Printf(banner, Version) | ||
|
||
botFactory, err := factory.Create( | ||
factory.WithDatabase(f.DBType), | ||
factory.WithClusterMode(f.Cluster), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer botFactory.Close() | ||
|
||
L := lua.NewState() | ||
defer L.Close() | ||
L.DoFile(f.ScriptPath + "/" + "message.lua") | ||
byteOrder := L.GetGlobal("ByteOrder").String() | ||
|
||
if f.OpenHttpMock != 0 { | ||
ms := mock.NewHttpServer() | ||
go ms.Start(":" + strconv.Itoa(f.OpenHttpMock)) | ||
defer ms.Close() | ||
} | ||
|
||
if f.OpenTcpMock != 0 { | ||
tcpls := mock.StarTCPServer(byteOrder, ":"+strconv.Itoa(f.OpenTcpMock)) | ||
defer tcpls.Close() | ||
} | ||
|
||
if f.OpenWSMock != 0 { | ||
ws := mock.StartWebsocketServe(byteOrder, ":"+strconv.Itoa(f.OpenWSMock)) | ||
defer ws.Close() | ||
} | ||
|
||
go func() { | ||
http.ListenAndServe(":6060", nil) | ||
}() | ||
|
||
// 查看有没有未完成的队列 | ||
factory.Global.CheckTaskHistory() | ||
|
||
openApiPort := 8888 | ||
if f.OpenAPIPort != 0 { | ||
openApiPort = f.OpenAPIPort | ||
} | ||
|
||
e := openapi.Start(openApiPort) | ||
defer e.Close() | ||
|
||
// Stop the service gracefully. | ||
if err := e.Shutdown(context.TODO()); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.