tgin

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 18 Imported by: 0

README

tgin

GoDoc

tgin is a light weight web framework

tgin API is most like gin web framework. But it is implements by basic go http library. If you focus on small compiled binary size and not very relay on all gin features, you can use it instead of gin.

Binary Size

Gin sample code:

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		msg := "Hello World"
		value, have := c.GetQuery("name")
		if have {
			msg = "Hello " + value
		}
		c.IndentedJSON(200, gin.H{"Message": msg})
	})
	r.Run("0.0.0.0:8888")
}

tgin sample code:

package main

import (
	gin "github.com/blacktear23/tgin"
)

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		msg := "Hello World"
		value, have := c.GetQuery("name")
		if have {
			msg = "Hello " + value
		}
		c.IndentedJSON(200, gin.H{"Message": msg})
	})
	r.Run("0.0.0.0:8888")
}

Compile command:

go build -trimpath -ldflags "-s -w"

Compiled binary size:

Package Binary Size (byte) Reduce Ratio go version
gin 11863092 Byte 0% 1.14
tgin 6076500 Byte 48% 1.14
gin 11819212 Byte 0% 1.15
tgin 5186060 Byte 56% 1.15

Documentation

Index

Constants

View Source
const INDEX = "index.html"

Variables

This section is empty.

Functions

func Dir

func Dir(root string, listDir bool) http.FileSystem

func GzipHandler added in v1.0.8

func GzipHandler(next http.Handler) http.Handler

func LoggerMiddleware

func LoggerMiddleware(c *Context)

func RecoveryMiddleware

func RecoveryMiddleware(c *Context)

Types

type Context

type Context struct {
	Method  string
	Request *http.Request
	Writer  http.ResponseWriter
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

func (*Context) BindJSON

func (c *Context) BindJSON(obj interface{}) error

func (*Context) File

func (c *Context) File(filePath string)

func (*Context) FormFile

func (c *Context) FormFile(key string) (*multipart.FileHeader, error)

func (*Context) Get

func (c *Context) Get(key string) (interface{}, bool)

func (*Context) GetHeader

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

func (*Context) GetQuery

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

func (*Context) GetQueryArray

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

func (*Context) Header

func (c *Context) Header(key, value string)

func (*Context) IndentedJSON

func (c *Context) IndentedJSON(code int, val interface{})

func (*Context) JSON

func (c *Context) JSON(code int, val interface{})

func (*Context) Next

func (c *Context) Next()

func (*Context) PostForm

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

func (*Context) PostFormArray

func (c *Context) PostFormArray(key string) []string

func (*Context) Redirect

func (c *Context) Redirect(code int, location string)

func (*Context) Set

func (c *Context) Set(key string, obj interface{})

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

func (*Context) Text

func (c *Context) Text(code int, message string)

type Engine

type Engine struct {
	*RouteGroup
}

func Default

func Default() *Engine

func New

func New() *Engine

func (*Engine) Run

func (e *Engine) Run(addr string) error

func (*Engine) RunTLS

func (e *Engine) RunTLS(addr, certFile, keyFile string) error

type H

type H map[string]interface{}

type MiddlewareTree added in v1.0.7

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

func (*MiddlewareTree) Add added in v1.0.7

func (mt *MiddlewareTree) Add(prefix string, handler RouteHandler)

func (*MiddlewareTree) BuildMiddlewares added in v1.0.7

func (mt *MiddlewareTree) BuildMiddlewares(path string) RouteHandlerChain

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	http.ResponseWriter
	http.Hijacker
	// contains filtered or unexported fields
}

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(code int)

type RouteGroup

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

func NewRouteGroup

func NewRouteGroup() *RouteGroup

func (*RouteGroup) Any

func (rg *RouteGroup) Any(path string, handler RouteHandler)

func (*RouteGroup) DELETE

func (rg *RouteGroup) DELETE(path string, handler RouteHandler)

func (*RouteGroup) Delete

func (rg *RouteGroup) Delete(path string, handler RouteHandler)

func (*RouteGroup) GET

func (rg *RouteGroup) GET(path string, handler RouteHandler)

func (*RouteGroup) Get

func (rg *RouteGroup) Get(path string, handler RouteHandler)

func (*RouteGroup) Group

func (rg *RouteGroup) Group(prefix string) *RouteGroup

func (*RouteGroup) HEAD

func (rg *RouteGroup) HEAD(path string, handler RouteHandler)

func (*RouteGroup) Head

func (rg *RouteGroup) Head(path string, handler RouteHandler)

func (*RouteGroup) OPTIONS

func (rg *RouteGroup) OPTIONS(path string, handler RouteHandler)

func (*RouteGroup) Options

func (rg *RouteGroup) Options(path string, handler RouteHandler)

func (*RouteGroup) POST

func (rg *RouteGroup) POST(path string, handler RouteHandler)

func (*RouteGroup) PUT

func (rg *RouteGroup) PUT(path string, handler RouteHandler)

func (*RouteGroup) Post

func (rg *RouteGroup) Post(path string, handler RouteHandler)

func (*RouteGroup) Put

func (rg *RouteGroup) Put(path string, handler RouteHandler)

func (*RouteGroup) ServeHTTP

func (rg *RouteGroup) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*RouteGroup) StaticFile

func (rg *RouteGroup) StaticFile(path, filePath string)

func (*RouteGroup) Use

func (rg *RouteGroup) Use(middlewares ...RouteHandler)

type RouteHandler

type RouteHandler func(c *Context)

func StaticFileMiddleware

func StaticFileMiddleware(urlPrefix, root string, indexes bool) RouteHandler

type RouteHandlerChain added in v1.0.7

type RouteHandlerChain []RouteHandler

Jump to

Keyboard shortcuts

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