修复字符串分割bug

This commit is contained in:
liyp 2024-04-14 22:08:50 +08:00
parent fe4654e9e1
commit c5b0fe3bb5
3 changed files with 5 additions and 5 deletions

View file

@ -17,7 +17,7 @@ func main() {
// 去除末尾的换行符 // 去除末尾的换行符
// raw_msg = strings.TrimRight(raw_msg, "\r\n") // raw_msg = strings.TrimRight(raw_msg, "\r\n")
parms := strings.Split(raw_msg, " ") parms := strings.Fields(raw_msg)
worker := workers.NewWorker(parms, "11", "111", "111", "222", raw_msg) worker := workers.NewWorker(parms, "11", "111", "111", "222", raw_msg)
fmt.Println("Test:", worker.CheckPermission()) fmt.Println("Test:", worker.CheckPermission())

View file

@ -23,7 +23,7 @@ func Router(data map[string]interface{}) {
mid := data["message_id"].(float64) mid := data["message_id"].(float64)
raw_msg := data["raw_message"].(string)[1:] raw_msg := data["raw_message"].(string)[1:]
parms := strings.Split(raw_msg, " ") parms := strings.Fields(raw_msg)
worker := workers.NewWorker(parms, fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg) worker := workers.NewWorker(parms, fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)

View file

@ -20,8 +20,8 @@ func (a *Ip) GetMsg() string {
// 去除换行符 // 去除换行符
raw_msg := strings.TrimRight(a.RawMsg, "\n") raw_msg := strings.TrimRight(a.RawMsg, "\n")
fmt.Println("raw_msg:", raw_msg) fmt.Println("raw_msg:", raw_msg)
parms := strings.Split(raw_msg, " ") parms := strings.Fields(raw_msg)
url := "https://api.ip.sb/geoip/" + parms[0] url := "https://api.ip.sb/geoip/" + parms[1]
// fmt.Println("url: ", url) // fmt.Println("url: ", url)
@ -50,7 +50,7 @@ func (a *Ip) GetMsg() string {
return err.Error() return err.Error()
} }
// 输出响应数据 // 输出响应数据
// fmt.Println("data: ", data) fmt.Println("data: ", data)
if _, ok := data["code"].(float64); ok { if _, ok := data["code"].(float64); ok {
code := data["code"].(float64) code := data["code"].(float64)
if code == 401 { if code == 401 {