tu

package module
v0.0.0-...-2d9b1df Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 7 Imported by: 0

README

Tiny U

Introduction

Tiny U is a data structure and algorithm library for golang.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlnum

func IsAlnum(ch byte) bool

IsAlnum checks if ch character is alphanumeric

func IsAlpha

func IsAlpha(ch byte) bool

IsAlpha checks if ch character is alphabetic

func IsBlank

func IsBlank(ch byte) bool

IsBlank checks if ch character is blank character

func IsCntrl

func IsCntrl(ch byte) bool

IsCntrl checks if ch character is control character

func IsDigit

func IsDigit(ch byte) bool

IsDigit checks if ch character is digit

func IsGraph

func IsGraph(ch byte) bool

IsGraph checks if ch character is graphical character

func IsLower

func IsLower(ch byte) bool

IsLower checks if ch character is lowercase character

func IsPrint

func IsPrint(ch byte) bool

IsPrint checks if ch character is printing character

func IsPunct

func IsPunct(ch byte) bool

IsPunct checks if ch character is punctuation character

func IsSpace

func IsSpace(ch byte) bool

IsSpace checks if ch character is space character

func IsUpper

func IsUpper(ch byte) bool

IsUpper checks if ch character is uppercase character

func IsXdigit

func IsXdigit(ch byte) bool

IsXdigit checks if ch character is hexadecimal character

func ToLower

func ToLower(ch byte) byte

ToLower converts a character to lowercase

func ToUpper

func ToUpper(ch byte) byte

ToUpper converts a character to uppercase

Types

type Context

type Context struct {
	// origin objects
	Response http.ResponseWriter
	Request  *http.Request

	// Request info
	Path   string
	Method string

	// Response info
	StatusCode int
}

func (*Context) AddHeader

func (self *Context) AddHeader(key string, val string)

AddHeader adds the key, value pair to the header. It appends to any existing values associated with key.

func (*Context) HTML

func (self *Context) HTML(code int, html string) error

HTML sends a HTML response

func (*Context) Header

func (self *Context) Header(key string) string

Header gets the first value associated with the given key. If there are no values associated with the key. Get return "".

func (*Context) JSON

func (self *Context) JSON(code int, obj any) error

JSON sends a JSON response

func (*Context) Param

func (self *Context) Param(key string) string

Param method retrieves the parameters from url

func (*Context) Query

func (self *Context) Query(key string) string

Query method retrieves the form data.

func (*Context) Redirect

func (self *Context) Redirect(url string)

Redirect method sets the response as a 302 redirection.

func (*Context) Send

func (self *Context) Send(code int, body any) error

Send the response immediately.

func (*Context) SetHeader

func (self *Context) SetHeader(key string, val string)

SetHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func (*Context) Status

func (self *Context) Status(code int)

Status takes an integer and sets the response statue to the integer given.

type H

type H map[string]any

type HandleFunc

type HandleFunc func(ctx *Context)

type Http

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

func NewHttp

func NewHttp() *Http

func (*Http) Delete

func (self *Http) Delete(path string, handleFunc HandleFunc)

func (*Http) Get

func (self *Http) Get(path string, handleFunc HandleFunc)

func (*Http) Head

func (self *Http) Head(path string, handleFunc HandleFunc)

func (*Http) Options

func (self *Http) Options(path string, handleFunc HandleFunc)

func (*Http) Patch

func (self *Http) Patch(path string, handleFunc HandleFunc)

func (*Http) Post

func (self *Http) Post(path string, handleFunc HandleFunc)

func (*Http) Put

func (self *Http) Put(path string, handleFunc HandleFunc)

func (*Http) Run

func (self *Http) Run(addr string) error

type Tbl

type Tbl[K comparable, V any] map[K]V

Tbl is a generic map-like structure for keys of any comparable type K and values of any type V.

func NewTbl

func NewTbl[K comparable, V any](args ...any) Tbl[K, V]

NewTbl returns Tbl[K, V], There are two calling forms:

NewTbl[K, V]() returns a Tbl[K, V] of length 0.
NewTbl[K, V](map[K, V] | Tbl[K, V]) returns a shallow copy of the given map or Tbl.

func (Tbl[K, V]) Filter

func (self Tbl[K, V]) Filter(fn func(key K, val V) bool) Tbl[K, V]

Filter creates a new Tbl with only the key-value pairs that satisfy the provided function.

func (Tbl[K, V]) FilterMap

func (self Tbl[K, V]) FilterMap(fn func(key K, val V) (bool, V)) Tbl[K, V]

