Explicitly ignore errors from writes to responses
Some checks failed
/ docker (push) Failing after 15m26s

This commit is contained in:
Melody Becker 2025-05-22 17:29:09 +02:00
parent ef95a0552d
commit 4a2462e24e
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
30 changed files with 280 additions and 237 deletions

View file

@ -36,7 +36,7 @@ func ImportRemoteNote(noteId string, requester *models.User) (string, error) {
return "", fmt.Errorf("activitypub: invalid status code: %v", res.StatusCode)
}
body, _ := io.ReadAll(res.Body)
res.Body.Close()
_ = res.Body.Close()
data := Note{}
err = json.Unmarshal(body, &data)
if err != nil {

View file

@ -424,7 +424,7 @@ func ImportRemoteAccountByAPUrl(apUrl string) (*models.User, error) {
return nil, other.Error("activitypub", "failed to complete signed request", err)
}
body, _ := io.ReadAll(response.Body)
response.Body.Close()
_ = response.Body.Close()
if response.StatusCode != 200 {
return nil, fmt.Errorf("activitypub: invalid status code: %v", response.StatusCode)
}

View file

@ -88,7 +88,13 @@ func (a *Authenticator) PerformTotpLogin(
}
// If not verified yet, mark as verified
if strings.HasSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix) {
dbgen.UserAuthMethod.
// TODO: Not nice, think about this more
// Problem: What does it mean for a credential to not be verified?
// Does it just mean not used yet?
// Or should it also mean that it's unusable until confirmation during setup?
// I prefer the 2nd one to avoid lockout problems
// In which case, this needs to be modified
_, _ = dbgen.UserAuthMethod.
Where(dbgen.UserAuthMethod.ID.
Eq(dbSecrets[foundIndex].ID)).
Update(dbgen.UserAuthMethod.Name, strings.TrimSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix))

View file

