ibnsina

package module
v0.0.0-...-1cb9e37 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

README

ibnsina

solid http router for go

warning: unit tests are still largely incomplete

coming up

  • session manager that supports redis & mysql
  • robust json reader and responder
  • clean validation package
  • configurations from command-line flags and .env files
  • seamless support for open-telemetery
  • middleware chains and handler groups
  • default gracefull shutdown

Documentation

Index

Constants

View Source
const TraceIDHeader = "X-Trace-ID"

Variables

View Source
var (
	EmailRX = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)

Functions

func CharsInRange

func CharsInRange(value string, minLimit, maxLimit int) bool

func In

func In[T comparable](value T, values []T) bool

func Matches

func Matches(value string, rx *regexp.Regexp) bool

func MaxChars

func MaxChars(value string, maxLimit int) bool

func MaxRunes

func MaxRunes(value string, maxLimit int) bool

func MinChars

func MinChars(value string, minLimit int) bool

func MinRunes

func MinRunes(value string, minLimit int) bool

func Param

func Param(ctx context.Context, name string) string

func RunesInRange

func RunesInRange(value string, minLimit, maxLimit int) bool

func Uniques

func Uniques[T comparable](values []T) bool

Types

type Config

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

func NewConfig

func NewConfig(file *os.File) (*Config, error)

func (*Config) Bool

func (config *Config) Bool(key string) (bool, error)

func (*Config) BoolOrDefault

func (config *Config) BoolOrDefault(key string, def bool) bool

func (*Config) Duration

func (config *Config) Duration(key string) (time.Duration, error)

func (*Config) DurationOrDefault

func (config *Config) DurationOrDefault(key string, def time.Duration) time.Duration

func (*Config) Int

func (config *Config) Int(key string) (int, error)

func (*Config) IntOrDefault

func (config *Config) IntOrDefault(key string, def int) int

func (*Config) Log

func (config *Config) Log() string

func (*Config) MustBool

func (config *Config) MustBool(key string) bool

func (*Config) MustDuration

func (config *Config) MustDuration(key string) time.Duration

func (*Config) MustInt

func (config *Config) MustInt(key string) int

func (*Config) MustString

func (config *Config) MustString(key string) string

func (*Config) MustTime

func (config *Config) MustTime(key string) time.Time

func (*Config) MustURL

func (config *Config) MustURL(key string) *url.URL

func (*Config) SetBool

func (config *Config) SetBool(key string, value bool)

func (*Config) SetDuration

func (config *Config) SetDuration(key string, value time.Duration)

func (*Config) SetInt

func (config *Config) SetInt(key string, value int)

func (*Config) SetString

func (config *Config) SetString(key string, value string)

func (*Config) SetTime

func (config *Config) SetTime(key string, value time.Time)

func (*Config) SetURL

func (config *Config) SetURL(key string, value *url.URL)

func (*Config) String

func (config *Config) String(key string) (string, error)

func (*Config) StringOrDefault

func (config *Config) StringOrDefault(key string, def string) string

func (*Config) Time

func (config *Config) Time(key string) (time.Time, error)

func (*Config) TimeOrDefault

func (config *Config) TimeOrDefault(key string, def time.Time) time.Time

func (*Config) URL

func (config *Config) URL(key string) (*url.URL, error)

func (*Config) URLOrDefault

func (config *Config) URLOrDefault(key string, def *url.URL) *url.URL

type Group

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

func (*Group) Handle

func (group *Group) Handle(path string, handler Handler, methods ...string)

type Handler

type Handler func(context.Context, http.ResponseWriter, *http.Request)

type Middleware

type Middleware func(Handler) Handler

type Router

type Router struct {
	NotFound         Handler
	MethodNotAllowed Handler
	Options          Handler
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(middlewares ...Middleware) *Router

func (*Router) Group

func (router *Router) Group(middlewares ...Middleware) *Group

func (*Router) Handle

func (router *Router) Handle(path string, handler Handler, methods ...string)

func (*Router) Run

func (router *Router) Run(addr string, timeout time.Duration, logger *log.Logger) error

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Router) Use

func (router *Router) Use(middlewares ...Middleware)

type Validator

type Validator struct {
	FieldErrors    map[string]string
	NonFieldErrors []string
}

func NewValidator

func NewValidator() *Validator

func (*Validator) AddFieldError

func (validator *Validator) AddFieldError(key string, message string)

func (*Validator) AddNonFieldError

func (validator *Validator) AddNonFieldError(message string)

func (*Validator) Check

func (validator *Validator) Check(cond bool, key string, message string)

func (*Validator) Ok

func (validator *Validator) Ok() bool

type Values

type Values struct {
	TraceID string
	Now     time.Time
	Status  int
}

Jump to

Keyboard shortcuts

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