1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-03 09:57:24 +02:00

[#47] fixed some doc and code inconsistencies and removed some redundant parentheses

This commit is contained in:
Valley 2022-07-10 14:13:44 +08:00 committed by GitHub
parent d64fbf9011
commit 460c684caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 17 deletions

View File

@ -38,13 +38,13 @@ func InitApi(app core.App) (*echo.Echo, error) {
var apiErr *rest.ApiError var apiErr *rest.ApiError
switch v := err.(type) { switch v := err.(type) {
case (*echo.HTTPError): case *echo.HTTPError:
if v.Internal != nil && app.IsDebug() { if v.Internal != nil && app.IsDebug() {
log.Println(v.Internal) log.Println(v.Internal)
} }
msg := fmt.Sprintf("%v", v.Message) msg := fmt.Sprintf("%v", v.Message)
apiErr = rest.NewApiError(v.Code, msg, v) apiErr = rest.NewApiError(v.Code, msg, v)
case (*rest.ApiError): case *rest.ApiError:
if app.IsDebug() && v.RawData() != nil { if app.IsDebug() && v.RawData() != nil {
log.Println(v.RawData()) log.Println(v.RawData())
} }

View File

@ -204,11 +204,11 @@ func ActivityLogger(app core.App) echo.MiddlewareFunc {
if err != nil { if err != nil {
switch v := err.(type) { switch v := err.(type) {
case (*echo.HTTPError): case *echo.HTTPError:
status = v.Code status = v.Code
meta["errorMessage"] = v.Message meta["errorMessage"] = v.Message
meta["errorDetails"] = fmt.Sprint(v.Internal) meta["errorDetails"] = fmt.Sprint(v.Internal)
case (*rest.ApiError): case *rest.ApiError:
status = v.Code status = v.Code
meta["errorMessage"] = v.Message meta["errorMessage"] = v.Message
meta["errorDetails"] = fmt.Sprint(v.RawData()) meta["errorDetails"] = fmt.Sprint(v.RawData())
@ -259,7 +259,7 @@ func ActivityLogger(app core.App) echo.MiddlewareFunc {
// --- // ---
now := time.Now() now := time.Now()
lastLogsDeletedAt := cast.ToTime(app.Cache().Get("lastLogsDeletedAt")) 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) { if daysDiff > float64(app.Settings().Logs.MaxDays) {
deleteErr := app.LogsDao().DeleteOldRequests(now.AddDate(0, 0, -1*app.Settings().Logs.MaxDays)) deleteErr := app.LogsDao().DeleteOldRequests(now.AddDate(0, 0, -1*app.Settings().Logs.MaxDays))

View File

@ -148,12 +148,12 @@ func (s *Settings) Merge(other *Settings) error {
} }
// Clone creates a new deep copy of the current settings. // Clone creates a new deep copy of the current settings.
func (c *Settings) Clone() (*Settings, error) { func (s *Settings) Clone() (*Settings, error) {
new := &Settings{} settings := &Settings{}
if err := new.Merge(c); err != nil { if err := settings.Merge(s); err != nil {
return nil, err return nil, err
} }
return new, nil return settings, nil
} }
// RedactClone creates a new deep copy of the current settings, // RedactClone creates a new deep copy of the current settings,

View File

@ -45,7 +45,7 @@ func (dao *Dao) FindAdminByEmail(email string) (*models.Admin, error) {
return model, nil 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. // Returns an error if the JWT token is invalid or expired.
func (dao *Dao) FindAdminByToken(token string, baseTokenKey string) (*models.Admin, error) { func (dao *Dao) FindAdminByToken(token string, baseTokenKey string) (*models.Admin, error) {

View File

@ -8,7 +8,7 @@ import (
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
) )
// UserEmailChangeConfirm defines a user email change request form. // UserEmailChangeRequest defines a user email change request form.
type UserEmailChangeRequest struct { type UserEmailChangeRequest struct {
app core.App app core.App
user *models.User user *models.User

View File

@ -53,7 +53,7 @@ func (m *BaseModel) GetCreated() types.DateTime {
return m.Created return m.Created
} }
// GetCreated returns the model's Updated datetime. // GetUpdated returns the model's Updated datetime.
func (m *BaseModel) GetUpdated() types.DateTime { func (m *BaseModel) GetUpdated() types.DateTime {
return m.Updated return m.Updated
} }
@ -71,7 +71,7 @@ func (m *BaseModel) RefreshCreated() {
m.Created = types.NowDateTime() 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() { func (m *BaseModel) RefreshUpdated() {
m.Updated = types.NowDateTime() m.Updated = types.NowDateTime()
} }

View File

@ -77,12 +77,12 @@ func NewRecordsFromNullStringMaps(collection *Collection, rows []dbx.NullStringM
return result 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 { func (m *Record) TableName() string {
return m.collection.Name 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 { func (m *Record) Collection() *Collection {
return m.collection return m.collection
} }

View File

@ -29,7 +29,7 @@ type Provider interface {
// SetClientId sets the provider client's ID. // SetClientId sets the provider client's ID.
SetClientId(clientId string) SetClientId(clientId string)
// ClientId returns the provider client's app secret. // ClientSecret returns the provider client's app secret.
ClientSecret() string ClientSecret() string
// SetClientSecret sets the provider client's app secret. // SetClientSecret sets the provider client's app secret.

View File

@ -10,7 +10,7 @@ import (
var cachedPatterns = map[string]*regexp.Regexp{} 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 { func ExistInSlice[T comparable](item T, list []T) bool {
if len(list) == 0 { if len(list) == 0 {
return false return false