Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] use string formatting package agnostic way of printing request attemps #3371

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package httpclient

import (
"net/http"
"strconv"
"time"

"github.com/superseriousbusiness/gotosocial/internal/log"
Expand All @@ -32,6 +33,7 @@ const (
// Request wraps an HTTP request
// to add our own retry / backoff.
type Request struct {

// Current backoff dur.
backoff time.Duration

Expand All @@ -57,8 +59,7 @@ func WrapRequest(r *http.Request) *Request {
// Only add content-type header if a request body exists.
entry = entry.WithField("contentType", r.Header.Get("Content-Type"))
}
// note our formatting library follows ptr values
entry = entry.WithField("attempt", &rr.attempts)
entry = entry.WithField("attempt", uintPtr{&rr.attempts})
rr.Entry = entry
return rr
}
Expand All @@ -73,3 +74,12 @@ func (r *Request) BackOff() time.Duration {
}
return r.backoff
}

type uintPtr struct{ u *uint }

func (f uintPtr) String() string {
if f.u == nil {
return "<nil>"
}
return strconv.FormatUint(uint64(*f.u), 10)
}