From 3f93dec9db61759d7f8cb20a45d37c47fbc87939 Mon Sep 17 00:00:00 2001 From: Call me Phil Date: Sun, 30 Mar 2025 23:14:21 +0000 Subject: [PATCH] Utililize go i2p logger (#1) - Drop log.go in favor of using go-i2p/logger - Fix an occurrence of ioutil deprecation. Bump go version to a recent one --- common.go | 3 +++ garlic.go | 3 +-- garlic_test.go | 4 ++-- go.mod | 5 ++++- go.sum | 7 +++---- log.go | 51 -------------------------------------------------- onion_test.go | 4 ++-- 7 files changed, 15 insertions(+), 62 deletions(-) delete mode 100644 log.go diff --git a/common.go b/common.go index b74d15f..8a82c8c 100644 --- a/common.go +++ b/common.go @@ -10,9 +10,12 @@ import ( "path/filepath" "strings" + "github.com/go-i2p/logger" "github.com/sirupsen/logrus" ) +var log = logger.GetGoI2PLogger() + //go:generate go run -tags gen ./gen.go // GetJoinedWD returns the working directory joined with the given path. diff --git a/garlic.go b/garlic.go index c6fbb8d..f3dab89 100644 --- a/garlic.go +++ b/garlic.go @@ -12,10 +12,9 @@ import ( "path/filepath" "strings" - "github.com/sirupsen/logrus" - "github.com/go-i2p/i2pkeys" "github.com/go-i2p/sam3" + "github.com/sirupsen/logrus" ) // Garlic is a ready-made I2P streaming manager. Once initialized it always diff --git a/garlic_test.go b/garlic_test.go index 6dddd8f..a957e32 100644 --- a/garlic_test.go +++ b/garlic_test.go @@ -6,7 +6,7 @@ package onramp import ( "crypto/tls" "fmt" - "io/ioutil" + "io" "net" "net/http" "testing" @@ -52,7 +52,7 @@ func TestBareGarlic(t *testing.T) { } defer resp.Body.Close() fmt.Println(resp.Status) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Error(err) } diff --git a/go.mod b/go.mod index 700dd06..8566cc7 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,13 @@ module github.com/go-i2p/onramp -go 1.18 +go 1.23.3 + +toolchain go1.24.1 require ( github.com/cretz/bine v0.2.0 github.com/go-i2p/i2pkeys v0.33.10-0.20241113193422-e10de5e60708 + github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c github.com/go-i2p/sam3 v0.33.9 github.com/sirupsen/logrus v1.9.3 ) diff --git a/go.sum b/go.sum index 1295a0a..d76f269 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/go-i2p/i2pkeys v0.0.0-20241108200332-e4f5ccdff8c4/go.mod h1:m5TlHjPZrU5KbTd7Lr+I2rljyC6aJ88HdkeMQXV0U0E= github.com/go-i2p/i2pkeys v0.33.10-0.20241113193422-e10de5e60708 h1:Tiy9IBwi21maNpK74yCdHursJJMkyH7w87tX1nXGWzg= github.com/go-i2p/i2pkeys v0.33.10-0.20241113193422-e10de5e60708/go.mod h1:m5TlHjPZrU5KbTd7Lr+I2rljyC6aJ88HdkeMQXV0U0E= +github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c h1:VTiECn3dFEmUlZjto+wOwJ7SSJTHPLyNprQMR5HzIMI= +github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c/go.mod h1:te7Zj3g3oMeIl8uBXAgO62UKmZ6m6kHRNg1Mm+X8Hzk= github.com/go-i2p/sam3 v0.33.9 h1:3a+gunx75DFc6jxloUZTAVJbdP6736VU1dy2i7I9fKA= github.com/go-i2p/sam3 v0.33.9/go.mod h1:oDuV145l5XWKKafeE4igJHTDpPwA0Yloz9nyKKh92eo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -17,14 +19,10 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -39,3 +37,4 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/log.go b/log.go deleted file mode 100644 index b26533f..0000000 --- a/log.go +++ /dev/null @@ -1,51 +0,0 @@ -package onramp - -import ( - "io" - "os" - "strings" - "sync" - - "github.com/sirupsen/logrus" -) - -var ( - log *logrus.Logger - once sync.Once -) - -func InitializeOnrampLogger() { - once.Do(func() { - log = logrus.New() - // We do not want to log by default - log.SetOutput(io.Discard) - log.SetLevel(logrus.PanicLevel) - // Check if DEBUG_I2P is set - if logLevel := os.Getenv("DEBUG_I2P"); logLevel != "" { - log.SetOutput(os.Stdout) - switch strings.ToLower(logLevel) { - case "debug": - log.SetLevel(logrus.DebugLevel) - case "warn": - log.SetLevel(logrus.WarnLevel) - case "error": - log.SetLevel(logrus.ErrorLevel) - default: - log.SetLevel(logrus.DebugLevel) - } - log.WithField("level", log.GetLevel()).Debug("Logging enabled.") - } - }) -} - -// GetI2PKeysLogger returns the initialized logger -func GetOnrampLogger() *logrus.Logger { - if log == nil { - InitializeOnrampLogger() - } - return log -} - -func init() { - GetOnrampLogger() -} diff --git a/onion_test.go b/onion_test.go index 5e82acc..f518881 100644 --- a/onion_test.go +++ b/onion_test.go @@ -6,7 +6,7 @@ package onramp import ( "crypto/tls" "fmt" - "io/ioutil" + "io" "net/http" "testing" ) @@ -44,7 +44,7 @@ func TestBareOnion(t *testing.T) { t.Error(err) } fmt.Println("Status:", resp.Status) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Error(err) }