web

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

statsd middleware

Index

Constants

View Source
const (
	CORS_ALLOW_METHODS string = "GET,HEAD,PUT,PATCH,POST"
	CORS_ALLOW_HEADERS string = ""
)
View Source
const JWT_COOKIE_KEY string = "JWT_TOKEN"

cookie key name

View Source
const JWT_OBJ_KEY string = "user_ctx"
View Source
const USER_TRACK_KEY string = "USER_TRACK"

Variables

View Source
var StatusCode = map[int]string{
	100: "Continue",
	101: "Switching Protocols",
	200: "OK",
	201: "Created",
	202: "Accepted",
	203: "Non-Authoritative Information",
	204: "No Content",
	205: "Reset Content",
	206: "Partial Content",
	300: "Multiple Choices",
	301: "Moved Permanently",
	302: "Found",
	303: "See Other",
	304: "Not Modified",
	305: "Use Proxy",
	307: "Temporary Redirect",
	400: "Bad Request",
	401: "Unauthorized",
	402: "Payment Required",
	403: "Forbidden",
	404: "Not Found",
	405: "Method Not Allowed",
	406: "Not Acceptable",
	407: "Proxy Authentication Required",
	408: "Request Time-out",
	409: "Conflict",
	410: "Gone",
	411: "Length Required",
	412: "Precondition Failed",
	413: "Request Entity Too Large",
	414: "Request-URI Too Large",
	415: "Unsupported Media Type",
	416: "Requested range not satisfiable",
	417: "Expectation Failed",
	500: "Internal Server Error",
	501: "Not Implemented",
	502: "Bad Gateway",
	503: "Service Unavailable",
	504: "Gateway Time-out",
	505: "HTTP Version not supported",
}

Functions

func BadRequest

func BadRequest(c *gin.Context, data map[string]interface{})

func CacheControl

func CacheControl(c *gin.Context, max int)

cache

func Cors

func Cors() gin.HandlerFunc

func CreateApi

func CreateApi(router *gin.Engine, config []Api) *gin.Engine

create api routes

func CreateGroup

func CreateGroup(router *gin.Engine, prefix string, config []Api) *gin.Engine

create api Group @param prefix [string] api prefix

func Forbidden

func Forbidden(c *gin.Context, data map[string]interface{})

func JwtClearCookie

func JwtClearCookie(c *gin.Context)

clear cookie

func JwtMiddleWare

func JwtMiddleWare() gin.HandlerFunc

middleware

func JwtSetCookie

func JwtSetCookie(c *gin.Context, v interface{})

sign and set cookie

func JwtUserCtx

func JwtUserCtx(c *gin.Context, v interface{}) error

read string from cookie, and parse it for user context which stored in v

func Logger

func Logger(headers ...string) gin.HandlerFunc

middleware

func NotFound

func NotFound(c *gin.Context, data map[string]interface{})

func ServerError

func ServerError(c *gin.Context, data map[string]interface{})

func StatsdGauge

func StatsdGauge(key string) gin.HandlerFunc

func StatsdIncrement

func StatsdIncrement(key string) gin.HandlerFunc

func Success

func Success(c *gin.Context, data map[string]interface{})

func Unauthorized

func Unauthorized(c *gin.Context, data map[string]interface{})

func UserTrack

func UserTrack() gin.HandlerFunc

Types

type Api

type Api struct {
	Method   string
	Path     string
	Handlers ApiHandlers
}

Api struct

type ApiHandlers

type ApiHandlers []gin.HandlerFunc

gin.HandlerFunc

type Jwt

type Jwt struct {
	Secret string
	Domain string
	Expire int
	// contains filtered or unexported fields
}

Jwt

func (*Jwt) Init

func (obj *Jwt) Init()

func (*Jwt) Ware

func (obj *Jwt) Ware(c *gin.Context)

middleware. parse and validate the JWT token

type MyClaims

type MyClaims struct {
	Payload string `json:"payload"`
	jwt.StandardClaims
}

custom claim

type UnlessWare

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

func Unless

func Unless(reg string) *UnlessWare

new a Unless ware @Params reg [string] regexp of HTTP Path

func (*UnlessWare) Then

func (that *UnlessWare) Then(fn gin.HandlerFunc) gin.HandlerFunc

if HTTP url matches apiRegexp, then skip fn, otherwise invoke fn. fn can be a middleware or a web controller.

Jump to

Keyboard shortcuts

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