FilterMap applies a function to each key-value pair, filtering and transforming the pairs in the process.

func (Tbl[K, V]) IsAll

func (self Tbl[K, V]) IsAll(fn func(key K, val V) bool) bool

IsAll returns true if all key-value pairs satisfy the provided function.

func (Tbl[K, V]) IsAny

func (self Tbl[K, V]) IsAny(fn func(key K, val V) bool) bool

IsAny returns true if any key-value pair satisfies the provided function.

func (Tbl[K, V]) IsEmpty

func (self Tbl[K, V]) IsEmpty() bool

IsEmpty returns true if the table has no key-value pairs.

func (Tbl[K, V]) Keys

func (self Tbl[K, V]) Keys() Vec[K]

Keys returns a Vec containing all the keys from the table.

func (Tbl[K, V]) Len

func (self Tbl[K, V]) Len() int

Len returns the number of key-value pairs in the table.

func (Tbl[K, V]) Map

func (self Tbl[K, V]) Map(fn func(key K, val V) V) Tbl[K, V]

Map applies a function to each key-value pair and returns a new Tbl with the results.

func (Tbl[K, V]) Pop

func (self Tbl[K, V]) Pop(key K) V

Pop removes a key-value pair from the table and returns the removed value.

func (Tbl[K, V]) Put

func (self Tbl[K, V]) Put(key K, val V)

Put sets the value for a specified key in the table.

type Vec

type Vec[T any] []T

Vec is a generic vector type for elements of any type.

func NewVec

func NewVec[T any](args ...any) Vec[T]

NewVec returns a Vec[T]. There are three calling forms:

NewVec[T]() returns a Vec[T] of length 0 and capacity 8.
NewVec[T](cap) returns a Vec[T] of length 0 and capacity parameter cap.
NewVec[T](array[T] | slice[T] | Vec[T]) returns a shallow copy of the given array, slice, or
Vec.

func (*Vec[T]) Cap

func (self *Vec[T]) Cap() int

Cap returns the capacity of the vector.

func (*Vec[T]) Del

func (self *Vec[T]) Del(idx int) T

Del removes and returns the element at the specified index in the vector.

func (*Vec[T]) Filter

func (self *Vec[T]) Filter(fn func(i int, it T) bool) Vec[T]

Filter returns a new Vec containing only the elements that satisfy the provided function.

func (*Vec[T]) FilterMap

func (self *Vec[T]) FilterMap(fn func(i int, it T) (bool, T)) Vec[T]

FilterMap returns a new Vec with elements that satisfy the function and applies another transformation.

func (*Vec[T]) Index

func (self *Vec[T]) Index(fn func(it T) bool) int

Index returns the first index where the provided function returns true, or -1 if no element matches.

func (*Vec[T]) Ins

func (self *Vec[T]) Ins(idx int, it T)

Ins inserts an element at the specified index in the vector.

func (*Vec[T]) IsAll

func (self *Vec[T]) IsAll(fn func(i int, it T) bool) bool

IsAll returns true if all elements in the vector satisfy the provided function.

func (*Vec[T]) IsAny

func (self *Vec[T]) IsAny(fn func(i int, it T) bool) bool

IsAny returns true if any element in the vector satisfies the provided function.

func (*Vec[T]) IsEmpty

func (self *Vec[T]) IsEmpty() bool

IsEmpty returns true if the vector has no elements.

func (*Vec[T]) IsExist

func (self *Vec[T]) IsExist(fn func(it T) bool) bool

IsExist checks if any element in the vector satisfies the provided function.

func (*Vec[T]) IsSort

func (self *Vec[T]) IsSort(fn func(a, b T) int) bool

IsSort checks if the vector is sorted according to the comparison function provided.

func (*Vec[T]) Len

func (self *Vec[T]) Len() int

Len returns the number of elements in the vector.

func (*Vec[T]) Map

func (self *Vec[T]) Map(fn func(i int, it T) T) Vec[T]

Map returns a new Vec constructed by applying the provided function to each element of the vector.

func (*Vec[T]) Pop

func (self *Vec[T]) Pop() T

Pop removes and returns the last elements of the vector.

func (*Vec[T]) Put

func (self *Vec[T]) Put(it T)

Put appends an element to the end of the vector.

func (*Vec[T]) Sort

func (self *Vec[T]) Sort(fn func(a, b T) int)

Sort sorts the vector based on the comparison function provided.

Jump to

Keyboard shortcuts

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