Enable stricter linting with golangci-lint (#316)

* update golangci-lint

* add golangci config file w/ more linters

* correct issues flagged by stricter linters

* add more generous timeout for golangci-lint

* add some style + formatting guidelines

* move timeout to config file

* go fmt
This commit is contained in:
tobi 2021-11-22 08:46:19 +01:00 committed by GitHub
commit f8630348b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 227 additions and 163 deletions

View file

@ -149,7 +149,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
requestingPublicKeyID, err := url.Parse(verifier.KeyId())
if err != nil {
l.Debug("couldn't parse public key URL")
return nil, false, nil // couldn't parse the public key ID url
return nil, false, err // couldn't parse the public key ID url
}
requestingRemoteAccount := &gtsmodel.Account{}

View file

@ -172,7 +172,7 @@ pageLoop:
l.Debugf("dereferencing page %s", currentPageIRI)
nextPage, err := d.DereferenceCollectionPage(ctx, username, currentPageIRI)
if err != nil {
return nil
return err
}
// next items could be either a list of URLs or a list of statuses
@ -188,19 +188,19 @@ pageLoop:
// We're looking for a url to feed to GetRemoteStatus.
// Items can be either an IRI, or a Note.
// If a note, we grab the ID from it and call it, rather than parsing the note.
var itemURI *url.URL
if iter.IsIRI() {
switch {
case iter.IsIRI():
// iri, easy
itemURI = iter.GetIRI()
} else if iter.IsActivityStreamsNote() {
case iter.IsActivityStreamsNote():
// note, get the id from it to use as iri
n := iter.GetActivityStreamsNote()
id := n.GetJSONLDId()
if id != nil && id.IsIRI() {
itemURI = id.GetIRI()
}
} else {
default:
// if it's not an iri or a note, we don't know how to process it
continue
}
@ -211,7 +211,7 @@ pageLoop:
}
// we can confidently say now that we found something
foundReplies = foundReplies + 1
foundReplies++
// get the remote statusable and put it in the db
_, statusable, new, err := d.GetRemoteStatus(ctx, username, itemURI, false, false)

View file

@ -97,9 +97,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
if iter.GetType() == nil {
continue
}
switch iter.GetType().GetTypeName() {
// we have the whole object so we can figure out what we're accepting
case ap.ActivityFollow:
if iter.GetType().GetTypeName() == ap.ActivityFollow {
// ACCEPT FOLLOW
asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok {

View file

@ -24,6 +24,8 @@ import (
"net/url"
"sync"
"sync/atomic"
"github.com/sirupsen/logrus"
)
// Lock takes a lock for the object at the specified id. If an error
@ -54,7 +56,10 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
// Get mutex, or create new
mu, ok := f.locks[idStr]
if !ok {
mu = f.pool.Get().(*mutex)
mu, ok = f.pool.Get().(*mutex)
if !ok {
logrus.Panic("Lock: pool entry was not a *mutex")
}
f.locks[idStr] = mu
}

View file

@ -90,9 +90,8 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
continue
}
switch iter.GetType().GetTypeName() {
// we have the whole object so we can figure out what we're rejecting
case ap.ActivityFollow:
if iter.GetType().GetTypeName() == ap.ActivityFollow {
// we have the whole object so we can figure out what we're rejecting
// REJECT FOLLOW
asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok {

View file

@ -308,17 +308,29 @@ func (f *federatingDB) collectIRIs(ctx context.Context, iris []*url.URL) (vocab.
func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) {
receivingAccountI := ctx.Value(util.APReceivingAccount)
if receivingAccountI != nil {
receivingAccount = receivingAccountI.(*gtsmodel.Account)
var ok bool
receivingAccount, ok = receivingAccountI.(*gtsmodel.Account)
if !ok {
logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APReceivingAccount)
}
}
requestingAcctI := ctx.Value(util.APRequestingAccount)
if requestingAcctI != nil {
requestingAccount = requestingAcctI.(*gtsmodel.Account)
var ok bool
requestingAccount, ok = requestingAcctI.(*gtsmodel.Account)
if !ok {
logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APRequestingAccount)
}
}
fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey)
if fromFederatorChanI != nil {
fromFederatorChan = fromFederatorChanI.(chan messages.FromFederator)
var ok bool
fromFederatorChan, ok = fromFederatorChanI.(chan messages.FromFederator)
if !ok {
logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to chan messages.FromFederator", util.APFromFederatorChanKey)
}
}
return

View file

@ -54,17 +54,18 @@ func (f *federator) NewTransport(ctx context.Context, actorBoxIRI *url.URL, gofe
var username string
var err error
if util.IsInboxPath(actorBoxIRI) {
switch {
case util.IsInboxPath(actorBoxIRI):
username, err = util.ParseInboxPath(actorBoxIRI)
if err != nil {
return nil, fmt.Errorf("couldn't parse path %s as an inbox: %s", actorBoxIRI.String(), err)
}
} else if util.IsOutboxPath(actorBoxIRI) {
case util.IsOutboxPath(actorBoxIRI):
username, err = util.ParseOutboxPath(actorBoxIRI)
if err != nil {
return nil, fmt.Errorf("couldn't parse path %s as an outbox: %s", actorBoxIRI.String(), err)
}
} else {
default:
return nil, fmt.Errorf("id %s was neither an inbox path nor an outbox path", actorBoxIRI.String())
}