bytego

package module
v0.0.0-...-38a9cd2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 24 Imported by: 1

README

bytego

Documentation

Overview

BSD licence at https://github.com/julienschmidt/httprouter/blob/master/LICENSE

Index

Constants

View Source
const (
	MIMEJSON              = "application/json"
	MIMEHTML              = "text/html"
	MIMEXML               = "application/xml"
	MIMEXML2              = "text/xml"
	MIMEPlain             = "text/plain"
	MIMEPOSTForm          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm = "multipart/form-data"
	MIMEPROTOBUF          = "application/x-protobuf"
	MIMEYAML              = "application/x-yaml"
)
View Source
const (
	HeaderContentLength   = "Content-Length"
	HeaderOrigin          = "Origin"
	HeaderVary            = "Vary"
	HeaderXForwardedFor   = "X-Forwarded-For"
	HeaderXForwardedProto = "X-Forwarded-Proto"
	HeaderXRealIP         = "X-Real-Ip"
	HeaderXRequestID      = "X-Request-ID"

	// Access control
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"
)

Variables

This section is empty.

Functions

func CleanPath

func CleanPath(p string) string

CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.

The following rules are applied iteratively until no further processing can be done:

  1. Replace multiple slashes with a single slash.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.

If the result of this process is an empty string, "/" is returned

Types

type App

type App struct {
	Router

	Logger Logger
	// contains filtered or unexported fields
}

func New

func New() *App

func (*App) Debug

func (a *App) Debug(isDebug bool)

func (*App) Handler

func (a *App) Handler() http.Handler

func (*App) Listener

func (a *App) Listener(listener net.Listener) error

func (*App) NoRoute

func (app *App) NoRoute(handlers ...HandlerFunc)

func (*App) Run

func (a *App) Run(addr string) error

func (*App) SetErrorHandler

func (a *App) SetErrorHandler(fc ErrorHandler)

func (*App) SetLogger

func (a *App) SetLogger(l Logger)

func (*App) SetRender

func (a *App) SetRender(render Renderer)

func (*App) SetValidator

func (a *App) SetValidator(fc Validate, trans ...ValidateTranslate)

func (*App) Stop

func (a *App) Stop() error

type Ctx

type Ctx struct {
	Response ResponseWriter
	Request  *http.Request
	Params   Params
	// contains filtered or unexported fields
}

func (*Ctx) Abort

func (c *Ctx) Abort()

func (*Ctx) AbortWithStatus

func (c *Ctx) AbortWithStatus(code int)

func (*Ctx) AppendHeader

func (c *Ctx) AppendHeader(key string, values ...string)

func (*Ctx) Bind

func (c *Ctx) Bind(i interface{}) error

func (*Ctx) Blob

func (c *Ctx) Blob(code int, contentType string, b []byte) (err error)

func (*Ctx) ClientIP

func (c *Ctx) ClientIP() string

func (*Ctx) ContentType

func (c *Ctx) ContentType() string

func (*Ctx) Context

func (c *Ctx) Context() context.Context

func (*Ctx) Cookie

func (c *Ctx) Cookie(name string) (*http.Cookie, error)

func (*Ctx) Form

func (c *Ctx) Form(key string) string

func (*Ctx) Get

func (c *Ctx) Get(key string) (val interface{}, exists bool)

func (*Ctx) HTML

func (c *Ctx) HTML(code int, html string) error

func (*Ctx) HTMLBlob

func (c *Ctx) HTMLBlob(code int, b []byte) (err error)

func (*Ctx) HandleError

func (c *Ctx) HandleError(err error)

func (*Ctx) Header

func (c *Ctx) Header(key string) string

func (*Ctx) IsDebug

func (c *Ctx) IsDebug() bool

func (*Ctx) JSON

func (c *Ctx) JSON(code int, i interface{}) error

func (*Ctx) JSONP

func (c *Ctx) JSONP(code int, i interface{}) error

func (*Ctx) Logger

func (c *Ctx) Logger() Logger

func (*Ctx) Next

func (c *Ctx) Next() error

func (*Ctx) Param

func (c *Ctx) Param(key string) string

func (*Ctx) Query

func (c *Ctx) Query(key string) string

func (*Ctx) Redirect

func (c *Ctx) Redirect(location string, code ...int) error

func (*Ctx) RemoteIP

func (c *Ctx) RemoteIP() string

func (*Ctx) RoutePath

func (c *Ctx) RoutePath() string

func (*Ctx) Set

func (c *Ctx) Set(key string, val interface{})

