支持了是否显示预设msg的配置
This commit is contained in:
parent
6f4d653835
commit
9e0f7bd2ea
|
|
@ -187,10 +187,10 @@ func initConfig() {
|
||||||
viper.AddConfigPath(configDir)
|
viper.AddConfigPath(configDir)
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
|
logger.UpdateLogLevel()
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
logger.Error("Error initializing config: %v", err)
|
logger.Error("Error initializing config: %v", err)
|
||||||
}
|
}
|
||||||
logger.UpdateLogLevel()
|
|
||||||
logger.Debug("Initializing...")
|
logger.Debug("Initializing...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExecParams struct {
|
type ExecParams struct {
|
||||||
|
|
@ -30,6 +32,10 @@ func NewUnixSocketTask() *UnixSocketTask {
|
||||||
return &UnixSocketTask{}
|
return &UnixSocketTask{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
viper.SetDefault("reporter.show_msg", true)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *UnixSocketTask) Execute(ctx context.Context) {
|
func (t *UnixSocketTask) Execute(ctx context.Context) {
|
||||||
socketPath := constants.SocketPath
|
socketPath := constants.SocketPath
|
||||||
|
|
||||||
|
|
@ -167,23 +173,27 @@ func (t *UnixSocketTask) handleConnection(conn net.Conn) {
|
||||||
// 在HTTP调用前发送[start]标记
|
// 在HTTP调用前发送[start]标记
|
||||||
t.writeMessage(conn, "[sthttp]")
|
t.writeMessage(conn, "[sthttp]")
|
||||||
|
|
||||||
initialMessage := constants.ColorBlue + "检测到您的命令执行出现错误! \n" + constants.ColorReset
|
showMsg := viper.GetBool("reporter.show_msg")
|
||||||
t.writeMessage(conn, initialMessage)
|
|
||||||
logger.Debug("write: %s", initialMessage)
|
|
||||||
// 显示加载动画
|
// 显示加载动画
|
||||||
loading := true
|
loading := true
|
||||||
go func() {
|
if showMsg {
|
||||||
frames := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
|
initialMessage := constants.ColorBlue + "检测到您的命令执行出现错误! \n" + constants.ColorReset
|
||||||
i := 0
|
t.writeMessage(conn, initialMessage)
|
||||||
for loading {
|
go func() {
|
||||||
t.writeMessage(conn, "\r正在查找解决方案"+frames[i%len(frames)])
|
frames := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
|
||||||
time.Sleep(100 * time.Millisecond)
|
i := 0
|
||||||
i++
|
for loading {
|
||||||
}
|
t.writeMessage(conn, "\r正在查找解决方案"+frames[i%len(frames)])
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
client := client.NewClient()
|
client := client.NewClient()
|
||||||
|
|
||||||
handleQuestion := func(question string) {
|
handleQuestion := func(question string) {
|
||||||
|
|
@ -210,10 +220,19 @@ func (t *UnixSocketTask) handleConnection(conn net.Conn) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("PostToStream error: %v", err)
|
logger.Error("PostToStream error: %v", err)
|
||||||
|
if showMsg {
|
||||||
|
t.writeMessage(conn, constants.ColorRed+"请求失败,请稍后再试"+constants.ColorReset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resetMsg string
|
||||||
|
if showMsg {
|
||||||
|
resetMsg = constants.ColorReset
|
||||||
|
} else {
|
||||||
|
resetMsg = "\n\r" + constants.ColorReset
|
||||||
|
}
|
||||||
// 结束后发送结束标记
|
// 结束后发送结束标记
|
||||||
t.writeMessage(conn, "\n\r"+constants.ColorReset)
|
t.writeMessage(conn, resetMsg)
|
||||||
t.writeMessage(conn, "[end]")
|
t.writeMessage(conn, "[end]")
|
||||||
conn.Close() // 关闭连接,防止客户端一直等待inf
|
conn.Close() // 关闭连接,防止客户端一直等待inf
|
||||||
logger.Debug("connection done.")
|
logger.Debug("connection done.")
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func WithBaseURL(baseURL string) ClientOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
viper.SetDefault("machine_registry.endpoint", "http://localhost:3001/endpoint")
|
viper.SetDefault("machine_registry.endpoint", "https://bash-backend.zustmyy.top/endpoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(opts ...ClientOption) *Client {
|
func NewClient(opts ...ClientOption) *Client {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ const (
|
||||||
ClientTimeout = 120 * time.Second
|
ClientTimeout = 120 * time.Second
|
||||||
MachineInfoApi = "/machine"
|
MachineInfoApi = "/machine"
|
||||||
GetVersionApi = "/version"
|
GetVersionApi = "/version"
|
||||||
QuestionStreamApi = "/question"
|
QuestionStreamApi = "/problem"
|
||||||
GetConfigApi = "/config"
|
GetConfigApi = "/config"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue