From 460c684caa26dc53bd6d6185b405a8e0e5bd1276 Mon Sep 17 00:00:00 2001 From: Valley Date: Sun, 10 Jul 2022 14:13:44 +0800 Subject: [PATCH] [#47] fixed some doc and code inconsistencies and removed some redundant parentheses --- apis/base.go | 4 ++-- apis/middlewares.go | 6 +++--- core/settings.go | 8 ++++---- daos/admin.go | 2 +- forms/user_email_change_request.go | 2 +- models/base.go | 4 ++-- models/record.go | 4 ++-- tools/auth/auth.go | 2 +- tools/list/list.go | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apis/base.go b/apis/base.go index c09f4f75..34a59ef2 100644 --- a/apis/base.go +++ b/apis/base.go @@ -38,13 +38,13 @@ func InitApi(app core.App) (*echo.Echo, error) { var apiErr *rest.ApiError switch v := err.(type) { - case (*echo.HTTPError): + case *echo.HTTPError: if v.Internal != nil && app.IsDebug() { log.Println(v.Internal) } msg := fmt.Sprintf("%v", v.Message) apiErr = rest.NewApiError(v.Code, msg, v) - case (*rest.ApiError): + case *rest.ApiError: if app.IsDebug() && v.RawData() != nil { log.Println(v.RawData()) } diff --git a/apis/middlewares.go b/apis/middlewares.go index abf18e4d..7b164c6c 100644 --- a/apis/middlewares.go +++ b/apis/middlewares.go @@ -204,11 +204,11 @@ func ActivityLogger(app core.App) echo.MiddlewareFunc { if err != nil { switch v := err.(type) { - case (*echo.HTTPError): + case *echo.HTTPError: status = v.Code meta["errorMessage"] = v.Message meta["errorDetails"] = fmt.Sprint(v.Internal) - case (*rest.ApiError): + case *rest.ApiError: status = v.Code meta["errorMessage"] = v.Message meta["errorDetails"] = fmt.Sprint(v.RawData()) @@ -259,7 +259,7 @@ func ActivityLogger(app core.App) echo.MiddlewareFunc { // --- now := time.Now() lastLogsDeletedAt := cast.ToTime(app.Cache().Get("lastLogsDeletedAt")) - daysDiff := (now.Sub(lastLogsDeletedAt).Hours() * 24) + daysDiff := now.Sub(lastLogsDeletedAt).Hours() * 24 if daysDiff > float64(app.Settings().Logs.MaxDays) { deleteErr := app.LogsDao().DeleteOldRequests(now.AddDate(0, 0, -1*app.Settings().Logs.MaxDays)) diff --git a/core/settings.go b/core/settings.go index 648664fa..e29f2bd3 100644 --- a/core/settings.go +++ b/core/settings.go @@ -148,12 +148,12 @@ func (s *Settings) Merge(other *Settings) error { } // Clone creates a new deep copy of the current settings. -func (c *Settings) Clone() (*Settings, error) { - new := &Settings{} - if err := new.Merge(c); err != nil { +func (s *Settings) Clone() (*Settings, error) { + settings := &Settings{} + if err := settings.Merge(s); err != nil { return nil, err } - return new, nil + return settings, nil } // RedactClone creates a new deep copy of the current settings, diff --git a/daos/admin.go b/daos/admin.go index 13b196df..86ad77ac 100644 --- a/daos/admin.go +++ b/daos/admin.go @@ -45,7 +45,7 @@ func (dao *Dao) FindAdminByEmail(email string) (*models.Admin, error) { return model, nil } -// FindAdminByEmail finds the admin associated with the provided JWT token. +// FindAdminByToken finds the admin associated with the provided JWT token. // // Returns an error if the JWT token is invalid or expired. func (dao *Dao) FindAdminByToken(token string, baseTokenKey string) (*models.Admin, error) { diff --git a/forms/user_email_change_request.go b/forms/user_email_change_request.go index 3a02043f..8e27b045 100644 --- a/forms/user_email_change_request.go +++ b/forms/user_email_change_request.go @@ -8,7 +8,7 @@ import ( "github.com/pocketbase/pocketbase/models" ) -// UserEmailChangeConfirm defines a user email change request form. +// UserEmailChangeRequest defines a user email change request form. type UserEmailChangeRequest struct { app core.App user *models.User diff --git a/models/base.go b/models/base.go index 9c94e15a..eb20529e 100644 --- a/models/base.go +++ b/models/base.go @@ -53,7 +53,7 @@ func (m *BaseModel) GetCreated() types.DateTime { return m.Created } -// GetCreated returns the model's Updated datetime. +// GetUpdated returns the model's Updated datetime. func (m *BaseModel) GetUpdated() types.DateTime { return m.Updated } @@ -71,7 +71,7 @@ func (m *BaseModel) RefreshCreated() { m.Created = types.NowDateTime() } -// RefreshCreated updates the model's Created field with the current datetime. +// RefreshUpdated updates the model's Created field with the current datetime. func (m *BaseModel) RefreshUpdated() { m.Updated = types.NowDateTime() } diff --git a/models/record.go b/models/record.go index 9d68eaed..e24f6981 100644 --- a/models/record.go +++ b/models/record.go @@ -77,12 +77,12 @@ func NewRecordsFromNullStringMaps(collection *Collection, rows []dbx.NullStringM return result } -// Returns the table name associated to the current Record model. +// TableName returns the table name associated to the current Record model. func (m *Record) TableName() string { return m.collection.Name } -// Returns the Collection model associated to the current Record model. +// Collection returns the Collection model associated to the current Record model. func (m *Record) Collection() *Collection { return m.collection } diff --git a/tools/auth/auth.go b/tools/auth/auth.go index 3b7b763b..25ace1d7 100644 --- a/tools/auth/auth.go +++ b/tools/auth/auth.go @@ -29,7 +29,7 @@ type Provider interface { // SetClientId sets the provider client's ID. SetClientId(clientId string) - // ClientId returns the provider client's app secret. + // ClientSecret returns the provider client's app secret. ClientSecret() string // SetClientSecret sets the provider client's app secret. diff --git a/tools/list/list.go b/tools/list/list.go index 008b2730..39994a07 100644 --- a/tools/list/list.go +++ b/tools/list/list.go @@ -10,7 +10,7 @@ import ( var cachedPatterns = map[string]*regexp.Regexp{} -// ExustInSlice checks whether a comparable element exists in a slice of the same type. +// ExistInSlice checks whether a comparable element exists in a slice of the same type. func ExistInSlice[T comparable](item T, list []T) bool { if len(list) == 0 { return false