ncode

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 13 Imported by: 0

README

encoding

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugJsonRequests = true
View Source
var ErrSkip = errors.New("skip error")
View Source
var ErrZeroLength = fmt.Errorf("cannot decode zero length")

ErrZeroLength 404 not found

View Source
var Json = toJson

Functions

func B2N

func B2N(b []byte) uint64

B2N []byte to number

func DecodeJson

func DecodeJson[T any](b []byte) (T, error)

func DecodeJsonReader

func DecodeJsonReader[T any](rdr io.Reader) (T, error)

DecodeJsonReader does not close reader. set `DebugJsonRequests = true` for debug logging

func DecodeRequestBody

func DecodeRequestBody[T any](w http.ResponseWriter, r *http.Request) (T, error)

DecodeRequestBody (and close body)

func JsonIndent

func JsonIndent(a any) []byte

eg: ncode.Json = ncode.JsonIndent

func JsonString

func JsonString(a any) string

func N2B

func N2B[E constraints.Unsigned](n E) []byte

N2B Number to []byte

func ParseBase

func ParseBase[T constraints.Unsigned](in string, base int) (T, error)

ParseBase string->~uint

func ParseNumber

func ParseNumber[T constraints.Unsigned](in string) (T, error)

ParseNumber string->~uint

func Twist

func Twist[T ~string](a []string) []T

Twist strings into things, O(n)

func TwistAny

func TwistAny[T any, K any](a []T, fn func(v T) K) []K

TwistAny array into another kind of array

func TwistAnyWithError

func TwistAnyWithError[T any, K any](a []K, fn func(s K) (T, error)) ([]T, error)

TwistAnyWithError in case theres a parsing issue. skip elements (but continue indexes) by returning ErrSkip in fn function TODO: skip without incrementing index

func TwistBack

func TwistBack[T ~string](a []T) []string

TwistBack things into strings, O(n)

func TwistFormat

func TwistFormat[T any](a []T, fn func(v T) string) []string

TwistFormat array into a string array

func TwistParse

func TwistParse[T any](a []string, fn func(s string) (T, error)) ([]T, error)

TwistParse strings into any things (with error handling) skip elements (but continue indexes) by returning ErrSkip in fn function TODO: skip without incrementing index

Types

This section is empty.

Directories

Path Synopsis
Package constraints defines a set of useful constraints to be used with type parameters.
Package constraints defines a set of useful constraints to be used with type parameters.

Jump to

Keyboard shortcuts

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