utils

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayIn

func ArrayIn[T comparable](val T, array []T) (exists bool, index int)

func Color

func Color(str string) string

func Colorf

func Colorf(format string, a ...any) string

func CreateJPGImage

func CreateJPGImage(img *image.RGBA, quality int) ([]byte, error)

func CreatePNGImage

func CreatePNGImage(img *image.RGBA) ([]byte, error)

func CreatePNGImageURI

func CreatePNGImageURI(img *image.RGBA) (string, error)

func GenerateUID

func GenerateUID(alphabet string, size int) (string, error)

GenerateUID is a low-level function to change alphabet and ID size.

func HttpJsonRequest

func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res any) error

func HttpJsonResponse

func HttpJsonResponse(w http.ResponseWriter, code int, res any)

func HttpRequestGET

func HttpRequestGET(url string) (string, error)

func HttpSuccess

func HttpSuccess(w http.ResponseWriter, res ...any) error

func JsonStringAutoDecode

func JsonStringAutoDecode(m any) func(rf reflect.Kind, rt reflect.Kind, data any) (any, error)

func NewUID

func NewUID(param ...int) (string, error)

NewUID generates secure URL-friendly unique ID.

func Unmarshal

func Unmarshal(in any, raw []byte, callback func() error) error

func Unzip

func Unzip(zipPath, target string) error

func Zip

func Zip(source, zipPath string) error

Types

type Generator

type Generator func([]byte) (int, error)

Generator function

var BytesGenerator Generator = rand.Read

BytesGenerator is the default bytes generator

type HTTPError

type HTTPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`

	InternalErr error  `json:"-"`
	InternalMsg string `json:"-"`
}

HTTPError is an error with a message and an HTTP status code.

func HttpBadRequest

func HttpBadRequest(res ...string) *HTTPError

func HttpError

func HttpError(code int, res ...string) *HTTPError

func HttpForbidden

func HttpForbidden(res ...string) *HTTPError

func HttpInternalServerError

func HttpInternalServerError(res ...string) *HTTPError

func HttpNotFound

func HttpNotFound(res ...string) *HTTPError

func HttpUnauthorized

func HttpUnauthorized(res ...string) *HTTPError

func HttpUnprocessableEntity

func HttpUnprocessableEntity(res ...string) *HTTPError

func (*HTTPError) Cause

func (e *HTTPError) Cause() error

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Msg

func (e *HTTPError) Msg(str string) *HTTPError

Sends error with custom message

func (*HTTPError) Msgf

func (e *HTTPError) Msgf(fmtSt string, args ...any) *HTTPError

Sends error with custom formated message

func (*HTTPError) WithInternalErr

func (e *HTTPError) WithInternalErr(err error) *HTTPError

WithInternalErr adds internal error information to the error

func (*HTTPError) WithInternalMsg

func (e *HTTPError) WithInternalMsg(msg string) *HTTPError

WithInternalMsg adds internal message information to the error

func (*HTTPError) WithInternalMsgf

func (e *HTTPError) WithInternalMsgf(fmtStr string, args ...any) *HTTPError

WithInternalMsg adds internal formated message information to the error

Jump to

Keyboard shortcuts

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