Go fmt ./...

This commit is contained in:
tsmethurst 2021-05-21 23:03:55 +02:00
commit 762dfe4b7e
7 changed files with 53 additions and 51 deletions

View file

@ -69,7 +69,7 @@ func (m *Module) OauthTokenMiddleware(c *gin.Context) {
if cid := ti.GetClientID(); cid != "" { if cid := ti.GetClientID(); cid != "" {
l.Tracef("authenticated client %s with bearer token, scope is %s", cid, ti.GetScope()) l.Tracef("authenticated client %s with bearer token, scope is %s", cid, ti.GetScope())
app := &gtsmodel.Application{} app := &gtsmodel.Application{}
if err := m.db.GetWhere([]db.Where{{Key: "client_id",Value: cid}}, app); err != nil { if err := m.db.GetWhere([]db.Where{{Key: "client_id", Value: cid}}, app); err != nil {
l.Tracef("no app found for client %s", cid) l.Tracef("no app found for client %s", cid)
} }
c.Set(oauth.SessionAuthorizedApplication, app) c.Set(oauth.SessionAuthorizedApplication, app)

View file

@ -32,18 +32,20 @@ const (
// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query. // ErrNoEntries is to be returned from the DB interface when no entries are found for a given query.
type ErrNoEntries struct{} type ErrNoEntries struct{}
func (e ErrNoEntries) Error() string { func (e ErrNoEntries) Error() string {
return "no entries" return "no entries"
} }
// ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints. // ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints.
type ErrAlreadyExists struct{} type ErrAlreadyExists struct{}
func (e ErrAlreadyExists) Error() string { func (e ErrAlreadyExists) Error() string {
return "already exists" return "already exists"
} }
type Where struct { type Where struct {
Key string Key string
Value interface{} Value interface{}
} }

View file

@ -164,46 +164,46 @@ func (p *processor) GetFediFollowers(requestedUsername string, request *http.Req
} }
func (p *processor) GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, ErrorWithCode) { func (p *processor) GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, ErrorWithCode) {
// get the account the request is referring to // get the account the request is referring to
requestedAccount := &gtsmodel.Account{} requestedAccount := &gtsmodel.Account{}
if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil { if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err)) return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
} }
// authenticate the request // authenticate the request
requestingAccount, err := p.authenticateAndDereferenceFediRequest(requestedUsername, request) requestingAccount, err := p.authenticateAndDereferenceFediRequest(requestedUsername, request)
if err != nil { if err != nil {
return nil, NewErrorNotAuthorized(err) return nil, NewErrorNotAuthorized(err)
} }
blocked, err := p.db.Blocked(requestedAccount.ID, requestingAccount.ID) blocked, err := p.db.Blocked(requestedAccount.ID, requestingAccount.ID)
if err != nil { if err != nil {
return nil, NewErrorInternalError(err) return nil, NewErrorInternalError(err)
} }
if blocked { if blocked {
return nil, NewErrorNotAuthorized(fmt.Errorf("block exists between accounts %s and %s", requestedAccount.ID, requestingAccount.ID)) return nil, NewErrorNotAuthorized(fmt.Errorf("block exists between accounts %s and %s", requestedAccount.ID, requestingAccount.ID))
} }
s := &gtsmodel.Status{} s := &gtsmodel.Status{}
if err := p.db.GetWhere([]db.Where{ if err := p.db.GetWhere([]db.Where{
{Key: "id", Value: requestedStatusID}, {Key: "id", Value: requestedStatusID},
{Key: "account_id", Value: requestedAccount.ID}, {Key: "account_id", Value: requestedAccount.ID},
}, s); err != nil { }, s); err != nil {
return nil, NewErrorNotFound(fmt.Errorf("database error getting status with id %s and account id %s: %s", requestedStatusID, requestedAccount.ID, err)) return nil, NewErrorNotFound(fmt.Errorf("database error getting status with id %s and account id %s: %s", requestedStatusID, requestedAccount.ID, err))
} }
asStatus, err := p.tc.StatusToAS(s) asStatus, err := p.tc.StatusToAS(s)
if err != nil { if err != nil {
return nil, NewErrorInternalError(err) return nil, NewErrorInternalError(err)
} }
data, err := streams.Serialize(asStatus) data, err := streams.Serialize(asStatus)
if err != nil { if err != nil {
return nil, NewErrorInternalError(err) return nil, NewErrorInternalError(err)
} }
return data, nil return data, nil
} }
func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) { func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) {

View file

@ -25,5 +25,5 @@ func (p *processor) notifyStatus(status *gtsmodel.Status) error {
} }
func (p *processor) notifyFollow(follow *gtsmodel.Follow) error { func (p *processor) notifyFollow(follow *gtsmodel.Follow) error {
return nil return nil
} }

View file

@ -56,7 +56,7 @@ func (p *processor) FollowRequestAccept(auth *oauth.Auth, accountID string) (*ap
p.fromClientAPI <- gtsmodel.FromClientAPI{ p.fromClientAPI <- gtsmodel.FromClientAPI{
APActivityType: gtsmodel.ActivityStreamsAccept, APActivityType: gtsmodel.ActivityStreamsAccept,
GTSModel: follow, GTSModel: follow,
} }
gtsR, err := p.db.GetRelationship(auth.Account.ID, accountID) gtsR, err := p.db.GetRelationship(auth.Account.ID, accountID)
@ -65,7 +65,7 @@ func (p *processor) FollowRequestAccept(auth *oauth.Auth, accountID string) (*ap
} }
r, err := p.tc.RelationshipToMasto(gtsR) r, err := p.tc.RelationshipToMasto(gtsR)
if err != nil { if err != nil {
return nil, NewErrorInternalError(err) return nil, NewErrorInternalError(err)
} }

View file

@ -439,7 +439,7 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
// replies // replies
// TODO // TODO
return status, nil return status, nil
} }

View file

@ -575,18 +575,18 @@ func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, erro
func (c *converter) RelationshipToMasto(r *gtsmodel.Relationship) (*model.Relationship, error) { func (c *converter) RelationshipToMasto(r *gtsmodel.Relationship) (*model.Relationship, error) {
return &model.Relationship{ return &model.Relationship{
ID: r.ID, ID: r.ID,
Following: r.Following, Following: r.Following,
ShowingReblogs: r.ShowingReblogs, ShowingReblogs: r.ShowingReblogs,
Notifying: r.Notifying, Notifying: r.Notifying,
FollowedBy: r.FollowedBy, FollowedBy: r.FollowedBy,
Blocking: r.Blocking, Blocking: r.Blocking,
BlockedBy: r.BlockedBy, BlockedBy: r.BlockedBy,
Muting: r.Muting, Muting: r.Muting,
MutingNotifications: r.MutingNotifications, MutingNotifications: r.MutingNotifications,
Requested: r.Requested, Requested: r.Requested,
DomainBlocking: r.DomainBlocking, DomainBlocking: r.DomainBlocking,
Endorsed: r.Endorsed, Endorsed: r.Endorsed,
Note: r.Note, Note: r.Note,
}, nil }, nil
} }