From 6f1ce7dcc1da668ca1df0d67f8f9275b1832fd92 Mon Sep 17 00:00:00 2001 From: Preston Baxter Date: Thu, 16 Nov 2023 19:45:48 -0600 Subject: [PATCH] B: gofmt --- service/controllers/controllers.go | 6 +++--- service/vendors/pco/pco.go | 12 ++++++------ service/vendors/pco/services.go | 2 +- service/vendors/pco/services/series.go | 1 - service/vendors/pco/services/service_type.go | 1 - service/vendors/pco/webhooks/structs.go | 4 ++-- service/vendors/youtube/youtube.go | 4 ++-- ui/config/config.go | 20 ++++++++++---------- ui/controllers/actions.go | 6 +++--- ui/controllers/auth.go | 1 - ui/controllers/pages.go | 5 ++--- ui/controllers/pco.go | 2 +- ui/controllers/youtube.go | 3 +-- ui/db/db.go | 6 +++--- ui/db/models/actions.go | 4 ++-- ui/db/models/user.go | 2 +- ui/db/models/vendor.go | 2 -- ui/db/token_source.go | 6 +++--- ui/db/token_source_test.go | 6 +++--- ui/db/user.go | 8 ++++---- ui/db/vendors.go | 6 +++--- 21 files changed, 50 insertions(+), 57 deletions(-) diff --git a/service/controllers/controllers.go b/service/controllers/controllers.go index 5897a57..4b3ec60 100644 --- a/service/controllers/controllers.go +++ b/service/controllers/controllers.go @@ -11,9 +11,9 @@ import ( ) var ( - log *logrus.Logger - mongo *db.DB - ytClientMap map[primitive.ObjectID]*youtube.Service + log *logrus.Logger + mongo *db.DB + ytClientMap map[primitive.ObjectID]*youtube.Service pcoClientMap map[primitive.ObjectID]*pco.PcoApiClient ) diff --git a/service/vendors/pco/pco.go b/service/vendors/pco/pco.go index 12cc70a..080cedf 100644 --- a/service/vendors/pco/pco.go +++ b/service/vendors/pco/pco.go @@ -11,10 +11,10 @@ import ( const PCO_API_URL = "https://api.planningcenteronline.com" type PcoApiClient struct { - oauth *oauth2.Config + oauth *oauth2.Config tokenSource oauth2.TokenSource - client *http.Client - url *url.URL + client *http.Client + url *url.URL } func NewClient() *PcoApiClient { @@ -25,7 +25,7 @@ func NewClient() *PcoApiClient { pco := &PcoApiClient{ oauth: &oauth2.Config{}, - url: pco_url, + url: pco_url, } return pco @@ -38,9 +38,9 @@ func NewClientWithOauthConfig(conf *oauth2.Config, tokenSource oauth2.TokenSourc } pco := &PcoApiClient{ - oauth: conf, + oauth: conf, tokenSource: tokenSource, - url: pco_url, + url: pco_url, } return pco diff --git a/service/vendors/pco/services.go b/service/vendors/pco/services.go index 2e42775..088ced4 100644 --- a/service/vendors/pco/services.go +++ b/service/vendors/pco/services.go @@ -8,7 +8,7 @@ import ( "github.com/google/jsonapi" ) -func (api *PcoApiClient) GetPlan(service_type_id, plan_id string) (*services.Plan, error){ +func (api *PcoApiClient) GetPlan(service_type_id, plan_id string) (*services.Plan, error) { api.Url().Path = fmt.Sprintf("/services/v2/service_types/%s/plans/%s", service_type_id, plan_id) req, err := http.NewRequest(http.MethodGet, api.Url().String(), nil) diff --git a/service/vendors/pco/services/series.go b/service/vendors/pco/services/series.go index ca4821b..c6a5b10 100644 --- a/service/vendors/pco/services/series.go +++ b/service/vendors/pco/services/series.go @@ -1,6 +1,5 @@ package services - type Series struct { Id string `jsonapi:"primary,Series"` } diff --git a/service/vendors/pco/services/service_type.go b/service/vendors/pco/services/service_type.go index 6a57156..b3d85dd 100644 --- a/service/vendors/pco/services/service_type.go +++ b/service/vendors/pco/services/service_type.go @@ -1,6 +1,5 @@ package services - type ServiceType struct { Id string `jsonapi:"primary,ServiceType"` } diff --git a/service/vendors/pco/webhooks/structs.go b/service/vendors/pco/webhooks/structs.go index 7588290..3980a85 100644 --- a/service/vendors/pco/webhooks/structs.go +++ b/service/vendors/pco/webhooks/structs.go @@ -7,7 +7,7 @@ import ( "github.com/google/jsonapi" ) -//Structure delivered to target when sending webhooks +// Structure delivered to target when sending webhooks type EventDelivery struct { //uuid of the EventDelivery ID string `jsonapi:"primary,EventDelivery"` @@ -22,7 +22,7 @@ type EventDelivery struct { Organization *services.Organization `jsonapi:"relation,organization"` } -//Unmarshall payload of EventDelivery into the struct you think it is +// Unmarshall payload of EventDelivery into the struct you think it is func (event *EventDelivery) UnmarshallPayload(obj any) error { return jsonapi.UnmarshalPayload(strings.NewReader(event.Payload), obj) } diff --git a/service/vendors/youtube/youtube.go b/service/vendors/youtube/youtube.go index 328998c..05fc0ec 100644 --- a/service/vendors/youtube/youtube.go +++ b/service/vendors/youtube/youtube.go @@ -8,10 +8,10 @@ import ( const ( STATUS_PRIVATE = "private" - STATUS_PUBLIC = "public" + STATUS_PUBLIC = "public" ) -//Inserts Broadcast into youtube +// Inserts Broadcast into youtube func InsertBroadcast(service *youtube.Service, title string, startTime time.Time, privacyStatus string) (*youtube.LiveBroadcast, error) { liveBroadcast := &youtube.LiveBroadcast{ Snippet: &youtube.LiveBroadcastSnippet{ diff --git a/ui/config/config.go b/ui/config/config.go index c1570fa..65ebc58 100644 --- a/ui/config/config.go +++ b/ui/config/config.go @@ -15,10 +15,10 @@ type config struct { } type MongoConfig struct { - Uri string `mapstructure:"uri"` - EntDb string `mapstructure:"ent_db"` - EntCol string `mapstructure:"ent_col"` - LockDb string `mapstructure:"lock_db"` + Uri string `mapstructure:"uri"` + EntDb string `mapstructure:"ent_db"` + EntCol string `mapstructure:"ent_col"` + LockDb string `mapstructure:"lock_db"` LockCol string `mapstructure:"lock_col"` } @@ -44,13 +44,13 @@ func (vendor *VendorConfig) OauthConfig() *oauth2.Config { return &oauth2.Config{ ClientID: vendor.ClientId, ClientSecret: vendor.ClientSecret, - Endpoint: oauth2.Endpoint{ - AuthURL: vendor.AuthUri, - TokenURL: vendor.TokenUri, - AuthStyle: oauth2.AuthStyleInParams, + Endpoint: oauth2.Endpoint{ + AuthURL: vendor.AuthUri, + TokenURL: vendor.TokenUri, + AuthStyle: oauth2.AuthStyleInParams, }, - RedirectURL: "", - Scopes: vendor.Scopes, + RedirectURL: "", + Scopes: vendor.Scopes, } } diff --git a/ui/controllers/actions.go b/ui/controllers/actions.go index 127121e..4d591eb 100644 --- a/ui/controllers/actions.go +++ b/ui/controllers/actions.go @@ -42,13 +42,13 @@ func AddActionFromForm(c *gin.Context) { // am := &models.ActionMapping{ - UserId: user.Id, - SourceEvent: &models.Event{ + UserId: user.Id, + SourceEvent: &models.Event{ VendorName: source[0], Key: source[1], Fields: map[string]string{}, }, - Action: &models.Action{ + Action: &models.Action{ VendorName: action[0], Type: action[1], Fields: map[string]string{}, diff --git a/ui/controllers/auth.go b/ui/controllers/auth.go index f7938c6..ed83a9d 100644 --- a/ui/controllers/auth.go +++ b/ui/controllers/auth.go @@ -146,7 +146,6 @@ func LoginHandler(c *gin.Context) { return } - if user == nil { log.Warnf("No user was found for: %s", reqBody.Email) renderTempl(c, templates.LoginPage(fmt.Sprintf("No user found for %s", reqBody.Email))) diff --git a/ui/controllers/pages.go b/ui/controllers/pages.go index 481ea50..bc06228 100644 --- a/ui/controllers/pages.go +++ b/ui/controllers/pages.go @@ -46,12 +46,12 @@ func DashboardPage(c *gin.Context) { waitGroup := new(sync.WaitGroup) waitGroup.Add(2) - go func(wg *sync.WaitGroup){ + go func(wg *sync.WaitGroup) { vendors, errs[0] = mongo.FindAllVendorAccountsByUser(user.MongoId()) wg.Done() }(waitGroup) - go func(wg *sync.WaitGroup){ + go func(wg *sync.WaitGroup) { actions, errs[1] = mongo.FindActionMappingsByUser(user.MongoId()) wg.Done() }(waitGroup) @@ -68,6 +68,5 @@ func DashboardPage(c *gin.Context) { } } - renderTempl(c, templates.DashboardPage(user, vendors, actions)) } diff --git a/ui/controllers/pco.go b/ui/controllers/pco.go index f9e30e8..6d5c921 100644 --- a/ui/controllers/pco.go +++ b/ui/controllers/pco.go @@ -94,7 +94,7 @@ func RecievePCOOuath(c *gin.Context) { } if resp.StatusCode != 200 { - log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode ,string(rawBody)) + log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode, string(rawBody)) c.AbortWithStatus(502) return } diff --git a/ui/controllers/youtube.go b/ui/controllers/youtube.go index 8d895c3..8e63bb1 100644 --- a/ui/controllers/youtube.go +++ b/ui/controllers/youtube.go @@ -106,12 +106,11 @@ func ReceiveYoutubeOauth(c *gin.Context) { } if resp.StatusCode != 200 { - log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode ,string(rawBody)) + log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode, string(rawBody)) c.AbortWithStatus(502) return } - oauthResp := &models.OauthCredential{} err = json.Unmarshal(rawBody, oauthResp) if err != nil { diff --git a/ui/db/db.go b/ui/db/db.go index 0bcf923..c9d54c6 100644 --- a/ui/db/db.go +++ b/ui/db/db.go @@ -11,7 +11,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -//Interface for any object that wants to take advantage of the DB package +// Interface for any object that wants to take advantage of the DB package type Model interface { //Should return the _id field of the object if it exits @@ -35,7 +35,7 @@ func NewClient(uri string) (*DB, error) { return &DB{client: client}, nil } -//Upserts +// Upserts func (db *DB) SaveModel(m Model) error { conf := config.Config() @@ -81,7 +81,7 @@ func (db *DB) SaveModels(m ...Model) error { return nil } -//Doesn't upsert +// Doesn't upsert func (db *DB) InsertModel(m Model) error { conf := config.Config() diff --git a/ui/db/models/actions.go b/ui/db/models/actions.go index d6281e7..01bb176 100644 --- a/ui/db/models/actions.go +++ b/ui/db/models/actions.go @@ -25,8 +25,8 @@ type Action struct { } type Event struct { - VendorName string `bson:"vendor_name,omitempty"` - Key string `bson:"key,omitempty"` + VendorName string `bson:"vendor_name,omitempty"` + Key string `bson:"key,omitempty"` Fields map[string]string `bson:"fields,omitempty"` } diff --git a/ui/db/models/user.go b/ui/db/models/user.go index f21469f..c3baf18 100644 --- a/ui/db/models/user.go +++ b/ui/db/models/user.go @@ -10,7 +10,7 @@ const USER_TYPE string = "user" type User struct { *CommonFields `bson:"obj_info"` - Id primitive.ObjectID `bson:"_id"` + Id primitive.ObjectID `bson:"_id"` Email string `bson:"email,omitempty"` PassowrdHash string `bson:"password_hash,omitempty"` } diff --git a/ui/db/models/vendor.go b/ui/db/models/vendor.go index 869467d..762d8ee 100644 --- a/ui/db/models/vendor.go +++ b/ui/db/models/vendor.go @@ -50,5 +50,3 @@ func (va *VendorAccount) Token() *oauth2.Token { Expiry: va.OauthCredentials.ExpiresAt, } } - - diff --git a/ui/db/token_source.go b/ui/db/token_source.go index c295fe7..c4b54aa 100644 --- a/ui/db/token_source.go +++ b/ui/db/token_source.go @@ -90,10 +90,10 @@ func (ts *VendorTokenSource) Token() (*oauth2.Token, error) { return token, nil } -//Allow us to check for kind of error at the end +// Allow us to check for kind of error at the end var TokenWaitExpired error = errors.New("Waiting for token to refresh took too long") -//Used to extract the token lock that was updated when the change stream alerts +// Used to extract the token lock that was updated when the change stream alerts type tokenLockChangeEvent struct { TokenLock *models.TokenLock `bson:"fullDocument"` } @@ -115,7 +115,7 @@ func (ts *VendorTokenSource) waitForToken(tl *models.TokenLock) error { }, opts) if err != nil { - return err + return err } defer changeStream.Close(context.Background()) diff --git a/ui/db/token_source_test.go b/ui/db/token_source_test.go index 3208235..b820144 100644 --- a/ui/db/token_source_test.go +++ b/ui/db/token_source_test.go @@ -74,7 +74,7 @@ func TestRefreshToken(t *testing.T) { wg := new(sync.WaitGroup) wg.Add(2) - go func(tkr oauth2.TokenSource, wg *sync.WaitGroup){ + go func(tkr oauth2.TokenSource, wg *sync.WaitGroup) { defer wg.Done() var err error tk1, err = tkr.Token() @@ -84,7 +84,7 @@ func TestRefreshToken(t *testing.T) { } }(tkr1, wg) - go func(tkr oauth2.TokenSource, wg *sync.WaitGroup){ + go func(tkr oauth2.TokenSource, wg *sync.WaitGroup) { defer wg.Done() var err error tk2, err = tkr.Token() @@ -92,7 +92,7 @@ func TestRefreshToken(t *testing.T) { t.Errorf("got err = %v; want none", err) return } - }(tkr2,wg) + }(tkr2, wg) wg.Wait() diff --git a/ui/db/user.go b/ui/db/user.go index fc804f8..b32b432 100644 --- a/ui/db/user.go +++ b/ui/db/user.go @@ -11,7 +11,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -//seraches for a single user by email address +// seraches for a single user by email address func (db *DB) FindUserByEmail(email string) (*models.User, error) { conf := config.Config() @@ -34,7 +34,7 @@ func (db *DB) FindUserByEmail(email string) (*models.User, error) { return user, nil } -//find user by its unique id +// find user by its unique id func (db *DB) FindUserById(id string) (*models.User, error) { conf := config.Config() @@ -44,7 +44,7 @@ func (db *DB) FindUserById(id string) (*models.User, error) { return nil, err } - res := db.client.Database(conf.Mongo.EntDb).Collection(conf.Mongo.EntCol).FindOne(context.Background(), bson.M{"_id": objId , "obj_info.ent": models.USER_TYPE}, opts) + res := db.client.Database(conf.Mongo.EntDb).Collection(conf.Mongo.EntCol).FindOne(context.Background(), bson.M{"_id": objId, "obj_info.ent": models.USER_TYPE}, opts) if res.Err() != nil { if res.Err() == mongo.ErrNoDocuments { @@ -62,7 +62,7 @@ func (db *DB) FindUserById(id string) (*models.User, error) { return user, nil } -//returns all users +// returns all users func (db *DB) FindAllUsers() ([]models.User, error) { conf := config.Config() diff --git a/ui/db/vendors.go b/ui/db/vendors.go index f63f605..bc6d7d9 100644 --- a/ui/db/vendors.go +++ b/ui/db/vendors.go @@ -11,7 +11,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -//return all vendor accounts for a user +// return all vendor accounts for a user func (db *DB) FindAllVendorAccountsByUser(userId primitive.ObjectID) ([]models.VendorAccount, error) { conf := config.Config() @@ -33,7 +33,7 @@ func (db *DB) FindAllVendorAccountsByUser(userId primitive.ObjectID) ([]models.V return vendors, nil } -//find vendor for user by name +// find vendor for user by name func (db *DB) FindVendorAccountByUser(userId primitive.ObjectID, name string) (*models.VendorAccount, error) { conf := config.Config() @@ -55,7 +55,7 @@ func (db *DB) FindVendorAccountByUser(userId primitive.ObjectID, name string) (* return vendor, nil } -//find vendoraccount by its unique id +// find vendoraccount by its unique id func (db *DB) FindVendorAccountById(vendorId primitive.ObjectID) (*models.VendorAccount, error) { conf := config.Config()