func (*Ctx) SetCookie

func (c *Ctx) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)

func (*Ctx) SetHeader

func (c *Ctx) SetHeader(key, value string)

func (*Ctx) SetSameSite

func (c *Ctx) SetSameSite(samesite http.SameSite)

func (*Ctx) Status

func (c *Ctx) Status(code int)

func (*Ctx) String

func (c *Ctx) String(code int, s string) error

func (*Ctx) View

func (c *Ctx) View(code int, name string, data interface{}) error

func (*Ctx) XML

func (c *Ctx) XML(code int, i interface{}) error

type ErrorCode

type ErrorCode interface {
	Error() string
	ErrCode() int
}

type ErrorHandler

type ErrorHandler func(error, *Ctx)

type Group

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

func (*Group) Any

func (g *Group) Any(path string, handlers ...HandlerFunc) Router

func (*Group) DELETE

func (g *Group) DELETE(path string, handlers ...HandlerFunc) Router

func (*Group) GET

func (g *Group) GET(path string, handlers ...HandlerFunc) Router

func (*Group) Group

func (g *Group) Group(relativePath string, handlers ...HandlerFunc) Router

func (*Group) HEAD

func (g *Group) HEAD(path string, handlers ...HandlerFunc) Router

func (*Group) Handle

func (g *Group) Handle(method string, path string, handlers ...HandlerFunc) Router

func (*Group) OPTIONS

func (g *Group) OPTIONS(path string, handlers ...HandlerFunc) Router

func (*Group) PATCH

func (g *Group) PATCH(path string, handlers ...HandlerFunc) Router

func (*Group) POST

func (g *Group) POST(path string, handlers ...HandlerFunc) Router

func (*Group) PUT

func (g *Group) PUT(path string, handlers ...HandlerFunc) Router

func (*Group) Static

func (g *Group) Static(relativePath, root string) Router

func (*Group) StaticFS

func (g *Group) StaticFS(relativePath string, fsys http.FileSystem) Router

func (*Group) StaticFile

func (g *Group) StaticFile(relativePath, filePath string) Router

func (*Group) TRACE

func (g *Group) TRACE(path string, handlers ...HandlerFunc) Router

func (*Group) Use

func (g *Group) Use(middlewares ...HandlerFunc)

type HandlerFunc

type HandlerFunc func(*Ctx) error

type LogLevel

type LogLevel int8
const (
	LEVEL_DEBUG LogLevel = iota - 1
	LEVEL_INFO
	LEVEL_WARN
	LEVEL_ERROR
)

func ParseLogLevel

func ParseLogLevel(s string) LogLevel

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	SetLevel(level string)

	Debug(v ...interface{})
	Info(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})

	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
}

func NewLogger

func NewLogger(w io.Writer, level ...string) Logger

type Map

type Map map[string]interface{}

type Param

type Param struct {
	Key   string
	Value string
}

type Params

type Params []Param

func (Params) Get

func (ps Params) Get(name string) (string, bool)

type Renderer

type Renderer interface {
	Render(io.Writer, string, interface{}) error
}

func NewTemplate

func NewTemplate(pattner string, fsys ...fs.FS) Renderer

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	Status() int
	Size() int
	WriteString(string) (int, error)
	Committed() bool
}

type Router

type Router interface {
	GET(path string, handlers ...HandlerFunc) Router
	POST(path string, handlers ...HandlerFunc) Router
	PUT(path string, handlers ...HandlerFunc) Router
	DELETE(path string, handlers ...HandlerFunc) Router
	HEAD(path string, handlers ...HandlerFunc) Router
	PATCH(path string, handlers ...HandlerFunc) Router
	OPTIONS(path string, handlers ...HandlerFunc) Router
	TRACE(path string, handlers ...HandlerFunc) Router
	Handle(method string, path string, handlers ...HandlerFunc) Router
	Any(path string, handlers ...HandlerFunc) Router
	Static(relativePath, root string) Router
	StaticFS(relativePath string, fsys http.FileSystem) Router
	StaticFile(relativePath, filePath string) Router
	Group(relativePath string, handlers ...HandlerFunc) Router
	Use(middlewares ...HandlerFunc)
}

type Validate

type Validate func(i interface{}) error

type ValidateTranslate

type ValidateTranslate func(c *Ctx, err error) error

Directories

Path Synopsis
internal
fasttemplate
Package fasttemplate implements simple and fast template library.
Package fasttemplate implements simple and fast template library.
middleware

Jump to

Keyboard shortcuts

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