@ -48,7 +48,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
if *flagOutputFile == "" {
@ -58,7 +58,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -204,5 +204,5 @@ func CompareRoles(a, b *models.Role) bool {
outBuilder.WriteString("\n}")
// And write the entire thing to the output
fmt.Fprint(output, outBuilder.String())
_, _ = fmt.Fprint(output, outBuilder.String())
}

View file

@ -37,7 +37,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
if *flagOutputFile == "" {
@ -47,7 +47,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -100,5 +100,5 @@ func main() {
}
outBuilder.WriteString("}\n}\n")
fmt.Fprint(output, outBuilder.String())
_, _ = fmt.Fprint(output, outBuilder.String())
}

View file

@ -38,7 +38,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
if *flagOutputFile == "" {
@ -48,7 +48,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -105,7 +105,7 @@ func main() {
}
outBuilder.WriteString("}")
fmt.Fprint(output, outBuilder.String())
_, _ = fmt.Fprint(output, outBuilder.String())
}
func convertGoNameToJsonApiName(name string) string {

View file

@ -39,7 +39,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
if *flagOutputFile == "" {
@ -49,7 +49,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -111,7 +111,7 @@ func main() {
role: Role
}
}`)
fmt.Fprint(output, outBuilder.String())
_, _ = fmt.Fprint(output, outBuilder.String())
}
func convertGoTypeToTS(t string) string {

View file

@ -43,7 +43,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
if *flagOutputFile == "" {
@ -53,7 +53,7 @@ func main() {
if err != nil {
panic(err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -176,5 +176,5 @@ func main() {
outBuilder.WriteString("\n}")
// And write the entire thing to the output
fmt.Fprint(output, outBuilder.String())
_, _ = fmt.Fprint(output, outBuilder.String())
}

View file

@ -23,7 +23,10 @@ func main() {
other.SetupFlags()
flag.Parse()
other.ConfigureLogging(nil)
config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
err := config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
if err != nil {
log.Fatal().Err(err).Msg("Failed to get config from file")
}
db, err := gorm.Open(
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),

View file

@ -280,7 +280,7 @@ func WriteDefaultConfig(toFile string) error {
Msg("Failed to create file for default config")
return err
}
defer file.Close()
defer func() { _ = file.Close() }()
data, err := toml.Marshal(&defaultConfig)
if err != nil {

View file

@ -2,10 +2,6 @@ package shared
import (
"flag"
"fmt"
"os"
"github.com/rs/zerolog/log"
)
var (
@ -27,7 +23,7 @@ var (
FlagDebugPort *string = flag.String(
"debugport",
"127.0.0.1:3305",
"Set the address the debug server will listen on. Format: IP:Port",
"Set the address the debug server will listen on. Format: IP:Port (irrelevant if debug server isn't enabled)",
)
FlagLogFile *string = flag.String(
"logfile",
@ -36,27 +32,27 @@ var (
)
)
func flagUsage() {
executable, err := os.Executable()
if err != nil {
log.Fatal().Err(err).Msg("Failed to get own path")
}
fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable)
fmt.Fprintln(os.Stderr, "\t-config string")
fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")")
fmt.Fprintln(os.Stderr, "\t-loglevel string")
fmt.Fprintln(
os.Stderr,
"\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")",
)
fmt.Fprintln(os.Stderr, "\t-validate-config")
fmt.Fprintln(
os.Stderr,
"\t\tIf set, the server will only validate the config (or write the default one) and then quit",
)
fmt.Fprintln(os.Stderr, "\t-jsonlogs")
fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead")
}
// func flagUsage() {
// executable, err := os.Executable()
// if err != nil {
// log.Fatal().Err(err).Msg("Failed to get own path")
// }
// fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable)
// fmt.Fprintln(os.Stderr, "\t-config string")
// fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")")
// fmt.Fprintln(os.Stderr, "\t-loglevel string")
// fmt.Fprintln(
// os.Stderr,
// "\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")",
// )
// fmt.Fprintln(os.Stderr, "\t-validate-config")
// fmt.Fprintln(
// os.Stderr,
// "\t\tIf set, the server will only validate the config (or write the default one) and then quit",
// )
// fmt.Fprintln(os.Stderr, "\t-jsonlogs")
// fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead")
// }
// func init() {
// flag.Usage = flagUsage

View file

@ -14,7 +14,7 @@ func TestFSWrapper_Open(t *testing.T) {
if err != nil {
t.Fatalf("failed to open /etc/hostname: %v", err)
}
defer f.Close()
defer func() { _ = f.Close() }()
data, err := os.ReadFile("/etc/hostname")
if err != nil {
t.Fatalf("failed to read with full path: %v", err)

View file

@ -11,7 +11,7 @@ func init() {
}
func tickExpireAccessTokens(now time.Time) {
dbgen.AccessToken.Where(dbgen.AccessToken.ExpiresAt.Lt(time.Now())).Delete()
_, _ = dbgen.AccessToken.Where(dbgen.AccessToken.ExpiresAt.Lt(time.Now())).Delete()
}
func buildExpireAccessTokens() (onTick func(time.Time), name string, tickSpeed time.Duration) {

View file

@ -118,16 +118,16 @@ func createActitiystreamsActivityType(db *gorm.DB) error {
)
}
func createActitiystreamsActivityTargetType(db *gorm.DB) error {
return migrateEnum(
db,
"activitystreams_activity_target_type",
sliceutils.Map(
models.AllActivitystreamsActivityTargetTypes,
func(t models.ActivitystreamsActivityTargetType) string { return string(t) },
),
)
}
// func createActitiystreamsActivityTargetType(db *gorm.DB) error {
// return migrateEnum(
// db,
// "activitystreams_activity_target_type",
// sliceutils.Map(
// models.AllActivitystreamsActivityTargetTypes,
// func(t models.ActivitystreamsActivityTargetType) string { return string(t) },
// ),
// )
// }
func createCollectionTarget(db *gorm.DB) error {
return migrateEnum(

View file

@ -31,7 +31,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
data := Inbound{}
err := dec.Decode(&data)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -49,10 +49,10 @@ func postAs(w http.ResponseWriter, r *http.Request) {
user, err := dbgen.User.GetByUsername(data.Username)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
} else {
log.Error().Err(err).Str("name", data.Username).Msg("Failed to find user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
return
}
@ -88,7 +88,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
Str("username", data.Username).
Str("content", data.Content).
Msg("Failed to create message")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -105,28 +105,28 @@ func postAs(w http.ResponseWriter, r *http.Request) {
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit note creation")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
u2u := dbgen.UserToUserRelation
links, err := u2u.GetFollowerInboxesForId(user.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get follower inbox links for user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
log.Debug().Strs("links", links).Send()
act, err := webap.CreateFromStorage(r.Context(), activity.Id)
if err != nil {
log.Error().Err(err).Msg("Failed to fetch and format new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
act.Context = activitypub.BaseLdContext
outData, err := json.Marshal(act)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
for _, link := range links {
@ -151,13 +151,13 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get user")
storage.HandleReconnectError(err)
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
notes, err := dbgen.Note.GetNotesPaged(user.ID, 0, uint8(models.NOTE_TARGET_PUBLIC))
if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get notes")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
publicNotes := sliceutils.Map(notes, func(t models.Note) webshared.Note {
@ -165,7 +165,7 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
n.FromModel(&t)
return n
})
webutils.SendJson(w, publicNotes)
_ = webutils.SendJson(w, publicNotes)
}
func inReplyTo(w http.ResponseWriter, r *http.Request) {
@ -176,7 +176,7 @@ func inReplyTo(w http.ResponseWriter, r *http.Request) {
Find()
if err != nil {
log.Error().Err(err).Str("id", noteId).Msg("Error getting replies to note with id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_ = webutils.SendJson(w, notes)

View file

@ -32,7 +32,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
var err error
page, err = strconv.Atoi(pageStr)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -43,7 +43,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
return
}
if page < 0 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -57,7 +57,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
users, err := dbgen.User.GetPagedAllNonDeleted(uint(page))
if err != nil {
log.Error().Err(err).Int("page", page).Msg("Failed to get non-deleted users")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusInternalServerError,
"/errors/db-failure",
@ -67,7 +67,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
)
return
}
webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User {
_ = webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User {
u := webshared.User{}
u.FromModel(&t)
return u
@ -88,7 +88,7 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
data := Inbound{}
err := jsonDecoder.Decode(&data)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -111,20 +111,20 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
publicKeyEdBytes, privateKeyEdBytes, err := shared.GenerateKeypair(true)
if err != nil {
log.Error().Err(err).Msg("Failed to generate and marshal public key")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
publicKeyRsaBytes, privateKeyRsaBytes, err := shared.GenerateKeypair(false)
if err != nil {
log.Error().Err(err).Msg("Failed to generate and marshal public key")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
pkeyId := make([]byte, 64)
_, err = rand.Read(pkeyId)
if err != nil {
log.Error().Err(err).Msg("Failed to generate passkey id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
@ -174,17 +174,17 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
}
if err = query.Create(&user); err != nil {
log.Error().Err(err).Msg("failed to create new local user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
if err = storage.EnsureLocalUserIdHasLinks(user.ID); err != nil {
log.Error().Err(err).Msg("Failed to add links to new user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}
func deleteUser(w http.ResponseWriter, r *http.Request) {
id := r.FormValue("id")
dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete()
_, _ = dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete()
w.WriteHeader(http.StatusOK)
}
@ -212,7 +212,7 @@ func returnKeypair(w http.ResponseWriter, r *http.Request) {
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Pem Sanity check failed")
}
fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen)
_, _ = fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen)
}
func issueUserImport(w http.ResponseWriter, r *http.Request) {
@ -235,20 +235,20 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
err := dec.Decode(&data)
if err != nil {
log.Warn().Err(err).Msg("Failed to decode json body")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
log.Debug().Any("data", data).Msg("Received message")
user, err := dbgen.User.GetByUsername(data.From)
if err != nil {
log.Error().Err(err).Msg("Failed to get user from storage")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
targetId, err := activitypub.ImportRemoteAccountByHandle(data.Target)
if err != nil {
log.Error().Err(err).Msg("Failed to import target user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
target, err := dbgen.User.Where(dbgen.User.ID.Eq(targetId)).
@ -256,14 +256,14 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
First()
if err != nil {
log.Error().Err(err).Msg("Failed to get target user from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
outBody, err := json.Marshal(data.Message)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal out data")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
log.Debug().Bytes("request-body", outBody).Msg("Body of proxied request")
@ -275,10 +275,10 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
)
if err != nil {
log.Error().Err(err).Msg("Request failed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
defer response.Body.Close()
defer func() { _ = response.Body.Close() }()
respBody, _ := io.ReadAll(response.Body)
log.Debug().
Int("status-code", response.StatusCode).
@ -291,9 +291,12 @@ func kickoffFollow(w http.ResponseWriter, r *http.Request) {
From string `json:"from"`
To string `json:"to"`
}
log := hlog.FromRequest(r)
var data Inbound
dec := json.NewDecoder(r.Body)
dec.Decode(&data)
_ = dec.Decode(&data)
log.Error().Msg("Not implemented yet")
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
func requestAs(w http.ResponseWriter, r *http.Request) {
@ -307,24 +310,24 @@ func requestAs(w http.ResponseWriter, r *http.Request) {
err := dec.Decode(&data)
if err != nil {
log.Warn().Err(err).Msg("Failed to decode json body")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
user, err := dbgen.User.GetByUsername(data.Username)
if err != nil {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
}
res, _, err := webshared.RequestSigned("GET", data.TargetUrl, nil, user)
if err != nil {
log.Warn().Err(err).Msg("Request failed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if res.StatusCode != 200 {
webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
_ = webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
return
}
body, _ := io.ReadAll(res.Body)
fmt.Fprint(w, string(body))
_, _ = fmt.Fprint(w, string(body))
}

View file

@ -32,24 +32,24 @@ func activityAccept(w http.ResponseWriter, r *http.Request) {
activity, err := CreateFromStorage(r.Context(), id)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil:
activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity)
if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
default:
if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else {
log.Error().Err(err).Msg("Failed to get create activity from db")
}
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}

View file

@ -31,24 +31,24 @@ func activityCreate(w http.ResponseWriter, r *http.Request) {
activity, err := CreateFromStorage(r.Context(), id)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil:
activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity)
if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
default:
if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else {
log.Error().Err(err).Msg("Failed to get create activity from db")
}
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}

View file

@ -31,24 +31,24 @@ func activityFollow(w http.ResponseWriter, r *http.Request) {
activity, err := FollowFromStorage(r.Context(), id)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil:
activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity)
if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
default:
if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else {
log.Error().Err(err).Msg("Failed to get create activity from db")
}
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}

View file

@ -42,7 +42,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
data := map[string]any{}
err = json.Unmarshal(body, &data)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -53,7 +53,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
return
}
if _, ok := data["@context"]; !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -65,7 +65,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
}
objectType, ok := data["type"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -77,7 +77,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
}
_, ok = data["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -104,7 +104,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
handleCreate(w, r, data)
default:
log.Warn().Str("object-type", objectType).Msg("Unknown message type")
webutils.ProblemDetailsStatusOnly(w, 500)
_ = webutils.ProblemDetailsStatusOnly(w, 500)
}
}
@ -113,7 +113,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
activityId := object["id"].(string)
likerUrl, ok := object["actor"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -126,7 +126,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
// TODO: Account for case where object is embedded in like
targetUrl, ok := object["object"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -142,7 +142,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Strs("match-results", targetIdMatches).
Str("url", targetUrl).
Msg("Url didn't match id extractor regex")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
targetId := targetIdMatches[1]
@ -152,7 +152,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
switch err {
case nil:
case gorm.ErrRecordNotFound:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -163,7 +163,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
return
default:
log.Error().Err(err).Str("note-id", targetId).Msg("Failed to get note from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
// Import liker after verifying that target note is correct
@ -173,7 +173,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Err(err).
Str("liker-url", likerUrl).
Msg("Failed to import liking remote account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
reaction := models.Reaction{
@ -190,7 +190,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
// TODO: Create corresponding activity too
activity := models.Activity{
@ -203,12 +203,12 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit reaction transaction to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}
@ -217,7 +217,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
log.Debug().Msg("Received follow request")
objectId, ok := object["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -229,7 +229,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
actorApId, ok := object["actor"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -241,7 +241,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetUrl, ok := object["object"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -253,7 +253,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
followedMatch := objectIdRegex.FindStringSubmatch(targetUrl)
if len(followedMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -267,18 +267,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
followed, err := dbgen.User.Where(dbgen.User.ID.Eq(followedId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("target-id", followedId).Msg("Failed to get account from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
if err != nil {
log.Error().Err(err).Msg("Failed to import following account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
u2u := dbgen.UserToUserRelation
@ -296,7 +296,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
Str("follower", follower.ID).
Str("followed", followedId).
Msg("Failed to count follow relations")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if followRelations > 0 {
@ -312,7 +312,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -325,13 +325,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !followed.RestrictedFollow {
@ -340,7 +340,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to update follow to confirmed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
acceptActivity := models.Activity{
@ -353,13 +353,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit follow accept to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
go func() {
@ -402,7 +402,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r)
rawTarget, ok := object["object"]
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -422,7 +422,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -434,7 +434,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetObjectId, ok = target["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -445,7 +445,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
return
}
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -457,7 +457,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
}
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -471,7 +471,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -479,7 +479,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -490,7 +490,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err {
case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -499,7 +499,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to update follow status to confirmed follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -515,7 +515,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
@ -524,7 +524,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
@ -534,7 +534,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r)
rawTarget, ok := object["object"]
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -554,7 +554,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -566,7 +566,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetObjectId, ok = target["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -577,7 +577,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
return
}
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -589,7 +589,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
}
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -603,7 +603,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -611,7 +611,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -621,7 +621,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err {
case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -630,7 +630,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to delete follow status")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = tx.Activity.Where(
@ -641,7 +641,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to delete accept for later rejected follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -657,7 +657,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
@ -666,7 +666,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
@ -680,7 +680,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Any("raw", object).
Msg("Failed to marshal create activity to proper type")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
actingUser, err := activitypub.ImportRemoteAccountByAPUrl(activity.Actor)
@ -689,7 +689,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("actor", activity.Actor).
Msg("Failed to import remote actor for note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
switch val := activity.Object.(type) {
@ -697,18 +697,18 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
actor, err := dbgen.User.GetById(r.PathValue("id"))
if err != nil {
log.Error().Err(err).Msg("Failed to get local actor for importing targeted note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = activitypub.ImportRemoteNote(val, actor)
if err != nil {
log.Error().Err(err).Str("note-url", val).Msg("Failed to import remote note that landed as id in the inbox")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
return
case map[string]any:
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -733,11 +733,11 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Any("raw", activity.Object).
Msg("Failed to unmarshal create object into note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if objectNote.Type != "Note" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -774,7 +774,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
createActivity := models.Activity{
@ -787,13 +787,13 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note create activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Any("note", dbNote).Msg("Failed to submit note creation in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}

View file

@ -17,7 +17,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
_ = object["id"].(string)
_, ok := object["actor"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -29,7 +29,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
}
rawTarget, ok := object["object"]
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -49,7 +49,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
case map[string]any:
objType, ok := target["type"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -62,7 +62,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
targetObjectType = objType
targetObjectId, ok = target["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -73,7 +73,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
return
}
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -92,7 +92,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
log.Error().
Str("undo-target-type", targetObjectType).
Msg("Unknown/unimplemented undo target type")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}
@ -109,7 +109,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err).
Str("activity-id", targetId).
Msg("Error while looking for like activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
reactionId := uint(other.Must(strconv.ParseUint(act.ObjectId, 10, 64)))
@ -123,7 +123,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err).
Str("activity-id", targetId).
Msg("Error while looking for find activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
tx := dbgen.Q.Begin()
@ -131,7 +131,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Str("activity-id", act.Id).Msg("Failed to delete activity on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = tx.Reaction.Where(dbgen.Reaction.ID.Eq(reaction.ID)).Delete()
@ -141,13 +141,13 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err).
Uint("reaction-id", reaction.ID).
Msg("Failed to delete reaction on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to delete reaction and activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}
@ -164,7 +164,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err).
Str("activity-id", targetId).
Msg("Error while looking for follow activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
relationId := other.Must(strconv.ParseUint(act.ObjectId, 10, 64))
@ -176,7 +176,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err).
Str("activity-id", act.Id).
Msg("Failed to delete follow activity on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
// Delete all activities that reference the follow activity (so accept/reject if exists)
@ -187,7 +187,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err).
Str("activity-id", act.Id).
Msg("Failed to delete accept/reject activity for follow on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = tx.UserToUserRelation.Where(dbgen.UserToUserRelation.ID.Eq(relationId)).Delete()
@ -198,12 +198,12 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Str("activity-id", act.Id).
Uint64("relation-id", relationId).
Msg("Failed to delete user-to-user relation for follow on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to delete reaction and activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}

View file

@ -51,25 +51,25 @@ func objectNote(w http.ResponseWriter, r *http.Request) {
note, err := NoteFromStorage(r.Context(), id)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
note.Context = activitypub.BaseLdContext
data, err := json.Marshal(note)
if err != nil {
log.Error().Err(err).Any("activity", note).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
default:
if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else {
log.Error().Err(err).Msg("Failed to get create activity from db")
}
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}

View file

@ -63,7 +63,14 @@ func users(w http.ResponseWriter, r *http.Request) {
Preload(dbgen.User.BeingTypes).
First()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -146,11 +153,11 @@ func users(w http.ResponseWriter, r *http.Request) {
encoded, err := json.Marshal(data)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal response")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(encoded))
_, _ = fmt.Fprint(w, string(encoded))
}
func userFollowing(w http.ResponseWriter, r *http.Request) {
@ -160,11 +167,11 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !exists {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
}
apUrl := activitypub.UserIdToApUrl(userId)
@ -172,7 +179,7 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
followingCount, err := dbgen.UserToUserRelation.CountFollowingForId(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get following count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if pageNrStr == "" {
@ -186,13 +193,13 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col)
if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
} else {
pageNr, err := strconv.Atoi(pageNrStr)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -207,12 +214,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
links, err := dbgen.UserToUserRelation.GetFollowingApLinksPagedForId(userId, pageNr)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
page := collectionPageOut{
@ -231,12 +238,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page)
if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
}
func userFollowers(w http.ResponseWriter, r *http.Request) {
@ -246,12 +253,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !exists {
log.Debug().Str("id", userId).Msg("user not found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
}
apUrl := activitypub.UserIdToApUrl(userId)
@ -259,7 +266,7 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
followersCount, err := dbgen.UserToUserRelation.CountFollowersForId(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get followers count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if pageNrStr == "" {
@ -273,13 +280,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col)
if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
} else {
pageNr, err := strconv.Atoi(pageNrStr)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -295,12 +302,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
switch err {
case gorm.ErrRecordNotFound:
log.Debug().Msg("No followers found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
page := collectionPageOut{
@ -319,13 +326,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page)
if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
log.Debug().Bytes("body", data).Msg("Sending collection(page) out")
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
}
/*
@ -354,7 +361,7 @@ var chain goap.BaseApChain = &goap.EmptyBaseObject{}
// data, err := goap.Compact(chain, baseLdContext)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal ap chain")
webutils.ProblemDetailsStatusOnly(w, 500)
_ = webutils.ProblemDetailsStatusOnly(w, 500)
return
}
*/

View file

@ -27,7 +27,7 @@ func BuildApiRouter() http.Handler {
),
)
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "in api")
_, _ = fmt.Fprint(w, "in api")
})
return router
}

View file

@ -35,7 +35,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
requestedResource := r.FormValue("resource")
matches := webfingerResourceRegex.FindStringSubmatch(requestedResource)
if len(matches) == 0 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/webfinger-bad-resource",
@ -56,16 +56,16 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
// Fail if requested user is a different domain
// TODO: Decide whether to include the info that it's a different domain
if domain != config.GlobalConfig.General.GetFullDomain() {
webutils.ProblemDetailsStatusOnly(w, 404)
_ = webutils.ProblemDetailsStatusOnly(w, 404)
return
}
user, err := dbgen.User.GetByUsername(username)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
webutils.ProblemDetailsStatusOnly(w, 404)
_ = webutils.ProblemDetailsStatusOnly(w, 404)
} else {
// Fail the request, then attempt to reconnect
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -101,7 +101,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
},
},
}
webutils.SendJson(w, &data)
_ = webutils.SendJson(w, &data)
}
func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
@ -117,7 +117,7 @@ func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
},
},
}
webutils.SendJson(w, data)
_ = webutils.SendJson(w, data)
}
func NodeInfo21(w http.ResponseWriter, r *http.Request) {
@ -125,7 +125,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true), u.ServerId.Eq(1)).Count()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -136,7 +143,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
n := dbgen.Note
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -169,7 +183,7 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
LocalComments: 0},
Metadata: map[string]any{},
}
webutils.SendJson(w, data)
_ = webutils.SendJson(w, data)
}
func NodeInfo20(w http.ResponseWriter, r *http.Request) {
@ -177,7 +191,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).Count()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -188,7 +209,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
n := dbgen.Note
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -221,5 +249,5 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
Metadata: map[string]any{},
}
webutils.SendJson(w, data)
_ = webutils.SendJson(w, data)
}

View file

@ -21,6 +21,6 @@ func errorTypeHandler(w http.ResponseWriter, r *http.Request) {
if description, ok := errorDescriptions[errName]; ok {
_, _ = fmt.Fprint(w, description)
} else {
webutils.ProblemDetailsStatusOnly(w, 404)
_ = webutils.ProblemDetailsStatusOnly(w, 404)
}
}

View file

@ -80,7 +80,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawDate := r.Header.Get("Date")
date, err := http.ParseTime(rawDate)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-date",
@ -91,7 +91,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
return
}
if time.Since(date) > time.Hour+time.Minute*5 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -105,7 +105,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
if signatureHeader == "" {
log.Debug().
Msg("Received AP request without signature header where one is required")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -123,7 +123,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
log.Debug().
Str("header", signatureHeader).
Msg("Received signature with invalid pattern")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -143,7 +143,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawAlgorithm2 := match[4]
signature, err := base64.StdEncoding.DecodeString(match[5])
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -167,7 +167,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
_, err = url.Parse(rawKeyId)
if err != nil {
log.Debug().Err(err).Msg("Key id is not an url")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -184,7 +184,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
requestingActor, err := getRequestingActor(rawKeyId)
if err != nil {
log.Error().Err(err).Msg("Failed to get requesting actor")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -206,7 +206,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawKey, err := x509.ParsePKIXPublicKey(requestingActor.PublicKeyRsa)
if err != nil {
log.Warn().Err(err).Msg("Failed to parse public key of requesting actor")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -220,7 +220,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
key, ok = rawKey.(*rsa.PublicKey)
if !ok {
log.Warn().Msg("Received public key is not rsa")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",
@ -235,7 +235,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
err = rsa.VerifyPKCS1v15(key, crypto.SHA256, hash[:], []byte(signature))
if err != nil {
log.Warn().Err(err).Msg("Signature verification failed")
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnauthorized,
"/errors/invalid-auth-signature",

View file

@ -19,7 +19,7 @@ func BuildMimetypeCheck(acceptedMimetypes []string) webutils.HandlerBuilder {
}
}
// Requested mimtype not in list of accepted ones, failing request with note
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusUnsupportedMediaType,
"/errors/bad-accept-mime-type",

View file

@ -24,7 +24,7 @@ func SignRequest(r *http.Request, keyId string, privateKeyBytes, postBody []byte
} else {
headers.Set("Date", time.Now().UTC().Format(http.TimeFormat))
}
applyBodyHash(headers, postBody)
_ = applyBodyHash(headers, postBody)
// Filter for only the date, host, digest and request-target headers
var signedString string
var usedHeaders []string

View file

@ -21,7 +21,7 @@ func TestSignRequest(t *testing.T) {
func Test_applyBodyHash_WithBody(t *testing.T) {
var headers = make(http.Header, 0)
digest := "SHA-256=" + string(testBodyHash)
applyBodyHash(headers, []byte(testBody))
_ = applyBodyHash(headers, []byte(testBody))
headerDigest := headers.Get("Digest")
if headerDigest != digest {
t.Fatalf("digests didn't match: header \"%v\" != precalc \"%v\"", headerDigest, digest)