Skip to content

Commit

Permalink
Merge pull request #15 from plainq/linter_fixes_and_deps_update
Browse files Browse the repository at this point in the history
Linter fixes and deps update
  • Loading branch information
heartwilltell authored Feb 4, 2025
2 parents 6afe214 + 7415a48 commit 0654a70
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 29 deletions.
10 changes: 5 additions & 5 deletions authkit/hashkit/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type Option func(hasher *BCryptHasher)
// then min or max cost wil be set.
func WithCost(cost int) Option {
var finalCost int

if cost < bcrypt.MinCost {
finalCost = bcrypt.MinCost
}

if cost > bcrypt.MaxCost {
finalCost = bcrypt.MaxCost
}
Expand All @@ -50,9 +50,9 @@ func WithCost(cost int) Option {

// BCryptHasher implements Hasher interface.
// Hashes passwords using bcrypt algorithm.
type BCryptHasher struct { cost int }
type BCryptHasher struct{ cost int }

func (h *BCryptHasher) CheckPassword(hash, pass string) error {
func (*BCryptHasher) CheckPassword(hash, pass string) error {
if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(pass)); err != nil {
if errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {
return errkit.ErrPasswordIncorrect
Expand All @@ -71,4 +71,4 @@ func (h *BCryptHasher) HashPassword(pass string) (string, error) {
}

return string(hash), nil
}
}
2 changes: 1 addition & 1 deletion dbkit/litekit/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/benbjohnson/litestream/file"
"github.com/benbjohnson/litestream/s3"
"github.com/heartwilltell/hc"
_ "github.com/mattn/go-sqlite3" //nolint // driver.
_ "github.com/mattn/go-sqlite3" // sqlite3 driver is required by the litestream.
"github.com/plainq/servekit/logkit"
)

Expand Down
2 changes: 1 addition & 1 deletion dbkit/litekit/schema_evolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (e *Evolver) MutateSchema() (eErr error) {
// Range over mutation to apply each one.
for _, m := range mutations {
// Skip already applied mutations.
if int(m.version) <= schemaVersionInfo.Version {
if schemaVersionInfo.Version < 0 || m.version <= uint(schemaVersionInfo.Version) {
continue
}

Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ toolchain go1.23.2
require (
github.com/VictoriaMetrics/metrics v1.35.1
github.com/benbjohnson/litestream v0.3.13
github.com/cristalhq/jwt/v5 v5.4.0
github.com/getsentry/sentry-go v0.31.1
github.com/go-chi/chi/v5 v5.2.0
github.com/go-chi/chi/v5 v5.2.1
github.com/go-chi/cors v1.2.1
github.com/heartwilltell/hc v0.1.5
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgx/v5 v5.7.2
github.com/jackc/tern/v2 v2.3.2
github.com/lmittmann/tint v1.0.6
github.com/lmittmann/tint v1.0.7
github.com/mattn/go-sqlite3 v1.14.24
github.com/maxatome/go-testdeep v1.14.0
github.com/oklog/ulid/v2 v2.1.0
github.com/redis/go-redis/v9 v9.7.0
github.com/resend/resend-go/v2 v2.14.0
github.com/resend/resend-go/v2 v2.15.0
github.com/rs/xid v1.6.0
github.com/valyala/fastrand v1.1.0
go.mongodb.org/mongo-driver v1.17.2
golang.org/x/sync v0.10.0
google.golang.org/grpc v1.69.4
golang.org/x/crypto v0.32.0
golang.org/x/sync v0.11.0
google.golang.org/grpc v1.70.0
)

require (
Expand All @@ -36,7 +38,6 @@ require (
github.com/aws/aws-sdk-go v1.55.6 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cristalhq/jwt/v5 v5.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down Expand Up @@ -67,10 +68,9 @@ require (
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/protobuf v1.36.3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 // indirect
google.golang.org/protobuf v1.36.4 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
Expand Down Expand Up @@ -147,6 +149,8 @@ github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw=
github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/lmittmann/tint v1.0.6 h1:vkkuDAZXc0EFGNzYjWcV0h7eEX+uujH48f/ifSkJWgc=
github.com/lmittmann/tint v1.0.6/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/lmittmann/tint v1.0.7 h1:D/0OqWZ0YOGZ6AyC+5Y2kD8PBEzBk6rFHVSfOqCkF9Y=
github.com/lmittmann/tint v1.0.7/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/mattn/go-ieproxy v0.0.11 h1:MQ/5BuGSgDAHZOJe6YY80IF2UVCfGkwfo6AeD7HtHYo=
github.com/mattn/go-ieproxy v0.0.11/go.mod h1:/NsJd+kxZBmjMc5hrJCKMbP57B84rvq9BiDRbtO9AS0=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
Expand Down Expand Up @@ -204,6 +208,8 @@ github.com/resend/resend-go/v2 v2.13.0 h1:O6Z5Z+LiBlDAm6daHHn0POQX4TJfsdGIhQJD8q
github.com/resend/resend-go/v2 v2.13.0/go.mod h1:3YCb8c8+pLiqhtRFXTyFwlLvfjQtluxOr9HEh2BwCkQ=
github.com/resend/resend-go/v2 v2.14.0 h1:eAjj3N/7a2Qsyv+zrLvrMr33tGKLn49wWYAOwF0N90k=
github.com/resend/resend-go/v2 v2.14.0/go.mod h1:3YCb8c8+pLiqhtRFXTyFwlLvfjQtluxOr9HEh2BwCkQ=
github.com/resend/resend-go/v2 v2.15.0 h1:B6oMEPf8IEQwn2Ovx/9yymkESLDSeNfLFaNMw+mzHhE=
github.com/resend/resend-go/v2 v2.15.0/go.mod h1:3YCb8c8+pLiqhtRFXTyFwlLvfjQtluxOr9HEh2BwCkQ=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
Expand Down Expand Up @@ -281,6 +287,8 @@ golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -293,6 +301,8 @@ golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
Expand Down Expand Up @@ -327,18 +337,24 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 h1:J1H9f+LEdWAfHcez/4cvaVBox7cOYT+IU6rgqj5x++8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
14 changes: 7 additions & 7 deletions httpkit/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ type roundTripper struct {
client *http.Client
}

//nolint:revive // cyclomatic is acceptable here.
func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
var (
attempts = int(t.maxAttempts)
attempts = t.maxAttempts
bodyReader io.ReadSeeker
)

Expand All @@ -353,7 +354,7 @@ func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

var res *http.Response

for i := 0; i <= attempts; i++ {
for i := uint(0); i <= attempts; i++ {
if res != nil {
// In case of retry when the previous response is not nil we try to drain
// the response body to utilize the HTTP connection.
Expand Down Expand Up @@ -398,8 +399,7 @@ func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}
}

time.Sleep(t.backoff.Next(uint(i)))

time.Sleep(t.backoff.Next(i))
continue
}

Expand All @@ -418,16 +418,16 @@ func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}
}

time.Sleep(t.backoff.Next(uint(i)))
time.Sleep(t.backoff.Next(i))
continue
}

if res.StatusCode >= http.StatusInternalServerError &&
res.StatusCode != http.StatusServiceUnavailable &&
res.StatusCode != http.StatusNotImplemented {
// Sleep before next retry attempt.
time.Sleep(t.backoff.Next(uint(i)))

// Sleep before next retry.
time.Sleep(t.backoff.Next(i))
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion idkit/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func DigiCode() string {
rng fastrand.RNG
)

rng.Seed(uint32(time.Now().UnixNano()))
rng.Seed(uint32(time.Now().UnixNano())) //nolint:gosec // UnixNano will never be negative.

for i := 0; i < digiCodeLen; i++ {
b.WriteString(strconv.Itoa(int(fastrand.Uint32n(digiCodeMaxN))))
Expand Down
4 changes: 2 additions & 2 deletions respond/respond.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func HTML(w http.ResponseWriter, r *http.Request, v []byte, options ...Option) {
// response with the specified status code. If the template execution fails, an
// error will be logged and a 500 Internal Server Error response will be sent.
// Additional options can be passed to modify the response using the Option functions.
func TemplateHTML(w http.ResponseWriter, r *http.Request, name string, v any, options ...Option) {
func TemplateHTML(w http.ResponseWriter, r *http.Request, name string, v any, options ...Option) { //nolint:revive // argument-limit is acceptable here.
o := Options(w, options...)

w.Header().Set("Content-Type", "text/html; charset=utf-8")
Expand Down Expand Up @@ -304,7 +304,7 @@ func WithHeader(key, value string) Option {
}

// WithErrorReport is an Option function that will enable error reporting by the
// errkit.ErrorReporter. Used in
// errkit.ErrorReporter. Used in the default implementation of HTTPErrorResponder.
func WithErrorReport() Option {
return func(o *ResponseOptions) { o.reportError = true }
}
Expand Down
4 changes: 2 additions & 2 deletions retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func Do(ctx context.Context, fn func(ctx context.Context) error, options ...Opti
option(&o)
}

for i := 0; uint(i) < o.maxRetries; i++ {
for i := uint(0); i < o.maxRetries; i++ {
select {
case <-ctx.Done():
return ctx.Err()
Expand All @@ -206,7 +206,7 @@ func Do(ctx context.Context, fn func(ctx context.Context) error, options ...Opti
return err
}

backoff := o.backoff.Next(uint(i))
backoff := o.backoff.Next(i)
timer := time.NewTimer(backoff)

select {
Expand Down

0 comments on commit 0654a70

Please sign in to comment.