util

package
v0.0.0-...-2551f53 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const KeyRequester = "requester"

Variables

View Source
var ErrBadRequest = DefaultError{
	StatusField: http.StatusText(http.StatusBadRequest),
	ErrorField:  "The request was invalid or contained malformed parameters",
	CodeField:   http.StatusBadRequest,
}
View Source
var ErrConflict = DefaultError{
	StatusField: http.StatusText(http.StatusConflict),
	ErrorField:  "A conflict occurred with the current state of the resource",
	CodeField:   http.StatusConflict,
}
View Source
var ErrForbidden = DefaultError{
	StatusField: http.StatusText(http.StatusForbidden),
	ErrorField:  "Access to the requested page or resource is forbidden",
	CodeField:   http.StatusForbidden,
}
View Source
var ErrInternalServerError = DefaultError{
	StatusField: http.StatusText(http.StatusInternalServerError),
	ErrorField:  "An internal server error occurred. Please try again later",
	CodeField:   http.StatusInternalServerError,
}
View Source
var ErrNotFound = DefaultError{
	StatusField: http.StatusText(http.StatusNotFound),
	ErrorField:  "The requested page or resource could not be found",
	CodeField:   http.StatusNotFound,
}
View Source
var ErrTimeout = DefaultError{
	StatusField: http.StatusText(http.StatusRequestTimeout),
	ErrorField:  "The request timed out",
	CodeField:   http.StatusRequestTimeout,
}
View Source
var ErrUnauthorized = DefaultError{
	StatusField: http.StatusText(http.StatusUnauthorized),
	ErrorField:  "Access denied. Please authenticate with valid credentials",
	CodeField:   http.StatusUnauthorized,
}
View Source
var ErrUnsupportedMediaType = DefaultError{
	StatusField: http.StatusText(http.StatusUnsupportedMediaType),
	ErrorField:  "The media type of the requested resource is not supported",
	CodeField:   http.StatusUnsupportedMediaType,
}

Functions

func CheckPassword

func CheckPassword(format string, hashedPassword string, args ...interface{}) error

func ContextWithRequester

func ContextWithRequester(ctx context.Context, requester Requester) context.Context

func ConvertWeight

func ConvertWeight(weight float64, from, to constant.WeightUnit) float64

func ErrorResponse

func ErrorResponse(ctx *gin.Context, err error)

func HashPassword

func HashPassword(format string, args ...interface{}) (string, error)

func NewDataResponse

func NewDataResponse(data interface{}) *successResponse

func NewRequester

func NewRequester(uid string) *requesterData

func NewResponse

func NewResponse(data, paging, extra interface{}) *successResponse

func RandomString

func RandomString(length int) (string, error)

func SuccessResponse

func SuccessResponse(ctx *gin.Context, data *successResponse)

Types

type Config

type Config struct {
	ENV                   string        `mapstructure:"ENV"`
	SecretKey             string        `mapstructure:"SECRET_KEY"`
	DBSource              string        `mapstructure:"DB_SOURCE"`
	MigrationURL          string        `mapstructure:"MIGRATION_URL"`
	ServerAddress         string        `mapstructure:"SERVER_ADDRESS"`
	AccessTokenExpiresIn  time.Duration `mapstructure:"ACCESS_TOKEN_EXPIRES_IN"`
	RefreshTokenExpiresIn time.Duration `mapstructure:"REFRESH_TOKEN_EXPIRES_IN"`
}

func LoadConfig

func LoadConfig(path string) (config Config, err error)

type DefaultError

type DefaultError struct {
	StatusField string `json:"status,omitempty"`
	CodeField   int    `json:"code,omitempty"`
	ErrorField  string `json:"message"`
	DebugField  string `json:"debug,omitempty"`
}

func (DefaultError) Error

func (e DefaultError) Error() string

func (DefaultError) Is

func (e DefaultError) Is(err error) bool

func (DefaultError) StatusCode

func (e DefaultError) StatusCode() int

func (DefaultError) WithDebug

func (e DefaultError) WithDebug(debug string) *DefaultError

func (DefaultError) WithError

func (e DefaultError) WithError(message string) *DefaultError

type Requester

type Requester interface {
	GetUID() string
}

func GetRequester

func GetRequester(ctx context.Context) Requester

type StatusCodeCarrier

type StatusCodeCarrier interface {
	StatusCode() int
}

Jump to

Keyboard shortcuts

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