utils

package
v0.0.0-...-79683fd Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 15 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cookies = cookies{
	Login: "login",
}

Cookies is cookie name enum

View Source
var CtxKeys = ctxKeys{
	UserID:      "userID",
	Log:         "Log",
	RequestID:   "requestID",
	RequestType: "requestType",
}

CtxKeys is context value keys

Functions

func BoolToString

func BoolToString(b bool) string

func CapitalizeASCII

func CapitalizeASCII(s string) string

func FileExists

func FileExists(name string) bool

func FormatAvatarURL

func FormatAvatarURL(uid int64, avatar string) string

func FormatLike

func FormatLike(s string) string

func GetMemStats

func GetMemStats() *runtime.MemStats

func GetURL

func GetURL(url string) ([]byte, error)

func Int64Ptr

func Int64Ptr(n int64) *int64

func LogCtx

func LogCtx(ctx context.Context) *logrus.Entry

LogCtx returns logger with certain context values included

func NewBucketLimiter

func NewBucketLimiter(d time.Duration, capacity int) (chan bool, *time.Ticker)

NewBucketLimiter creates a ticker channel that fills a bucket with one token every d and has a given capacity for burst usage

func NilTime

func NilTime(t *time.Time) time.Time

func RequestID

func RequestID(ctx context.Context) string

RequestID extracts requestID from context

func RequestType

func RequestType(ctx context.Context) string

RequestType extracts requestID from context

func SizeToString

func SizeToString(size int64) string

Convert size in bytes (123456789B) to a human readable string (Extensions B through EB)

func SplitMultilineText

func SplitMultilineText(s *string) []string

func StrPtr

func StrPtr(s string) *string

func Unpointify

func Unpointify(s *string) string

Unpointify is for template

func UnsetCookie

func UnsetCookie(w http.ResponseWriter, name string)

UnsetCookie unsets cookie

func UploadMultipartFile

func UploadMultipartFile(ctx context.Context, url string, f io.Reader, filename string) ([]byte, error)

func UserID

func UserID(ctx context.Context) int64

UserID extracts userID from context

func WriteTarball

func WriteTarball(w io.Writer, filePaths []string) error

Types

type CookieCutter

type CookieCutter struct {
	Previous *securecookie.SecureCookie
	Current  *securecookie.SecureCookie
}

CookieCutter is the cookie handler

func (*CookieCutter) GetSecureCookie

func (cc *CookieCutter) GetSecureCookie(r *http.Request, name string) (map[string]string, error)

GetSecureCookie gets cookie

func (*CookieCutter) SetSecureCookie

func (cc *CookieCutter) SetSecureCookie(w http.ResponseWriter, name string, value map[string]string, maxAge int) error

SetSecureCookie sets cookie

type RandomStringer

type RandomStringer interface {
	RandomString(n int) string
}

type RealRandomString

type RealRandomString struct {
	// contains filtered or unexported fields
}

func NewRealRandomStringProvider

func NewRealRandomStringProvider() *RealRandomString

func (*RealRandomString) RandomString

func (r *RealRandomString) RandomString(n int) string

type ValueOnlyContext

type ValueOnlyContext struct {
	context.Context
}

func (ValueOnlyContext) Deadline

func (ValueOnlyContext) Deadline() (deadline time.Time, ok bool)

func (ValueOnlyContext) Done

func (ValueOnlyContext) Done() <-chan struct{}

func (ValueOnlyContext) Err

func (ValueOnlyContext) Err() error

Jump to

Keyboard shortcuts

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