From a602a3d9d225a3298139a832080f455c0d6be6f2 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Sat, 15 May 2021 11:53:38 +0200 Subject: [PATCH] fmt + lint --- internal/api/client/auth/token.go | 2 +- internal/api/client/followrequest/accept.go | 2 ++ internal/api/client/followrequest/deny.go | 2 ++ internal/api/client/followrequest/get.go | 1 + internal/api/client/instance/instance.go | 2 +- internal/api/client/instance/instanceget.go | 1 + internal/api/client/media/media.go | 2 ++ internal/api/client/media/mediaget.go | 2 +- internal/api/model/attachment.go | 6 +++--- internal/api/model/status.go | 4 ++++ internal/api/s2s/user/inboxpost.go | 2 ++ internal/api/s2s/user/user.go | 3 ++- internal/api/s2s/webfinger/webfinger.go | 2 +- internal/db/db.go | 10 +++++++++- internal/db/pg/pg.go | 4 ++-- internal/federation/clock.go | 1 + internal/federation/federating_db.go | 13 +++++++------ internal/typeutils/asinterfaces.go | 1 + internal/typeutils/astointernal.go | 4 ++-- testrig/federator.go | 1 + testrig/testmodels.go | 8 +++++--- 21 files changed, 51 insertions(+), 22 deletions(-) diff --git a/internal/api/client/auth/token.go b/internal/api/client/auth/token.go index 886c7e064..798a88d19 100644 --- a/internal/api/client/auth/token.go +++ b/internal/api/client/auth/token.go @@ -42,7 +42,7 @@ func (m *Module) TokenPOSTHandler(c *gin.Context) { form := &tokenBody{} if err := c.ShouldBind(form); err == nil { - c.Request.Form = url.Values{} + c.Request.Form = url.Values{} if form.ClientID != nil { c.Request.Form.Set("client_id", *form.ClientID) } diff --git a/internal/api/client/followrequest/accept.go b/internal/api/client/followrequest/accept.go index ecfc8c700..45dc1a2af 100644 --- a/internal/api/client/followrequest/accept.go +++ b/internal/api/client/followrequest/accept.go @@ -25,6 +25,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +// FollowRequestAcceptPOSTHandler deals with follow request accepting. It should be served at +// /api/v1/follow_requests/:id/authorize func (m *Module) FollowRequestAcceptPOSTHandler(c *gin.Context) { l := m.log.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) diff --git a/internal/api/client/followrequest/deny.go b/internal/api/client/followrequest/deny.go index 59136cb7d..c1a9e4dbf 100644 --- a/internal/api/client/followrequest/deny.go +++ b/internal/api/client/followrequest/deny.go @@ -20,6 +20,8 @@ package followrequest import "github.com/gin-gonic/gin" +// FollowRequestDenyPOSTHandler deals with follow request rejection. It should be served at +// /api/v1/follow_requests/:id/reject func (m *Module) FollowRequestDenyPOSTHandler(c *gin.Context) { } diff --git a/internal/api/client/followrequest/get.go b/internal/api/client/followrequest/get.go index d117095c2..3f02ee02a 100644 --- a/internal/api/client/followrequest/get.go +++ b/internal/api/client/followrequest/get.go @@ -25,6 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +// FollowRequestGETHandler allows clients to get a list of their incoming follow requests. func (m *Module) FollowRequestGETHandler(c *gin.Context) { l := m.log.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) diff --git a/internal/api/client/instance/instance.go b/internal/api/client/instance/instance.go index ed7c18718..ba54480a5 100644 --- a/internal/api/client/instance/instance.go +++ b/internal/api/client/instance/instance.go @@ -11,7 +11,7 @@ import ( ) const ( - // InstanceInformationPath + // InstanceInformationPath is for serving instance info requests InstanceInformationPath = "api/v1/instance" ) diff --git a/internal/api/client/instance/instanceget.go b/internal/api/client/instance/instanceget.go index f8e82c096..6ae419a83 100644 --- a/internal/api/client/instance/instanceget.go +++ b/internal/api/client/instance/instanceget.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" ) +// InstanceInformationGETHandler is for serving instance information at /api/v1/instance func (m *Module) InstanceInformationGETHandler(c *gin.Context) { l := m.log.WithField("func", "InstanceInformationGETHandler") diff --git a/internal/api/client/media/media.go b/internal/api/client/media/media.go index e45eec7ea..f68a73c2c 100644 --- a/internal/api/client/media/media.go +++ b/internal/api/client/media/media.go @@ -33,8 +33,10 @@ import ( // BasePath is the base API path for making media requests const BasePath = "/api/v1/media" + // IDKey is the key for media attachment IDs const IDKey = "id" + // BasePathWithID corresponds to a media attachment with the given ID const BasePathWithID = BasePath + "/:" + IDKey diff --git a/internal/api/client/media/mediaget.go b/internal/api/client/media/mediaget.go index 31c40a5aa..7acb475ce 100644 --- a/internal/api/client/media/mediaget.go +++ b/internal/api/client/media/mediaget.go @@ -43,7 +43,7 @@ func (m *Module) MediaGETHandler(c *gin.Context) { attachment, errWithCode := m.processor.MediaGet(authed, attachmentID) if errWithCode != nil { - c.JSON(errWithCode.Code(),gin.H{"error": errWithCode.Safe()}) + c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()}) return } diff --git a/internal/api/model/attachment.go b/internal/api/model/attachment.go index ce0e13600..ed53757eb 100644 --- a/internal/api/model/attachment.go +++ b/internal/api/model/attachment.go @@ -28,11 +28,11 @@ type AttachmentRequest struct { Focus string `form:"focus"` } -// AttachmentRequest represents the form data parameters submitted by a client during a media update/PUT request. +// AttachmentUpdateRequest represents the form data parameters submitted by a client during a media update/PUT request. // See: https://docs.joinmastodon.org/methods/statuses/media/ type AttachmentUpdateRequest struct { - Description *string `form:"description" json:"description" xml:"description"` - Focus *string `form:"focus" json:"focus" xml:"focus"` + Description *string `form:"description" json:"description" xml:"description"` + Focus *string `form:"focus" json:"focus" xml:"focus"` } // Attachment represents the object returned to a client after a successful media upload request. diff --git a/internal/api/model/status.go b/internal/api/model/status.go index 54d021e29..2cb22aa0d 100644 --- a/internal/api/model/status.go +++ b/internal/api/model/status.go @@ -119,11 +119,15 @@ const ( VisibilityDirect Visibility = "direct" ) +// AdvancedStatusCreateForm wraps the mastodon status create form along with the GTS advanced +// visibility settings. type AdvancedStatusCreateForm struct { StatusCreateRequest AdvancedVisibilityFlagsForm } +// AdvancedVisibilityFlagsForm allows a few more advanced flags to be set on new statuses, in addition +// to the standard mastodon-compatible ones. type AdvancedVisibilityFlagsForm struct { // The gotosocial visibility model VisibilityAdvanced *string `form:"visibility_advanced"` diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go index 7be36590a..60b74ab70 100644 --- a/internal/api/s2s/user/inboxpost.go +++ b/internal/api/s2s/user/inboxpost.go @@ -26,6 +26,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/message" ) +// InboxPOSTHandler deals with incoming POST requests to an actor's inbox. +// Eg., POST to https://example.org/users/whatever/inbox. func (m *Module) InboxPOSTHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "InboxPOSTHandler", diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go index 36c1389d1..a6116247d 100644 --- a/internal/api/s2s/user/user.go +++ b/internal/api/s2s/user/user.go @@ -38,7 +38,8 @@ const ( // Use this anywhere you need to know the username of the user being queried. // Eg https://example.org/users/:username UsersBasePathWithUsername = UsersBasePath + "/:" + UsernameKey - UsersInboxPath = UsersBasePathWithUsername + "/" + util.InboxPath + // UsersInboxPath is for serving POST requests to a user's inbox with the given username key. + UsersInboxPath = UsersBasePathWithUsername + "/" + util.InboxPath ) // ActivityPubAcceptHeaders represents the Accept headers mentioned here: diff --git a/internal/api/s2s/webfinger/webfinger.go b/internal/api/s2s/webfinger/webfinger.go index c11d3fb61..168fe1e76 100644 --- a/internal/api/s2s/webfinger/webfinger.go +++ b/internal/api/s2s/webfinger/webfinger.go @@ -29,7 +29,7 @@ import ( ) const ( - // The base path for serving webfinger lookup requests + // WebfingerBasePath is the base path for serving webfinger lookup requests WebfingerBasePath = ".well-known/webfinger" ) diff --git a/internal/db/db.go b/internal/db/db.go index f425f0ead..a354ddee8 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -26,7 +26,10 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -const DBTypePostgres string = "POSTGRES" +const ( + // DBTypePostgres represents an underlying POSTGRES database type. + DBTypePostgres string = "POSTGRES" +) // ErrNoEntries is to be returned from the DB interface when no entries are found for a given query. type ErrNoEntries struct{} @@ -112,6 +115,8 @@ type DB interface { HANDY SHORTCUTS */ + // AcceptFollowRequest moves a follow request in the database from the follow_requests table to the follows table. + // In other words, it should create the follow, and delete the existing follow request. AcceptFollowRequest(originAccountID string, targetAccountID string) error // CreateInstanceAccount creates an account in the database with the same username as the instance host value. @@ -150,6 +155,9 @@ type DB interface { // In case of no entries, a 'no entries' error will be returned GetFollowersByAccountID(accountID string, followers *[]gtsmodel.Follow) error + // GetFavesByAccountID is a shortcut for the common action of fetching a list of faves made by the given accountID. + // The given slice 'faves' will be set to the result of the query, whatever it is. + // In case of no entries, a 'no entries' error will be returned GetFavesByAccountID(accountID string, faves *[]gtsmodel.StatusFave) error // GetStatusesByAccountID is a shortcut for the common action of fetching a list of statuses produced by accountID. diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go index 82db68559..f8c2fdbe8 100644 --- a/internal/db/pg/pg.go +++ b/internal/db/pg/pg.go @@ -317,9 +317,9 @@ func (ps *postgresService) AcceptFollowRequest(originAccountID string, targetAcc } follow := >smodel.Follow{ - AccountID: originAccountID, + AccountID: originAccountID, TargetAccountID: targetAccountID, - URI: fr.URI, + URI: fr.URI, } if _, err := ps.conn.Model(follow).Insert(); err != nil { diff --git a/internal/federation/clock.go b/internal/federation/clock.go index f0d6f5e84..cc67f8b73 100644 --- a/internal/federation/clock.go +++ b/internal/federation/clock.go @@ -37,6 +37,7 @@ func (c *Clock) Now() time.Time { return time.Now() } +// NewClock returns a simple pub.Clock for use in federation interfaces. func NewClock() pub.Clock { return &Clock{} } diff --git a/internal/federation/federating_db.go b/internal/federation/federating_db.go index f3d0cbe1b..4ea0412e7 100644 --- a/internal/federation/federating_db.go +++ b/internal/federation/federating_db.go @@ -47,6 +47,7 @@ type federatingDB struct { typeConverter typeutils.TypeConverter } +// NewFederatingDB returns a pub.Database interface using the given database, config, and logger. func NewFederatingDB(db db.DB, config *config.Config, log *logrus.Logger) pub.Database { return &federatingDB{ locks: new(sync.Map), @@ -505,8 +506,8 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (id *url.URL, err func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) { l := f.log.WithFields( logrus.Fields{ - "func": "Followers", - "actorIRI": actorIRI.String(), + "func": "Followers", + "actorIRI": actorIRI.String(), }, ) l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String()) @@ -547,8 +548,8 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) { l := f.log.WithFields( logrus.Fields{ - "func": "Following", - "actorIRI": actorIRI.String(), + "func": "Following", + "actorIRI": actorIRI.String(), }, ) l.Debugf("entering FOLLOWING function with actorIRI %s", actorIRI.String()) @@ -589,8 +590,8 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin func (f *federatingDB) Liked(c context.Context, actorIRI *url.URL) (liked vocab.ActivityStreamsCollection, err error) { l := f.log.WithFields( logrus.Fields{ - "func": "Liked", - "actorIRI": actorIRI.String(), + "func": "Liked", + "actorIRI": actorIRI.String(), }, ) l.Debugf("entering LIKED function with actorIRI %s", actorIRI.String()) diff --git a/internal/typeutils/asinterfaces.go b/internal/typeutils/asinterfaces.go index 4a12f9b61..970ed2ecf 100644 --- a/internal/typeutils/asinterfaces.go +++ b/internal/typeutils/asinterfaces.go @@ -95,6 +95,7 @@ type Mentionable interface { withHref } +// Followable represents the minimum interface for an activitystreams 'follow' activity. type Followable interface { withJSONLDId withTypeName diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go index c68e50d3c..7f0a4c1a4 100644 --- a/internal/typeutils/astointernal.go +++ b/internal/typeutils/astointernal.go @@ -333,8 +333,8 @@ func (c *converter) ASFollowToFollowRequest(followable Followable) (*gtsmodel.Fo } followRequest := >smodel.FollowRequest{ - URI: uri, - AccountID: originAccount.ID, + URI: uri, + AccountID: originAccount.ID, TargetAccountID: targetAccount.ID, } diff --git a/testrig/federator.go b/testrig/federator.go index 63ad520db..c2d86fd21 100644 --- a/testrig/federator.go +++ b/testrig/federator.go @@ -24,6 +24,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/transport" ) +// NewTestFederator returns a federator with the given database and (mock!!) transport controller. func NewTestFederator(db db.DB, tc transport.Controller) federation.Federator { return federation.NewFederator(db, tc, NewTestConfig(), NewTestLog(), NewTestTypeConverter(db)) } diff --git a/testrig/testmodels.go b/testrig/testmodels.go index 6d7390729..90d7f63b6 100644 --- a/testrig/testmodels.go +++ b/testrig/testmodels.go @@ -1037,6 +1037,7 @@ func NewTestFaves() map[string]*gtsmodel.StatusFave { } } +// ActivityWithSignature wraps a pub.Activity along with its signature headers, for testing. type ActivityWithSignature struct { Activity pub.Activity SignatureHeader string @@ -1076,11 +1077,11 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit // NewTestFediPeople returns a bunch of activity pub Person representations for testing converters and so on. func NewTestFediPeople() map[string]typeutils.Accountable { - new_person_1priv, err := rsa.GenerateKey(rand.Reader, 2048) + newPerson1Priv, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { panic(err) } - new_person_1pub := &new_person_1priv.PublicKey + newPerson1Pub := &newPerson1Priv.PublicKey return map[string]typeutils.Accountable{ "new_person_1": newPerson( @@ -1096,7 +1097,7 @@ func NewTestFediPeople() map[string]typeutils.Accountable { URLMustParse("https://unknown-instance.com/@brand_new_person"), true, URLMustParse("https://unknown-instance.com/users/brand_new_person#main-key"), - new_person_1pub, + newPerson1Pub, URLMustParse("https://unknown-instance.com/media/some_avatar_filename.jpeg"), "image/jpeg", URLMustParse("https://unknown-instance.com/media/some_header_filename.jpeg"), @@ -1105,6 +1106,7 @@ func NewTestFediPeople() map[string]typeutils.Accountable { } } +// NewTestDereferenceRequests returns a map of incoming dereference requests, with their signatures. func NewTestDereferenceRequests(accounts map[string]*gtsmodel.Account) map[string]ActivityWithSignature { sig, digest, date := getSignatureForDereference(accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].URI)) return map[string]ActivityWithSignature{