fastgo3

package module
v0.0.0-...-066dc65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 9 Imported by: 0

README

fastgo3

A simple Golang web framework base on fasthttp.

fastgo3 does meaning that Fast Go Go Go.

simple usage:

import (
  "github.com/fastgo3/fastgo3"
)

func main() {
  app := fastgo3.New()
  app.Get("/helloworld", func (ctx *fastgo3.Context) {
    ctx.RenderString("hello, world!")
  })
  app.Run("0.0.0.0", 3030)
}

more examples

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SUPPORT_METHODS = []string{"GET", "HEAD", "POST", "DELETE", "PATCH", "PUT", "OPTIONS"}
View Source
var SUPPORT_METHOD_SET = func() map[string]int {
	m := make(map[string]int)
	for _, key := range SUPPORT_METHODS {
		m[key] = 0
	}
	return m
}()

Functions

func Purify

func Purify(uri string) string

func Upper

func Upper(method string) string

func Web404Handler

func Web404Handler(context *Context)

func Web405Handler

func Web405Handler(context *Context)

func WebErrHandler

func WebErrHandler(context *Context, httpCode int, message string)

Types

type ApiResult

type ApiResult struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type Application

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

func New

func New() Application

func (*Application) Connect

func (app *Application) Connect(uri string, handler HandlerFunc) *Application

func (*Application) Delete

func (app *Application) Delete(uri string, handler HandlerFunc) *Application

func (*Application) Get

func (app *Application) Get(uri string, handler HandlerFunc) *Application

func (*Application) GetRouter

func (app *Application) GetRouter() *Router

func (*Application) Head

func (app *Application) Head(uri string, handler HandlerFunc) *Application

func (*Application) Options

func (app *Application) Options(uri string, handler HandlerFunc) *Application

func (*Application) Patch

func (app *Application) Patch(uri string, handler HandlerFunc) *Application

func (*Application) Post

func (app *Application) Post(uri string, handler HandlerFunc) *Application

func (*Application) Put

func (app *Application) Put(uri string, handler HandlerFunc) *Application

func (*Application) Route

func (app *Application) Route(methods []string, uri string, handler HandlerFunc) *Application

func (*Application) Run

func (app *Application) Run(ip string, port int)

func (*Application) Trace

func (app *Application) Trace(uri string, handler HandlerFunc) *Application

func (*Application) Use

func (app *Application) Use(middlewares ...HandlerFunc) *Application

type Context

type Context struct {
	Method string

	SeqId   string
	UriArgs map[string]string
	// contains filtered or unexported fields
}

func NewContext

func NewContext(fastHttpRequestCtx *fasthttp.RequestCtx) Context

func (*Context) BoolParam

func (context *Context) BoolParam(name string, defaultValue bool) bool

GetBool returns boolean value for the given key.

true is returned for "1", "t", "T", "true", "TRUE", "True", "y", "yes", "Y", "YES", "Yes", otherwise false is returned.

func (*Context) BytesParam

func (context *Context) BytesParam(name string, defaultValue []byte) []byte

func (*Context) ConnRequestNum

func (context *Context) ConnRequestNum() uint64

func (*Context) ConnTime

func (context *Context) ConnTime() string

func (*Context) Err

func (context *Context) Err(msg string)

func (*Context) Finish

func (context *Context) Finish(code int, msg string, data interface{})

func (*Context) FloatParam

func (context *Context) FloatParam(key string, defaultValue float64) float64

func (*Context) Host

func (context *Context) Host() string

func (*Context) IntParam

func (context *Context) IntParam(key string, defaultValue int) int

func (*Context) Next

func (context *Context) Next()

func (*Context) Ok

func (context *Context) Ok(data interface{})

func (*Context) Path

func (context *Context) Path() string

func (*Context) PostArgs

func (context *Context) PostArgs() *fasthttp.Args

PostArgs returns POST arguments.

It doesn't return query arguments from RequestURI - use QueryArgs for this.

Returned arguments are valid until returning from RequestHandler.

See also QueryArgs, FormValue and FormFile.

func (*Context) QueryArgs

func (context *Context) QueryArgs() *fasthttp.Args

QueryArgs returns query arguments from RequestURI.

It doesn't return POST'ed arguments - use PostArgs() for this.

Returned arguments are valid until returning from RequestHandler.

See also PostArgs, FormValue and FormFile.

func (*Context) Redirect

func (context *Context) Redirect(url string)

func (*Context) RemoteIP

func (context *Context) RemoteIP() string

func (*Context) RenderHtml

func (context *Context) RenderHtml(data string)

func (*Context) RenderJson

func (context *Context) RenderJson(data interface{})

func (*Context) RenderString

func (context *Context) RenderString(data string)

func (*Context) Request

func (context *Context) Request() *fasthttp.Request

func (*Context) RequestURI

func (context *Context) RequestURI() string

func (*Context) SetContentType

func (context *Context) SetContentType(contentType string) *Context

func (*Context) SetCookie

func (context *Context) SetCookie(name string, value string) *Context

func (*Context) SetHeader

func (context *Context) SetHeader(name string, value string) *Context

func (*Context) StrParam

func (context *Context) StrParam(name string, defaultValue string) string

func (*Context) Time

func (context *Context) Time() string

func (*Context) UserAgent

func (context *Context) UserAgent() string

func (*Context) Write

func (context *Context) Write(p []byte) (int, error)

Write writes p into response body.

func (*Context) WriteString

func (context *Context) WriteString(s string) (int, error)

WriteString appends s to response body.

type DynRouteNode

type DynRouteNode struct {
	Handler HandlerFunc // HandlerFunc or nil
	// contains filtered or unexported fields
}

func NewDynRouteNode

func NewDynRouteNode(path string, isEnd bool, handler HandlerFunc) DynRouteNode

func (*DynRouteNode) Add

func (node *DynRouteNode) Add(child *DynRouteNode)

type HandlerFunc

type HandlerFunc func(ctx *Context)

func Logger

func Logger() HandlerFunc

func SeqId

func SeqId() HandlerFunc

type MethodHandler

type MethodHandler map[string]HandlerFunc

type MiddlewareFunc

type MiddlewareFunc func() HandlerFunc

type Router

type Router struct {
	StaticRoutes    map[string]MethodHandler
	DynRoot         DynRouteNode
	DynRoutesHeight int
}

func (*Router) Add

func (router *Router) Add(method string, uri string, handler HandlerFunc) *Router

func (*Router) Match

func (router *Router) Match(uri string, method string) (HandlerFunc, map[string]string, int)

type StaticRoute

type StaticRoute struct {
	Method  string
	Uri     string
	Handler HandlerFunc
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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