helper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolYNToStr

func BoolYNToStr(b bool) string

BoolYNToStr return 'yes' if true otherwise return 'no' instead.

func BytesToStr

func BytesToStr(b []byte) string

BytesToStr zero allocation bytes to string conversion. Because default string([]byte) take allocation so this helper may help with performance improvement but should be used in caution and appropriately.

Caution: Make sure the given b bytes will never change.

Refs:

func Def

func Def[T comparable](t *T) (n T)

Def return the value of given pointer and return the default value of that type instead if nil.

func Default

func Default[T comparable](t T, def ...T) (tt T)

Default return the default value while it's present and t is blank.

func DropBlankSpace

func DropBlankSpace(r rune) rune

DropBlankSpace return -1 if given rune is blank space ' ', this intended to be used in strings.Map to remove any blank space from string.

func ExtractRequest

func ExtractRequest(r *http.Request) map[string]any

ExtractRequest encode given request to json and just return {} if the request body is empty.

func ExtractRequestHeader

func ExtractRequestHeader(r http.Request) map[string]any

ExtractRequestHeader extract header from given request and return it as json encoded string.

func Ptr

func Ptr[T comparable](t T) *T

Ptr return pointer to given t.

func StrToBytes

func StrToBytes(s string) (b []byte)

StrToBytes zero allocation string to bytes conversion. Because default []byte("string") take allocation so this helper may help with performance improvement but should be used in caution and appropriately.

Caution: Make sure the given s string will never change.

Refs:

func StrYNToBool

func StrYNToBool(s string) bool

StrYNToBool return true only if given s is 'yes' otherwise will return false.

func ToSnake

func ToSnake(s string) string

ToSnake converts a string to snake_case

Types

This section is empty.

Jump to

Keyboard shortcuts

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