vex

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: MIT Imports: 10 Imported by: 0

README

vex

Vex is a web framework written in Go (Golang). This will be a progressively more functional web framework

Documentation

Index

Constants

View Source
const ANY = "ANY"

ANY is the other name of "ANY" means url use ANY method

Variables

This section is empty.

Functions

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes use unsafe pointer it will not copy the memory

func SubStringLast

func SubStringLast(str string, substr string) string

Types

type Context

type Context struct {
	W http.ResponseWriter // response
	R *http.Request       // request
	// contains filtered or unexported fields
}

Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example

func (*Context) DefaultQuery

func (c *Context) DefaultQuery(key, defaultValue string) string

DefaultQuery if you have not set the key return the default value

func (*Context) File

func (c *Context) File(fileName string)

File writes the specified file into the body stream in an efficient way.

func (*Context) FileAttachment

func (c *Context) FileAttachment(filepath, filename string)

FileAttachment writes the specified file into the body stream in an efficient way On the client side, the file will typically be downloaded with the given filename

func (*Context) FileFromFS

func (c *Context) FileFromFS(filepath string, fs http.FileSystem)

FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.

func (*Context) GetAllQuery

func (c *Context) GetAllQuery(key string) ([]string, bool)

GetAllQuery if you want to all the url query param by using key like ?id=1&id=2 return [1, 2]

func (*Context) GetQuery

func (c *Context) GetQuery(key string) string

GetQuery if url is ?key:value you want to get value by using key

func (*Context) GetQueryMap

func (c *Context) GetQueryMap(key string) (map[string]string, bool)

GetQueryMap get the mapping

func (*Context) HTML

func (c *Context) HTML(status int, html string) error

HTML Render the HTML files to request it return pure HTML files, don't need any data

func (*Context) HTMLTemplate

func (c *Context) HTMLTemplate(name string, data any, filename ...string) error

HTMLTemplate is the function to render the HTML Template return HTML template files with data

func (*Context) HTMLTemplateGlob

func (c *Context) HTMLTemplateGlob(name string, data any, pattern string) error

HTMLTemplate is the function to render the HTML Template you set

func (*Context) JSON

func (c *Context) JSON(status int, data any) error

JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".

func (*Context) QueryArray

func (c *Context) QueryArray(key string) (values []string)

QueryArray return query param without check

func (*Context) QueryMap

func (c *Context) QueryMap(key string) (dicts map[string]string)

QueryMap get the query map without check

func (*Context) Redirect

func (c *Context) Redirect(status int, url string) error

func (*Context) Render

func (c *Context) Render(statusCode int, r render.Render) error

func (*Context) String

func (c *Context) String(status int, format string, values ...any) error

String return c.String()

func (*Context) Template

func (c *Context) Template(name string, data any) error

Template set the content to the memory and load all HTML template files to system

func (*Context) XML

func (c *Context) XML(status int, data any) error

XML serializes the given struct as XML into the response body. It also sets the Content-Type as "application/xml".

type Engine

type Engine struct {
	HTMLRender render.HTMLRender
	// contains filtered or unexported fields
}

Engine is the framework's instance, it contains the muxer, middleware and configuration settings. Create an instance of Engine, by using New() or Default().

func New

func New() *Engine

New returns a new blank Engine instance without any middleware attached.

func (Engine) Group

func (r Engine) Group(name string) *routerGroup

Group grouping the routes initialize the routerGroups by using the Group function take the routerGroup to manipulate the url

func (*Engine) LoadHTMLTemplate

func (e *Engine) LoadHTMLTemplate(pattern string)

func (*Engine) Run

func (e *Engine) Run()

Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

implement the interface method ServeHTTP

func (*Engine) SetFuncMap

func (e *Engine) SetFuncMap(funcMap template.FuncMap)

SetFuncMap SetHTMLTemplate LoadHTMLTemplate These three function is to render the html template files in memory

func (*Engine) SetHTMLTemplate

func (e *Engine) SetHTMLTemplate(t *template.Template)

type HandleFunc

type HandleFunc func(ctx *Context)

HandleFunc defines the handler used by vex middleware as return value. Context is the wrap of (w *http.ResponseWriter, r http.Request)

type MiddlewareFunc

type MiddlewareFunc func(handleFunc HandleFunc) HandleFunc

MiddlewareFunc is code before or after HandleFunc input the handleFunc before process then return the handle Func which after process

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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