From da37b8c8983a090950f1dae9fa02f5a800e09f56 Mon Sep 17 00:00:00 2001 From: kony <2312708932@qq.com> Date: Mon, 13 Jan 2025 15:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=8A=B6=E6=80=81=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FyneApp.toml | 2 +- pro/comm.go | 15 ++++----- pro/local.go | 33 +++++++++--------- pro/remote.go | 45 ++++++++++++------------- proxy/proxy_io.go | 4 +-- proxy/proxy_l.go | 4 +-- stun2/cli.go | 8 ++--- ui2/log.go | 57 +++++++++++++++++++++++++++---- ui2/ui.go | 39 +--------------------- utils/guard.go | 4 +-- utils/log.go | 85 +++++++++++++++++++++++++++++++++++++++++++++++ utils/net.go | 4 +-- 12 files changed, 192 insertions(+), 108 deletions(-) create mode 100644 utils/log.go diff --git a/FyneApp.toml b/FyneApp.toml index f2f84d2..516a00a 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -4,5 +4,5 @@ Website = "https://goodlink.kony.vip" Icon = "theme/favicon.png" Name = "goodlink-windows-amd64-ui" ID = "goodlink.kony.vip" - Version = "1.14.26" + Version = "1.14.27" Build = 0 diff --git a/pro/comm.go b/pro/comm.go index 5414b9f..afcff7d 100644 --- a/pro/comm.go +++ b/pro/comm.go @@ -6,9 +6,9 @@ import ( "fmt" "goodlink/aes" "goodlink/config" + "goodlink/utils" "goodlink2/tun" _ "goodlink2/tun" - "log" "time" "github.com/go-redis/redis" @@ -23,16 +23,16 @@ var ( ) func Init(m_cli_redis_addr, m_cli_redis_pass string, m_cli_redis_id int) error { - log.Println(" 初始化配置中") + utils.Log().Debug("初始化配置中") for { if err := config.Init(); err != nil { - log.Println(err) + utils.Log().Debug(err.Error()) time.Sleep(3 * time.Second) continue } break } - log.Println(" 初始化配置完成") + utils.Log().Debug("初始化配置完成") if m_cli_redis_addr == "" { m_cli_redis_addr = config.GetAddr() @@ -60,8 +60,7 @@ func Init(m_cli_redis_addr, m_cli_redis_pass string, m_cli_redis_id int) error { } func Release() { - log.Println(" 全局释放资源开始") - defer log.Println(" 全局释放资源结束") + utils.Log().SetDebugSate(0) if m_tun_active != nil { m_tun_active.Release() @@ -105,11 +104,11 @@ func RedisGet(redisJson *RedisJsonType) error { aes_res, err := m_redis_db.Get(m_md5_tun_key).Bytes() if err != nil || aes_res == nil || len(aes_res) == 0 { - return fmt.Errorf(" 获取信令数据失败: %v", err) + return fmt.Errorf("获取信令数据失败: %v", err) } if err = json.Unmarshal(aes.Decrypt(aes_res, m_tun_key), redisJson); err != nil { - return fmt.Errorf(" 解析信令数据失败: %v", err) + return fmt.Errorf("解析信令数据失败: %v", err) } return nil diff --git a/pro/local.go b/pro/local.go index e81898e..bde948d 100644 --- a/pro/local.go +++ b/pro/local.go @@ -8,13 +8,10 @@ import ( "goodlink/utils" "goodlink2/tun" _ "goodlink2/tun" - "log" "net" "strings" "time" - "gogo" - "github.com/quic-go/quic-go" ) @@ -36,17 +33,17 @@ func GetLocalQuicConn(conn_type int, count int) (quic.Connection, quic.Stream, e SessionID := string(utils.RandomBytes(24)) redisJson.SessionID = SessionID - gogo.Log().DebugF(" 会话ID: %s", SessionID) + utils.Log().DebugF("会话ID: %s", SessionID) switch conn_type { case 0: - gogo.Log().Debug("0: 请求连接对端") + utils.Log().Debug("请求连接对端") RedisSet(15*time.Second, &redisJson) default: redisJson.ClientIP, redisJson.ClientPort1, redisJson.ClientPort2 = ClientIP, ClientPort1, ClientPort2 redisJson.State = 0 - gogo.Log().DebugF("%d: 发送本端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("发送本端地址: %v", redisJson) RedisSet(15*time.Second, &redisJson) } @@ -54,18 +51,20 @@ func GetLocalQuicConn(conn_type int, count int) (quic.Connection, quic.Stream, e time.Sleep(1 * time.Second) if RedisGet(&redisJson) != nil { - gogo.Log().Debug(" 连接超时") + utils.Log().Debug("连接超时") return nil, nil, nil } + utils.Log().SetDebugSate(redisJson.State) + if !strings.EqualFold(redisJson.SessionID, SessionID) { - gogo.Log().Debug(" 连接被重置") + utils.Log().Debug("连接被重置") return nil, nil, nil } switch redisJson.State { case 1: - gogo.Log().DebugF("%d: 收到对端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("收到对端地址: %v", redisJson) switch conn_type { case 0: @@ -84,7 +83,7 @@ func GetLocalQuicConn(conn_type int, count int) (quic.Connection, quic.Stream, e m_tun_passive.Start() redisJson.State = 2 - gogo.Log().DebugF("%d: 发送本端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("发送本端地址: %v", redisJson) RedisSet(redisJson.RedisTimeOut, &redisJson) go m_tun_passive.Start() @@ -109,25 +108,25 @@ func GetLocalQuicConn(conn_type int, count int) (quic.Connection, quic.Stream, e case 3: if m_tun_passive != nil { if m_tun_passive.TunQuicConn != nil { - gogo.Log().DebugF("%d: 连接成功", redisJson.State) + utils.Log().DebugF("连接成功") return m_tun_passive.TunQuicConn, m_tun_passive.TunHealthStream, nil } } if m_tun_active != nil { if m_tun_active.TunQuicConn != nil { - gogo.Log().DebugF("%d: 连接成功", redisJson.State) + utils.Log().DebugF("连接成功") return m_tun_active.TunQuicConn, m_tun_active.TunHealthStream, nil } } - gogo.Log().Debug(" 连接失败") + utils.Log().Debug("连接失败") return nil, nil, nil case 4: - gogo.Log().DebugF("%d: 连接超时", redisJson.State) + utils.Log().Debug("连接超时") return nil, nil, nil default: - gogo.Log().DebugF("%d: 等待对端状态", redisJson.State) + utils.Log().Debug("等待对端状态") } } @@ -147,7 +146,7 @@ func StopLocal() error { func RunLocal(conn_type int, tun_local_addr string, tun_key string) error { m_local_state = 1 - log.Printf(" 绑定端口: %v", tun_local_addr) + utils.Log().DebugF("绑定端口: %v", tun_local_addr) chain := make(chan int, 1) @@ -189,7 +188,7 @@ func RunLocal(conn_type int, tun_local_addr string, tun_key string) error { if m_local_state != 0 { m_local_state = 1 } - gogo.Log().DebugF(" 释放连接: %v", conn.LocalAddr()) + utils.Log().DebugF("释放连接: %v", conn.LocalAddr()) Release() if conn, err := net.Dial("tcp", tun_local_addr); conn != nil && err == nil { diff --git a/pro/remote.go b/pro/remote.go index 7396533..9559365 100644 --- a/pro/remote.go +++ b/pro/remote.go @@ -8,13 +8,10 @@ import ( "goodlink/utils" "goodlink2/tun" _ "goodlink2/tun" - "log" "strings" "sync" "time" - "gogo" - "github.com/quic-go/quic-go" ) @@ -35,30 +32,32 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { } SessionID := redisJson.SessionID - gogo.Log().DebugF(" 会话ID: %s", SessionID) + utils.Log().DebugF("会话ID: %s", SessionID) for m_remote_stats == 1 { time.Sleep(1 * time.Second) if RedisGet(&redisJson) != nil { - gogo.Log().Debug(" 连接超时") + utils.Log().Debug("连接超时") return nil, nil } + utils.Log().SetDebugSate(redisJson.State) + if !strings.EqualFold(redisJson.SessionID, SessionID) { - gogo.Log().Debug(" 连接被重置") + utils.Log().Debug("连接被重置") return nil, nil } if redisJson.State < last_state { m_redis_db.Del(m_md5_tun_key) - gogo.Log().DebugF(" 状态异常: %d -> %d", last_state, redisJson.State) + utils.Log().DebugF("状态异常: %d -> %d", last_state, redisJson.State) return nil, nil } if redisJson.State != 3 && redisJson.State != 4 && redisJson.State-last_state > 1 { m_redis_db.Del(m_md5_tun_key) - gogo.Log().DebugF(" 状态异常: %d -> %d", last_state, redisJson.State) + utils.Log().DebugF("状态异常: %d -> %d", last_state, redisJson.State) return nil, nil } @@ -67,7 +66,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { switch redisJson.State { case 0: - gogo.Log().DebugF("%d: 收到对端请求: %v", redisJson.State, redisJson) + utils.Log().DebugF("收到对端请求: %v", redisJson) conn := utils.GetListenUDP() redisJson.ServerIP, redisJson.ServerPort1, redisJson.ServerPort2 = stun2.GetWanIpPort2(conn) @@ -75,7 +74,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { switch redisJson.ClientPort1 { case 0: conn_type = 0 - gogo.Log().Debug(" 对端未发来IP") + utils.Log().Debug("对端未发来IP") if m_tun_active != nil { m_tun_active.Release() @@ -87,11 +86,11 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { redisJson.State = 1 redisJson.SendPortCount = 0x100 - gogo.Log().DebugF("%d: 发送本端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("发送本端地址: %v", redisJson) RedisSet(redisJson.RedisTimeOut, &redisJson) default: - gogo.Log().Debug(" 对端有发来IP") + utils.Log().Debug("对端有发来IP") conn_type = 1 if m_tun_passive != nil { @@ -105,7 +104,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { tun_passive_chain = m_tun_passive.GetChain() redisJson.State = 1 - gogo.Log().DebugF("%d: 发送本端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("发送本端地址: %v", redisJson) RedisSet(redisJson.RedisTimeOut, &redisJson) go m_tun_passive.Start() @@ -114,17 +113,17 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { case 2: switch conn_type { case 0: - gogo.Log().DebugF("%d: 收到对端地址: %v", redisJson.State, redisJson) + utils.Log().DebugF("收到对端地址: %v", redisJson) m_tun_active.Start(redisJson.ServerPort1, redisJson.ServerPort2, redisJson.ClientIP, redisJson.ClientPort1, redisJson.ClientPort2, redisJson.SocketTimeOut) case 1: - gogo.Log().DebugF("%d: 收到对端地址, 等待连接: %v", redisJson.State, redisJson) + utils.Log().DebugF("收到对端地址, 等待连接: %v", redisJson) } select { case <-tun_active_chain: redisJson.State = 3 - gogo.Log().DebugF("%d: 通知对端, 连接成功", redisJson.State) + utils.Log().Debug("通知对端, 连接成功") RedisSet(redisJson.RedisTimeOut, &redisJson) if m_tun_active != nil { return m_tun_active.TunQuicConn, m_tun_active.TunHealthStream @@ -133,7 +132,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { case <-tun_passive_chain: redisJson.State = 3 - gogo.Log().DebugF("%d: 通知对端, 连接成功", redisJson.State) + utils.Log().Debug("通知对端, 连接成功") RedisSet(redisJson.RedisTimeOut, &redisJson) if m_tun_passive != nil { return m_tun_passive.TunQuicConn, m_tun_passive.TunHealthStream @@ -142,7 +141,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { case <-time.After(time_out): redisJson.State = 4 - gogo.Log().DebugF("%d: 通知对端, 连接超时", redisJson.State) + utils.Log().Debug("通知对端, 连接超时") RedisSet(redisJson.RedisTimeOut, &redisJson) return nil, nil } @@ -150,7 +149,7 @@ func GetRemoteQuicConn(time_out time.Duration) (quic.Connection, quic.Stream) { case 3, 4: default: - gogo.Log().DebugF("%d: 等待对端状态", redisJson.State) + utils.Log().Debug("等待对端状态") } last_state = redisJson.State @@ -170,10 +169,10 @@ func RunRemote(remote_addr string, tun_key string, time_out time.Duration) error var wg sync.WaitGroup if remote_addr == "" { - log.Println(" 开启本地代理") + utils.Log().Debug("开启本地代理") remote_addr = utils.GetFreeLocalAddr() if remote_addr == "" { - return errors.New(" 获取本地端口失败") + return errors.New("获取本地端口失败") } wg.Add(1) @@ -183,7 +182,7 @@ func RunRemote(remote_addr string, tun_key string, time_out time.Duration) error }() } - log.Printf(" 转发地址: %s", remote_addr) + utils.Log().DebugF("转发地址: %s", remote_addr) m_remote_stats = 1 @@ -211,7 +210,7 @@ func RunRemote(remote_addr string, tun_key string, time_out time.Duration) error }() tun.ProcessHealth(health) - gogo.Log().DebugF(" 释放连接: %v", conn.LocalAddr()) + utils.Log().DebugF("释放连接: %v", conn.LocalAddr()) }(remote_addr, conn) } diff --git a/proxy/proxy_io.go b/proxy/proxy_io.go index 0f022af..ae98041 100644 --- a/proxy/proxy_io.go +++ b/proxy/proxy_io.go @@ -24,7 +24,7 @@ func stunT2QProcess1(tc net.Conn, qc quic.Stream, stun_quic_conn quic.Connection tc.Close() qc.Close() if check(err) { - log.Printf("udp.conn: %v, quic.conn: %v, quic.stream: %v, err: %v\n", tc.RemoteAddr(), stun_quic_conn.RemoteAddr(), qc.StreamID(), err) + log.Printf(" udp.conn: %v, quic.conn: %v, quic.stream: %v, err: %v\n", tc.RemoteAddr(), stun_quic_conn.RemoteAddr(), qc.StreamID(), err) } break } @@ -37,7 +37,7 @@ func stunQ2TProcess1(qc quic.Stream, tc net.Conn, stun_quic_conn quic.Connection tc.Close() qc.Close() if check(err) { - log.Printf("udp.conn: %v, quic.conn: %v, quic.stream: %v, err: %v\n", tc.RemoteAddr(), stun_quic_conn.RemoteAddr(), qc.StreamID(), err) + log.Printf(" udp.conn: %v, quic.conn: %v, quic.stream: %v, err: %v\n", tc.RemoteAddr(), stun_quic_conn.RemoteAddr(), qc.StreamID(), err) } break } diff --git a/proxy/proxy_l.go b/proxy/proxy_l.go index 75599b6..50c4e1a 100644 --- a/proxy/proxy_l.go +++ b/proxy/proxy_l.go @@ -2,14 +2,14 @@ package proxy import ( "context" - "log" + "goodlink/utils" "net" "github.com/quic-go/quic-go" ) func ProcessProxyClient(listener net.Listener, stun_quic_conn quic.Connection) { - log.Println(" 您已可以访问remote端的主机, 请勿关闭本程序") + utils.Log().Debug("您已可以访问remote端的主机, 请勿关闭本程序") for { new_tcp_conn, err := listener.Accept() diff --git a/stun2/cli.go b/stun2/cli.go index a96ae95..e75fecc 100644 --- a/stun2/cli.go +++ b/stun2/cli.go @@ -11,8 +11,6 @@ import ( "math/big" "net" "time" - - "gogo" ) func getStunIpPort5(attrType uint16, attributes []byte, attrLength uint16, magicCookie []byte, transactionID []byte) (string, int, error) { @@ -185,7 +183,7 @@ func getStunIpPort2(conn *net.UDPConn, addr string) (string, int, int, error) { } if err == nil { if wan_ip1 != wan_ip2 { - gogo.Log().ErrorF("wan_ip: %s, %s", wan_ip1, wan_ip2) + utils.Log().ErrorF("wan_ip: %s, %s", wan_ip1, wan_ip2) } return wan_ip1, wan_port1, wan_port2, nil } @@ -197,7 +195,7 @@ func getStunIpPort2(conn *net.UDPConn, addr string) (string, int, int, error) { } func GetWanIpPort2(conn *net.UDPConn) (string, int, int) { - gogo.Log().Debug(" 获取本端地址") + utils.Log().Debug("获取本端地址") defer conn.SetReadDeadline(time.Time{}) n2 := 0 @@ -205,7 +203,7 @@ func GetWanIpPort2(conn *net.UDPConn) (string, int, int) { n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(config.GetConfig().StunList)))) stun_svr := config.GetConfig().StunList[n.Int64()] wan_ip, wan_port1, wan_port2, err := getStunIpPort2(conn, stun_svr) - //log.Printf(" stun_svr: %s, wan_ip: %s, wan_port1: %d, wan_port2: %d, err: %v", stun_svr, wan_ip, wan_port1, wan_port2, err) + //log.Printf("stun_svr: %s, wan_ip: %s, wan_port1: %d, wan_port2: %d, err: %v", stun_svr, wan_ip, wan_port1, wan_port2, err) if err != nil { log.Printf(" stun_svr: %s, err: %v", stun_svr, err) /*if strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "closed") { diff --git a/ui2/log.go b/ui2/log.go index acd41bb..aa05e92 100644 --- a/ui2/log.go +++ b/ui2/log.go @@ -3,28 +3,71 @@ package ui2 import ( + "errors" + "fmt" + "goodlink/utils" + "log" + "time" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/widget" ) var ( m_log_label *LogLabel + m_view_time widget.Label ) type LogLabel struct { widget.Label } -func NewLogLabel(content string) *LogLabel { - m_log_label = &LogLabel{} - m_log_label.ExtendBaseWidget(m_log_label) - m_log_label.SetText(content) - return m_log_label -} - func SetLogLabel(content string) { if m_log_label != nil { m_log_label.SetText(content) m_log_label.TextStyle = fyne.TextStyle{Bold: true} } } + +func UILogPrintF(a ...any) { + var content string + + switch len(a) { + case 1: + content = a[0].(string) + default: + content = fmt.Sprintf(a[0].(string), a[1:]...) + } + + log.Println(content) + + if len(content) > 32 { + content = content[:32] + } + SetLogLabel(content) + + m_view_time.SetText(time.Now().Format("2006/01/02 15:04:05")) +} + +func UILogInit() { + utils.Log().RegistInfo(func(content string) { + UILogPrintF(content) + }) + utils.Log().RegistDebug(func(content string) { + UILogPrintF(content) + }) + utils.Log().RegistError(func(content string) { + UILogPrintF(content) + fyne.LogError("error: ", errors.New(content)) + }) +} + +func NewLogLabel(content string) *LogLabel { + m_log_label = &LogLabel{} + m_log_label.ExtendBaseWidget(m_log_label) + m_log_label.SetText(content) + + UILogInit() + + return m_log_label +} diff --git a/ui2/ui.go b/ui2/ui.go index fd8cd98..9e17e9c 100644 --- a/ui2/ui.go +++ b/ui2/ui.go @@ -4,11 +4,8 @@ package ui2 import ( "encoding/json" - "errors" - "fmt" "gogo" "log" - "time" "goodlink/config" "goodlink/pro" @@ -32,46 +29,12 @@ var ( m_ui_remote *RemoteUI m_button_key_create *widget.Button m_button_key_paste *widget.Button - m_view_log *LogLabel - m_view_time widget.Label ) const ( M_APP_TITLE = "GoodLink" ) -func UILogPrintF(a ...any) { - var content string - if len(a) > 1 { - content = fmt.Sprintf(a[0].(string), a[1:]...) - } else { - content = a[0].(string) - } - log.Println(content) - - if len(content) > 32 { - content = content[:32] - } - SetLogLabel(content) - - m_view_time.SetText(time.Now().Format("2006/01/02 15:04:05")) -} - -func UILogInit() { - m_view_log = NewLogLabel("等待启动") - - gogo.Log().RegistInfo(func(content string) { - UILogPrintF(content) - }) - gogo.Log().RegistDebug(func(content string) { - UILogPrintF(content) - }) - gogo.Log().RegistError(func(content string) { - UILogPrintF(content) - fyne.LogError("error: ", errors.New(content)) - }) -} - func GetMainUI(myWindow *fyne.Window) *fyne.Container { var configInfo config.ConfigInfo json.Unmarshal(gogo.Utils().FileReadAll("goodlink.json"), &configInfo) @@ -141,7 +104,7 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container { container.New(layout.NewFormLayout(), widget.NewRichTextWithText("连接密钥: "), m_validated_key), container.NewGridWithColumns(3, m_button_key_create, key_copy_button, m_button_key_paste), localUI_Container, remoteUI_Container, - container.New(layout.NewFormLayout(), widget.NewRichTextWithText("更新状态: "), m_view_log), + container.New(layout.NewFormLayout(), widget.NewRichTextWithText("更新状态: "), NewLogLabel("等待启动")), container.New(layout.NewFormLayout(), widget.NewRichTextWithText("更新时间: "), &m_view_time), container.NewStack(m_button_start, m_activity_start_button)) } diff --git a/utils/guard.go b/utils/guard.go index e7611d7..07b1388 100644 --- a/utils/guard.go +++ b/utils/guard.go @@ -42,9 +42,9 @@ func GuardStart(proc_handler func(), time_out time.Duration, err_handle func(err var err error if err = cmd.Start(); err != nil { - log.Printf("failed to run command: %v\n", err) + log.Printf(" failed to run command: %v\n", err) } else if err = cmd.Wait(); err != nil { - log.Printf("failed to wait command: %v\n", err) + log.Printf(" failed to wait command: %v\n", err) } err_handle(err) diff --git a/utils/log.go b/utils/log.go new file mode 100644 index 0000000..9190646 --- /dev/null +++ b/utils/log.go @@ -0,0 +1,85 @@ +package utils + +import ( + "fmt" + "log" +) + +var ( + mp_log *Log_Class + m_debug_state int +) + +func Log() *Log_Class { + if mp_log == nil { + mp_log = &Log_Class{} + } + return mp_log +} + +type LogProcFunc func(content string) + +type Log_Class struct { + ErrorFunc LogProcFunc + DebugFunc LogProcFunc + LogInfoFunc LogProcFunc +} + +func (c *Log_Class) RegistError(handle LogProcFunc) { + c.ErrorFunc = handle +} + +func (c *Log_Class) RegistDebug(handle LogProcFunc) { + c.DebugFunc = handle +} + +func (c *Log_Class) RegistInfo(handle LogProcFunc) { + c.LogInfoFunc = handle +} + +func (c *Log_Class) SetDebugSate(state int) { + m_debug_state = state +} + +// Debug 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) Debug(content string) { + content2 := fmt.Sprintf("%d: %s", m_debug_state, content) + if c.DebugFunc != nil { + c.DebugFunc(content2) + return + } + log.Println(content2) +} + +// DebugF 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) DebugF(format string, a ...interface{}) { + c.Debug(fmt.Sprintf(format, a...)) +} + +// LogInfo 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) Info(content string) { + if c.DebugFunc != nil { + c.DebugFunc(content) + return + } + log.Println(content) +} + +// LogInfoF 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) InfoF(format string, a ...interface{}) { + c.Info(fmt.Sprintf(format, a...)) +} + +// Error 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) Error(content string) { + if c.DebugFunc != nil { + c.DebugFunc(content) + return + } + log.Println(content) +} + +// ErrorF 日志输出和官方fmt.Print、fmt.Printf使用一致 +func (c *Log_Class) ErrorF(format string, a ...interface{}) { + c.Error(fmt.Sprintf(format, a...)) +} diff --git a/utils/net.go b/utils/net.go index 631e036..e026c46 100644 --- a/utils/net.go +++ b/utils/net.go @@ -3,14 +3,12 @@ package utils import ( "fmt" "net" - - "gogo" ) func GetListenUDP() *net.UDPConn { conn, err := net.ListenUDP("udp4", nil) if err != nil { - gogo.Log().ErrorF(" 绑定端口失败: %v", err) + Log().ErrorF("绑定端口失败: %v", err) } return conn }