common

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseUrlName         = "BaseUrl"
	RedirectName        = "Redirect"
	AllowedToCreateName = "AllowedToCreate"
	AllowedToUpdateName = "AllowedToUpdate"
	AllowedToDeleteName = "AllowedToDelete"
)
View Source
const (
	UserIdName     = "Id" // current connected user id
	ViewedUserName = "ViewedUser"
	UrlName        = "CurrentUrl"
	SessionName    = "Session"
)
View Source
const (
	ErrorBadRoleNameKey          = "ErrorBadRoleName"
	ErrorBaseVersionKey          = "BaseVersionOutdated"
	ErrorEmptyCommentKey         = "EmptyComment"
	ErrorEmptyLoginKey           = "EmptyLogin"
	ErrorEmptyPasswordKey        = "EmptyPassword"
	ErrorExistingLoginKey        = "ExistingLogin"
	ErrorNotAuthorizedKey        = "ErrorNotAuthorized"
	ErrorTechnicalKey            = "ErrorTechnicalProblem"
	ErrorUpdateKey               = "ErrorUpdate"
	ErrorWeakPasswordKey         = "WeakPassword"
	ErrorWrongConfirmPasswordKey = "WrongConfirmPassword"
	ErrorWrongLangKey            = "WrongLang"
	ErrorWrongLoginKey           = "WrongLogin"
)

error displayed to user

View Source
const ErrorKey = "error"
View Source
const QueryError = "?" + ErrorKey + "="

Variables

View Source
var (
	ErrBadRoleName   = errors.New(ErrorBadRoleNameKey)
	ErrBaseVersion   = errors.New(ErrorBaseVersionKey)
	ErrEmptyComment  = errors.New(ErrorEmptyCommentKey)
	ErrEmptyLogin    = errors.New(ErrorEmptyLoginKey)
	ErrEmptyPassword = errors.New(ErrorEmptyPasswordKey)
	ErrExistingLogin = errors.New(ErrorExistingLoginKey)
	ErrNotAuthorized = errors.New(ErrorNotAuthorizedKey)
	ErrTechnical     = errors.New(ErrorTechnicalKey)
	ErrUpdate        = errors.New(ErrorUpdateKey)
	ErrWeakPassword  = errors.New(ErrorWeakPasswordKey)
	ErrWrongConfirm  = errors.New(ErrorWrongConfirmPasswordKey)
	ErrWrongLogin    = errors.New(ErrorWrongLoginKey)
)

Functions

func CheckPort

func CheckPort(port string) string

func CreateRedirect

func CreateRedirect(redirecter Redirecter) gin.HandlerFunc

func CreateRedirectString

func CreateRedirectString(target string) gin.HandlerFunc

func DefaultErrorRedirect

func DefaultErrorRedirect(logger *slog.Logger, errorMsg string) string

func FilterErrorMsg

func FilterErrorMsg(logger *slog.Logger, errorMsg string) string

func FilterExtractHtml

func FilterExtractHtml(html string, extractSize uint64) string

html must be well formed

func GetBaseUrl

func GetBaseUrl(levelToErase uint8, c *gin.Context) string

func GetCurrentUrl

func GetCurrentUrl(c *gin.Context) string

func GetPagination

func GetPagination(defaultPageSize uint64, c *gin.Context) (uint64, uint64, uint64, string)

func InitPagination

func InitPagination(data gin.H, filter string, pageNumber uint64, end uint64, total uint64)

func LogOriginalError

func LogOriginalError(logger *slog.Logger, err error)

func MapToValueSlice

func MapToValueSlice[K comparable, V any](objects map[K]V) []V

func WriteError

func WriteError(urlBuilder *strings.Builder, logger *slog.Logger, errorMsg string)

Types

type DataAdder

type DataAdder func(gin.H, *gin.Context)

type LoggerGetter

type LoggerGetter interface {
	Logger(context.Context) *slog.Logger
}

type Redirecter

type Redirecter func(*gin.Context) string

type Set

type Set[V comparable] map[V]empty

func MakeSet

func MakeSet[V comparable](values []V) Set[V]

func (Set[V]) Add

func (s Set[V]) Add(value V)

func (Set[V]) Contains

func (s Set[V]) Contains(value V) bool

func (Set[V]) Remove

func (s Set[V]) Remove(value V)

func (Set[V]) Slice

func (s Set[V]) Slice() []V

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any]() *Stack[T]

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

func (*Stack[T]) Push

func (s *Stack[T]) Push(e T)

type TemplateRedirecter

type TemplateRedirecter func(gin.H, *gin.Context) (string, string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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