mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
refactor: standardize logging on zap across all packages
Replace all fmt.Printf/Println and log.Printf/Fatal with structured zap.Logger calls to eliminate inconsistent logging (anti-pattern #12). - network/crypt_conn: inject logger via NewCryptConn, replace 6 fmt calls - signserver/session: use existing s.logger for debug packet dumps - entranceserver: use s.logger for inbound/outbound debug logging - api/utils: accept logger param in verifyPath, replace fmt.Println - api/endpoints: use s.logger for screenshot path diagnostics - config: replace log.Fatal with error return in getOutboundIP4 - deltacomp: replace log.Printf with zap.L() global logger
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package _config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
@@ -305,19 +305,18 @@ func (c *EntranceChannelInfo) IsEnabled() bool {
|
||||
return *c.Enabled
|
||||
}
|
||||
|
||||
|
||||
// getOutboundIP4 gets the preferred outbound ip4 of this machine
|
||||
// From https://stackoverflow.com/a/37382208
|
||||
func getOutboundIP4() net.IP {
|
||||
func getOutboundIP4() (net.IP, error) {
|
||||
conn, err := net.Dial("udp4", "8.8.8.8:80")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, fmt.Errorf("detecting outbound IP: %w", err)
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
|
||||
return localAddr.IP.To4()
|
||||
return localAddr.IP.To4(), nil
|
||||
}
|
||||
|
||||
// LoadConfig loads the given config toml file.
|
||||
@@ -342,7 +341,11 @@ func LoadConfig() (*Config, error) {
|
||||
}
|
||||
|
||||
if c.Host == "" {
|
||||
c.Host = getOutboundIP4().To4().String()
|
||||
ip, err := getOutboundIP4()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to detect host IP: %w", err)
|
||||
}
|
||||
c.Host = ip.To4().String()
|
||||
}
|
||||
|
||||
for i := range versionStrings {
|
||||
@@ -365,4 +368,3 @@ func LoadConfig() (*Config, error) {
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user