utils

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = fmt.Errorf("no token provided")
View Source
var ErrUnauthorized = fmt.Errorf("unauthorized")

Functions

func ExtractFirstNumber

func ExtractFirstNumber(input []byte) (int32, int, error)

func GenerateSecrets

func GenerateSecrets(length int) (string, error)

func GenerateTokens

func GenerateTokens(username string, tokenSecret string, refreshTokenSecret string, tokenDuration time.Duration, refreshTokenDuration time.Duration) (string, string, error)

func GetEnv

func GetEnv(key, defaultValue string) string

func HTTPGet

func HTTPGet(url string, queryParams map[string]string, timeout time.Duration, logger logger.Logger) (*http.Response, error)

func HTTPPost added in v0.2.1

func HTTPPost(url string, body []byte, headers map[string]string, ctx context.Context, logger logger.Logger) error

func JoinStrings

func JoinStrings(strs []string, separator string) string

func ParseJSON added in v0.2.1

func ParseJSON(in string, data interface{}) error

func ParseQueryParams

func ParseQueryParams(r *http.Request, inParams ...types.Param) (map[string]string, error)

func ParseRequest

func ParseRequest(r *http.Request, data interface{}) error

func ParseResponse

func ParseResponse(resp *http.Response, data interface{}) error

func ParseTime

func ParseTime(ti string) (time.Time, error)

func RefreshToken

func RefreshToken(tokenString string, secret string, duration time.Duration) (string, error)

func SetCookie

func SetCookie(w http.ResponseWriter, name string, value string, expires time.Duration, httpOnly bool)

func SplitString

func SplitString(str string, separator rune) []string

func ValidateToken

func ValidateToken(tokenString string, secret string, username string) (bool, error)

func WriteError

func WriteError(w http.ResponseWriter, status int, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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