utils

package
v0.0.0-...-74a3d09 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReserveRequestRoutes = []string{
		"/api-nebula/db/",
		"/api/files",
		"/api/import-tasks",
	}
	ReserveResponseRoutes = []string{
		"/api-nebula/db/",
		"/api/import-tasks",
	}
	IgnoreHandlerBodyPatterns = []*regexp.Regexp{
		regexp.MustCompile(`^/api/import-tasks/\w+/download`),
	}
)

Functions

func AddQueryParams

func AddQueryParams(r *http.Request, params map[string]string)

dynamicly add query params to the request

func Contains

func Contains[T comparable](s []T, e T) bool

func CopyHttpRequest

func CopyHttpRequest(r *http.Request) *http.Request

func CreateDir

func CreateDir(dir string) error

func Decrypt

func Decrypt(encoded string, key []byte) ([]byte, error)

Decrypt decrypts a base64-encoded ciphertext using AES encryption with a given key. It returns the plaintext.

func DisabledCookie

func DisabledCookie(name string, httpsEnable bool) *http.Cookie

func Encrypt

func Encrypt(plaintext, key []byte) (string, error)

Encrypt encrypts plaintext using AES encryption with a given key. It returns a base64-encoded ciphertext.

func GormErrorWithLogger

func GormErrorWithLogger(ctx context.Context) func(err error, formatWithArgs ...interface{}) error

func NewMutexMap

func NewMutexMap[T any]() *mutexMap[T]

func Paginate

func Paginate(page int64, pageSize int64) func(db *gorm.DB) *gorm.DB

func ParseEndpoint

func ParseEndpoint(platform, rawEndpoint string) (string, string, error)

func PathHasPrefix

func PathHasPrefix(path string, routes []string) bool

func PathMatchPattern

func PathMatchPattern(path string, patterns []*regexp.Regexp) bool

func ReadPartFile

func ReadPartFile(path string) ([]string, error)

read part of file: top 50 lines and bottom 50 lines

Types

type GormErrorWrapper

type GormErrorWrapper func(err error, formatWithArgs ...interface{}) error

type WithErrorMessage

type WithErrorMessage func(c *errorx.ErrCode, err error, formatWithArgs ...interface{}) error

func ErrMsgWithLogger

func ErrMsgWithLogger(ctx context.Context) WithErrorMessage

Jump to

Keyboard shortcuts

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