Skip to content

Commit

Permalink
dep: go mod: update
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Jun 8, 2024
1 parent 36373d6 commit cb314d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
34 changes: 15 additions & 19 deletions encoding/base64/base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
func EncodeGzip(src []byte, compressLevel int) (string, error) {
var err error
if compressLevel != 0 {
src, err = gziputil.Compress(src, compressLevel)
src, err = gziputil.CompressBytes(src, compressLevel)
if err != nil {
return "", err
}
Expand All @@ -60,15 +60,13 @@ func EncodeGzip(src []byte, compressLevel int) (string, error) {
// DecodeGunzip base64 decodes a string with optional gzip uncompression.
func DecodeGunzip(enc string) ([]byte, error) {
enc = Pad(enc)
bytes, err := base64.StdEncoding.DecodeString(enc)
if err != nil {
if bytes, err := base64.StdEncoding.DecodeString(enc); err != nil {
return bytes, err
}
bytesUnc, err := gziputil.Uncompress(bytes)
if err != nil {
} else if bytesUnc, err := gziputil.UncompressBytes(bytes); err != nil {
return bytes, nil
} else {
return bytesUnc, nil
}
return bytesUnc, nil
}

func IsValid(enc []byte) bool {
Expand All @@ -89,11 +87,11 @@ func Pad(enc string) string {

// EncodeGzipJSON encodes a struct that is JSON encoded.
func EncodeGzipJSON(data any, compressLevel int) (string, error) {
bytes, err := json.Marshal(data)
if err != nil {
if bytes, err := json.Marshal(data); err != nil {
return "", err
} else {
return EncodeGzip(bytes, compressLevel)
}
return EncodeGzip(bytes, compressLevel)
}

// DecodeGunzipJSON base64 decodes a string with optoinal
Expand All @@ -103,24 +101,22 @@ func DecodeGunzipJSON(enc string, output any) error {
enc = strings.TrimSpace(enc)
if strings.Index(enc, "{") == 0 || strings.Index(enc, "[") == 0 {
return json.Unmarshal([]byte(enc), output)
}
bytes, err := DecodeGunzip(enc)
if err != nil {
} else if bytes, err := DecodeGunzip(enc); err != nil {
return errorsutil.Wrap(err, "DecodeGunzipJSON.DecodeGunzip")
} else {
return json.Unmarshal(bytes, output)
}
return json.Unmarshal(bytes, output)
}

// ReadAll provides an interface like `io.ReadAll`
// with optional base64 decoding. It is useful for
// decoding `*http.Response.Body`.
func ReadAll(r io.Reader) ([]byte, error) {
bytes, err := io.ReadAll(r)
if err != nil {
if bytes, err := io.ReadAll(r); err != nil {
return bytes, err
}
if IsValid(bytes) {
} else if IsValid(bytes) {
return Decode(bytes)
} else {
return bytes, err
}
return bytes, err
}
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/caarlos0/env/v6 v6.10.1
github.com/grokify/base36 v1.0.5
github.com/grokify/bitcoinmath v0.1.0
github.com/huandu/xstrings v1.4.0
github.com/huandu/xstrings v1.5.0
github.com/iancoleman/strcase v0.3.0
github.com/itchyny/base58-go v0.2.2
github.com/jessevdk/go-flags v1.5.0
Expand All @@ -18,12 +18,12 @@ require (
github.com/lytics/base62 v0.0.0-20180808010106-0ee4de5a5d6d
github.com/martinlindhe/base36 v1.1.1
github.com/microcosm-cc/bluemonday v1.0.26
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
golang.org/x/image v0.16.0
golang.org/x/net v0.25.0
golang.org/x/crypto v0.24.0
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
golang.org/x/image v0.17.0
golang.org/x/net v0.26.0
golang.org/x/text v0.16.0
google.golang.org/genproto v0.0.0-20240528184218-531527333157
google.golang.org/genproto v0.0.0-20240604185151-ef581f913117
)

require (
Expand All @@ -33,7 +33,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/grokify/base36 v1.0.5 h1:iUgnt40hrPtn3M2gjU4Darow5ikf8xWXrTuMWTLziCk=
github.com/grokify/base36 v1.0.5/go.mod h1:L+1aaUBGfp5Ctar7KCS5G9uPABo1Ccu1Ct2iQAuhOJ4=
github.com/grokify/bitcoinmath v0.1.0 h1:NySFRW09cYQlTXrUw6QpjNgtrudC5QlgsqgXWWNN+50=
github.com/grokify/bitcoinmath v0.1.0/go.mod h1:Y8OyDefB55NHGzi+uJshYmE4Hn5juIQqJahsQJN5o2k=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/itchyny/base58-go v0.2.2 h1:pswMT6rW2nRoELk5Mi8+xGLQPmDnlNnCwbfRCl2p7Mo=
Expand Down Expand Up @@ -49,21 +49,21 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco=
golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/genproto v0.0.0-20240528184218-531527333157 h1:u7WMYrIrVvs0TF5yaKwKNbcJyySYf+HAIFXxWltJOXE=
google.golang.org/genproto v0.0.0-20240528184218-531527333157/go.mod h1:ubQlAQnzejB8uZzszhrTCU2Fyp6Vi7ZE5nn0c3W8+qQ=
google.golang.org/genproto v0.0.0-20240604185151-ef581f913117 h1:HCZ6DlkKtCDAtD8ForECsY3tKuaR+p4R3grlK80uCCc=
google.golang.org/genproto v0.0.0-20240604185151-ef581f913117/go.mod h1:lesfX/+9iA+3OdqeCpoDddJaNxVB1AB6tD7EfqMmprc=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit cb314d4

Please sign in to comment.