util

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorDelimiter string = "---"

Variables

View Source
var GetRefreshTokenLimit = func() uint {
	return jwtCfg.RefreshTokenLimit
}
View Source
var NewOauthProvider func(provider OauthProvider) OauthInterface = newOauthProvider

Functions

func IsDatabaseError

func IsDatabaseError(db *gorm.DB) bool

func IssueAccessToken

func IssueAccessToken(subject any) string

func IssueJwtWithConfig

func IssueJwtWithConfig(claims jwt.Claims) string

func IssueRefreshToken

func IssueRefreshToken(subject any) string

func MakeArgon2IdHash

func MakeArgon2IdHash(password string) string

func MakeArgon2IdHashWithConfig

func MakeArgon2IdHashWithConfig(password string, config *Argon2IdConfig) string

func NewRateLimiter

func NewRateLimiter() *rate.Limiter

func RandomString

func RandomString(n int) string

func Stack

func Stack(skip int) string

func Stacktrace

func Stacktrace(skip int) []byte

func VerifyArgon2IdHash

func VerifyArgon2IdHash(password string, encodedHash string) bool

func VerifyJwt

func VerifyJwt(tokenString string) (*jwt.Token, error)

func WrapError

func WrapError(err error) error

Types

type Argon2IdConfig

type Argon2IdConfig struct {
	Memory  uint32
	Time    uint32
	Threads uint8
	KeyLen  uint32
	SaltLen uint32
}

type GoogleOauth

type GoogleOauth struct {
	Token *oauth2.Token
	Id    string
	Email string
}

func (*GoogleOauth) GetAccessToken

func (googleOauth *GoogleOauth) GetAccessToken(code string) error

func (*GoogleOauth) SetIdAndEmail

func (googleOauth *GoogleOauth) SetIdAndEmail() error

type OauthInterface

type OauthInterface interface {
	GetAccessToken(code string) error
	SetIdAndEmail() error
}

type OauthProvider

type OauthProvider string
const (
	Google OauthProvider = "google"
)

type PaginationRequest

type PaginationRequest struct {
	Page    int    `form:"page" mod:"default=1" validate:"omitempty,min=1"`
	PerPage int    `form:"per_page" mod:"default=10" validate:"omitempty,min=1"`
	OrderBy string `form:"order_by" validate:"omitempty"`
}

type PaginationResponse

type PaginationResponse struct {
	Page     int   `json:"page,omitempty"`
	PerPage  int   `json:"per_page,omitempty"`
	LastPage uint  `json:"last_page,omitempty"`
	Total    int64 `json:"total,omitempty"`
}

type Paginator

type Paginator struct {
	Page     int
	PerPage  int
	Total    int64
	LastPage uint
	// contains filtered or unexported fields
}

func NewPaginator

func NewPaginator(
	db *gorm.DB,
	whereConditions WhereCondition,
	orders map[string]string,
) Paginator

func (*Paginator) AddWhereConditions

func (p *Paginator) AddWhereConditions(filter reflect.Value) *Paginator

func (*Paginator) CalculateTotalAndLastPage

func (p *Paginator) CalculateTotalAndLastPage() *Paginator

func (*Paginator) GetData

func (p *Paginator) GetData(data any, query any, args ...any) *Paginator

func (*Paginator) SetOrderBy

func (p *Paginator) SetOrderBy(orderBy string) *Paginator

func (*Paginator) SetPagination

func (p *Paginator) SetPagination(page int, perPage int) *Paginator

type TimeForJson

type TimeForJson time.Time

func (*TimeForJson) MarshalJSON

func (t *TimeForJson) MarshalJSON() ([]byte, error)

func (*TimeForJson) UnmarshalJSON

func (t *TimeForJson) UnmarshalJSON(b []byte) error

type WhereCondition

type WhereCondition map[string]func(db *gorm.DB, value any)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL