tango

package module
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 29 Imported by: 0

README

Tango 简体中文

CircleCI codecov

Tango Logo

Package tango is a micro & pluggable web framework for Go.

Current version: v0.5.0 Version History

Getting Started

To install Tango:

go get github.com/youjianglong/tango

A classic usage of Tango below:

package main

import (
    "errors"
    "github.com/youjianglong/tango"
)

type Action struct {
    tango.JSON
}

func (Action) Get() interface{} {
    if true {
        return map[string]string{
            "say": "Hello tango!",
        }
    }
    return errors.New("something error")
}

func main() {
    t := tango.Classic()
    t.Get("/", new(Action))
    t.Run()
}

Then visit http://localhost:8000 on your browser. You will get

{"say":"Hello tango!"}

If you change true after if to false, then you will get

{"err":"something error"}

This code will automatically convert returned map or error to a json because we has an embedded struct tango.JSON.

Features

  • Powerful routing & Flexible routes combinations.
  • Directly integrate with existing services.
  • Easy to plugin features with modular design.
  • High performance dependency injection embedded.

Middlewares

Middlewares allow you easily plugin features for your Tango applications.

There are already many middlewares to simplify your work:

Documentation

Discuss

Cases

License

This project is under BSD License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	HeaderAcceptEncoding  = "Accept-Encoding"
	HeaderContentEncoding = "Content-Encoding"
	HeaderContentLength   = "Content-Length"
	HeaderContentType     = "Content-Type"
	HeaderVary            = "Vary"
)

some http headers

View Source
const (
	LogLevelError = iota
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
)

Variables

View Source
var (
	SupportMethods = []string{
		"GET",
		"POST",
		"HEAD",
		"DELETE",
		"PUT",
		"OPTIONS",
		"TRACE",
		"PATCH",
	}

	PoolSize = 10
)

enumerates all supported HTTP methods

View Source
var (
	// ClassicHandlers the default handlers
	ClassicHandlers = []Handler{
		Logging(),
		Recovery(false),
		Compresses([]string{}),
		Static(StaticOptions{Prefix: "public"}),
		Return(),
		Param(),
		Contexts(),
	}
)

Functions

func Dir added in v0.4.4

func Dir(dir string) func(ctx *Context)

Dir returns a handle to serve a directory

func File added in v0.4.4

func File(path string) func(ctx *Context)

File returns a handle to serve a file

func NewCookie

func NewCookie(name string, value string, age ...int64) *http.Cookie

NewCookie return a http.Cookie via give name and value

func NewSecureCookie

func NewSecureCookie(secret, name string, val string, age ...int64) *http.Cookie

NewSecureCookie generates a new secure cookie

func Version

func Version() string

Version returns tango's version

Types

type AbortError

type AbortError interface {
	error
	Code() int
}

AbortError defines an interface to describe HTTP error

func Abort

func Abort(code int, content ...string) AbortError

Abort returns an AbortError

func Forbidden

func Forbidden(content ...string) AbortError

Forbidden returns forbidden HTTP error

func InternalServerError

func InternalServerError(content ...string) AbortError

InternalServerError returns internal server HTTP error

func NotFound

func NotFound(content ...string) AbortError

NotFound returns not found HTTP error

func NotSupported

func NotSupported(content ...string) AbortError

NotSupported returns not supported HTTP error

func Unauthorized

func Unauthorized(content ...string) AbortError

Unauthorized returns unauthorized HTTP error

type CompositeLogger added in v0.5.6

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

CompositeLogger defines a composite loggers

func (*CompositeLogger) Debug added in v0.5.6

func (l *CompositeLogger) Debug(v ...interface{})

Debug implementes Logger interface

func (*CompositeLogger) Debugf added in v0.5.6

func (l *CompositeLogger) Debugf(format string, v ...interface{})

Debugf implementes Logger interface

func (*CompositeLogger) Debugln added in v0.5.6

func (l *CompositeLogger) Debugln(v ...interface{})

Debug implementes Logger interface

func (*CompositeLogger) Error added in v0.5.6

func (l *CompositeLogger) Error(v ...interface{})

Error implementes Logger interface

func (*CompositeLogger) Errorf added in v0.5.6

func (l *CompositeLogger) Errorf(format string, v ...interface{})

Errorf implementes Logger interface

func (*CompositeLogger) Errorln added in v0.5.6

func (l *CompositeLogger) Errorln(v ...interface{})

Errorln implementes Logger interface

func (*CompositeLogger) Info added in v0.5.6

func (l *CompositeLogger) Info(v ...interface{})

Info implementes Logger interface

func (*CompositeLogger) Infof added in v0.5.6

func (l *CompositeLogger) Infof(format string, v ...interface{})

Infof implementes Logger interface

func (*CompositeLogger) Infoln added in v0.5.6

func (l *CompositeLogger) Infoln(v ...interface{})

Infoln implementes Logger interface

func (*CompositeLogger) Warn added in v0.5.6

func (l *CompositeLogger) Warn(v ...interface{})

Warn implementes Logger interface

func (*CompositeLogger) Warnf added in v0.5.6

func (l *CompositeLogger) Warnf(format string, v ...interface{})

Warnf implementes Logger interface

func (*CompositeLogger) Warnln added in v0.5.6

func (l *CompositeLogger) Warnln(v ...interface{})

Warnln implementes Logger interface

type Compress

type Compress struct{}

Compress implements auto Compresser

func (Compress) CompressType

func (Compress) CompressType() string

CompressType returns compress type

type Compresser

type Compresser interface {
	CompressType() string
}

Compresser defines the interface return compress type

type Context

type Context struct {
	Logger

	ResponseWriter

	Result interface{}
	// contains filtered or unexported fields
}

Context defines request and response context

func (*Context) Abort

func (ctx *Context) Abort(status int, body ...string)

Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.

func (*Context) Action

func (ctx *Context) Action() interface{}

Action returns action

func (*Context) ActionTag added in v0.5.6

func (ctx *Context) ActionTag(fieldName string) string

ActionTag returns field tag on action struct TODO: cache the name

func (*Context) ActionValue added in v0.5.6

func (ctx *Context) ActionValue() reflect.Value

ActionValue returns action value

func (*Context) Body added in v0.4.8

func (ctx *Context) Body() ([]byte, error)

Body returns body's content

func (*Context) Cookie added in v0.4.8

func (ctx *Context) Cookie(key string, defaults ...string) string

Cookie returns cookie as string with default

func (*Context) CookieBool added in v0.4.8

func (ctx *Context) CookieBool(key string, defaults ...bool) bool

CookieBool returns cookie as bool with default

func (*Context) CookieEscape added in v0.4.8

func (ctx *Context) CookieEscape(key string, defaults ...string) string

CookieEscape returns cookie as escaped string with default

func (*Context) CookieFloat32 added in v0.4.8

func (ctx *Context) CookieFloat32(key string, defaults ...float32) float32

CookieFloat32 returns cookie as float32 with default

func (*Context) CookieFloat64 added in v0.4.8

func (ctx *Context) CookieFloat64(key string, defaults ...float64) float64

CookieFloat64 returns cookie as float64 with default

func (*Context) CookieInt added in v0.4.8

func (ctx *Context) CookieInt(key string, defaults ...int) int

CookieInt returns cookie as int with default

func (*Context) CookieInt32 added in v0.4.8

func (ctx *Context) CookieInt32(key string, defaults ...int32) int32

CookieInt32 returns cookie as int32 with default

func (*Context) CookieInt64 added in v0.4.8

func (ctx *Context) CookieInt64(key string, defaults ...int64) int64

CookieInt64 returns cookie as int64 with default

func (*Context) CookieUint added in v0.4.8

func (ctx *Context) CookieUint(key string, defaults ...uint) uint

CookieUint returns cookie as uint with default

func (*Context) CookieUint32 added in v0.4.8

func (ctx *Context) CookieUint32(key string, defaults ...uint32) uint32

CookieUint32 returns cookie as uint32 with default

func (*Context) CookieUint64 added in v0.4.8

func (ctx *Context) CookieUint64(key string, defaults ...uint64) uint64

CookieUint64 returns cookie as uint64 with default

func (*Context) Cookies

func (ctx *Context) Cookies() Cookies

Cookies returns the cookies

func (*Context) DecodeJSON added in v0.5.6

func (ctx *Context) DecodeJSON(obj interface{}) error

DecodeJSON decodes body as JSON format to obj

func (*Context) DecodeJson added in v0.4.8

func (ctx *Context) DecodeJson(obj interface{}) error

DecodeJson decodes body as JSON format to obj Deprecated: use DecodeJSON instead

func (*Context) DecodeXML added in v0.5.6

func (ctx *Context) DecodeXML(obj interface{}) error

DecodeXML decodes body as XML format to obj

func (*Context) DecodeXml added in v0.4.8

func (ctx *Context) DecodeXml(obj interface{}) error

DecodeXml decodes body as XML format to obj Deprecated: use DecodeXML instead

func (*Context) Download

func (ctx *Context) Download(fpath string) error

Download provides a locale file to http client

func (*Context) Form added in v0.4.8

func (ctx *Context) Form(key string, defaults ...string) string

Form returns request form as string with default

func (*Context) FormBool added in v0.4.8

func (ctx *Context) FormBool(key string, defaults ...bool) bool

FormBool returns request form as bool with default

func (*Context) FormEscape added in v0.4.8

func (ctx *Context) FormEscape(key string, defaults ...string) string

FormEscape returns request form as escaped string with default

func (*Context) FormFloat32 added in v0.4.8

func (ctx *Context) FormFloat32(key string, defaults ...float32) float32

FormFloat32 returns request form as float32 with default

func (*Context) FormFloat64 added in v0.4.8

func (ctx *Context) FormFloat64(key string, defaults ...float64) float64

FormFloat64 returns request form as float64 with default

func (*Context) FormInt added in v0.4.8

func (ctx *Context) FormInt(key string, defaults ...int) int

FormInt returns request form as int with default

func (*Context) FormInt32 added in v0.4.8

func (ctx *Context) FormInt32(key string, defaults ...int32) int32

FormInt32 returns request form as int32 with default

func (*Context) FormInt64 added in v0.4.8

func (ctx *Context) FormInt64(key string, defaults ...int64) int64

FormInt64 returns request form as int64 with default

func (*Context) FormStrings added in v0.4.8

func (ctx *Context) FormStrings(key string, defaults ...[]string) []string

FormStrings returns request form as strings with default

func (*Context) FormUint added in v0.4.8

func (ctx *Context) FormUint(key string, defaults ...uint) uint

FormUint returns request form as uint with default

func (*Context) FormUint32 added in v0.4.8

func (ctx *Context) FormUint32(key string, defaults ...uint32) uint32

FormUint32 returns request form as uint32 with default

func (*Context) FormUint64 added in v0.4.8

func (ctx *Context) FormUint64(key string, defaults ...uint64) uint64

FormUint64 returns request form as uint64 with default

func (*Context) Forms added in v0.4.6

func (ctx *Context) Forms() *Forms

Forms returns the query/body names and values

func (*Context) HandleError

func (ctx *Context) HandleError()

HandleError handles errors

func (*Context) IP added in v0.4.8

func (ctx *Context) IP() string

IP returns remote IP

func (*Context) IsAjax added in v0.4.8

func (ctx *Context) IsAjax() bool

IsAjax returns if the request is an ajax request

func (*Context) Next

func (ctx *Context) Next()

Next call next middleware or action WARNING: don't invoke this method on action

func (*Context) NotFound

func (ctx *Context) NotFound(message ...string)

NotFound writes a 404 HTTP response

func (*Context) NotModified

func (ctx *Context) NotModified()

NotModified writes a 304 HTTP response

func (*Context) Param added in v0.4.8

func (ctx *Context) Param(key string, defaults ...string) string

Param returns request form as string with default

func (*Context) ParamBool added in v0.4.8

func (ctx *Context) ParamBool(key string, defaults ...bool) bool

ParamBool returns request form as bool with default

func (*Context) ParamEscape added in v0.4.8

func (ctx *Context) ParamEscape(key string, defaults ...string) string

ParamEscape returns request form as escaped string with default

func (*Context) ParamFloat32 added in v0.4.8

func (ctx *Context) ParamFloat32(key string, defaults ...float32) float32

ParamFloat32 returns request form as float32 with default

func (*Context) ParamFloat64 added in v0.4.8

func (ctx *Context) ParamFloat64(key string, defaults ...float64) float64

ParamFloat64 returns request form as float64 with default

func (*Context) ParamInt added in v0.4.8

func (ctx *Context) ParamInt(key string, defaults ...int) int

ParamInt returns request form as int with default

func (*Context) ParamInt32 added in v0.4.8

func (ctx *Context) ParamInt32(key string, defaults ...int32) int32

ParamInt32 returns request form as int32 with default

func (*Context) ParamInt64 added in v0.4.8

func (ctx *Context) ParamInt64(key string, defaults ...int64) int64

ParamInt64 returns request form as int64 with default

func (*Context) ParamStrings added in v0.4.8

func (ctx *Context) ParamStrings(key string, defaults ...[]string) []string

ParamStrings returns request form as slice of string with default

func (*Context) ParamUint added in v0.4.8

func (ctx *Context) ParamUint(key string, defaults ...uint) uint

ParamUint returns request form as uint with default

func (*Context) ParamUint32 added in v0.4.8

func (ctx *Context) ParamUint32(key string, defaults ...uint32) uint32

ParamUint32 returns request form as uint32 with default

func (*Context) ParamUint64 added in v0.4.8

func (ctx *Context) ParamUint64(key string, defaults ...uint64) uint64

ParamUint64 returns request form as uint64 with default

func (*Context) Params

func (ctx *Context) Params() *Params

Params returns the URL params

func (*Context) Queries added in v0.5.6

func (ctx *Context) Queries() *Queries

Queries returns the query names and values

func (*Context) Query added in v0.5.6

func (ctx *Context) Query(key string, defaults ...string) string

Query returns request form as string with default

func (*Context) QueryBool added in v0.5.6

func (ctx *Context) QueryBool(key string, defaults ...bool) bool

FormBool returns request form as bool with default

func (*Context) QueryEscape added in v0.5.6

func (ctx *Context) QueryEscape(key string, defaults ...string) string

QueryEscape returns request form as escaped string with default

func (*Context) QueryFloat32 added in v0.5.6

func (ctx *Context) QueryFloat32(key string, defaults ...float32) float32

QueryFloat32 returns request form as float32 with default

func (*Context) QueryFloat64 added in v0.5.6

func (ctx *Context) QueryFloat64(key string, defaults ...float64) float64

FormFloat64 returns request form as float64 with default

func (*Context) QueryInt added in v0.5.6

func (ctx *Context) QueryInt(key string, defaults ...int) int

QueryInt returns request form as int with default

func (*Context) QueryInt32 added in v0.5.6

func (ctx *Context) QueryInt32(key string, defaults ...int32) int32

QueryInt32 returns request form as int32 with default

func (*Context) QueryInt64 added in v0.5.6

func (ctx *Context) QueryInt64(key string, defaults ...int64) int64

QueryInt64 returns request form as int64 with default

func (*Context) QueryStrings added in v0.5.6

func (ctx *Context) QueryStrings(key string, defaults ...[]string) []string

QueryStrings returns request form as strings with default

func (*Context) QueryUint added in v0.5.6

func (ctx *Context) QueryUint(key string, defaults ...uint) uint

QueryUint returns request form as uint with default

func (*Context) QueryUint32 added in v0.5.6

func (ctx *Context) QueryUint32(key string, defaults ...uint32) uint32

QueryUint32 returns request form as uint32 with default

func (*Context) QueryUint64 added in v0.5.6

func (ctx *Context) QueryUint64(key string, defaults ...uint64) uint64

QueryUint64 returns request form as uint64 with default

func (*Context) Redirect

func (ctx *Context) Redirect(url string, status ...int)

Redirect redirects the request to another URL

func (*Context) Req

func (ctx *Context) Req() *http.Request

Req returns current HTTP Request information

func (*Context) Route

func (ctx *Context) Route() *Route

Route returns route

func (*Context) SaveToFile added in v0.4.3

func (ctx *Context) SaveToFile(formName, savePath string) error

SaveToFile saves the HTTP post file form to local file path

func (*Context) SecureCookies

func (ctx *Context) SecureCookies(secret string) Cookies

SecureCookies generates a secret cookie

func (*Context) ServeContent added in v0.5.6

func (ctx *Context) ServeContent(path string, fileSystem http.FileSystem) error

ServeContent serve content

func (*Context) ServeFile

func (ctx *Context) ServeFile(path string) error

ServeFile serves a file

func (*Context) ServeJSON added in v0.5.6

func (ctx *Context) ServeJSON(obj interface{}) error

ServeJSON serves marshaled JSON content from obj

func (*Context) ServeJson

func (ctx *Context) ServeJson(obj interface{}) error

ServeJson serves marshaled JSON content from obj Deprecated: use ServeJSON instead

func (*Context) ServeXML added in v0.5.6

func (ctx *Context) ServeXML(obj interface{}) error

ServeXML serves marshaled XML content from obj

func (*Context) ServeXml

func (ctx *Context) ServeXml(obj interface{}) error

ServeXml serves marshaled XML content from obj Deprecated: use ServeXML instead

func (*Context) SetRequest added in v0.5.6

func (ctx *Context) SetRequest(req *http.Request)

SetRequest sets the request to context

func (*Context) Unauthorized

func (ctx *Context) Unauthorized()

Unauthorized writes a 401 HTTP response

func (*Context) WriteString added in v0.5.6

func (ctx *Context) WriteString(content string) (int, error)

WriteString writes a string to response write

type Contexter

type Contexter interface {
	SetContext(*Context)
}

Contexter describes an interface to set *Context

type Cookies

type Cookies interface {
	Set
	Get(string) *http.Cookie
	Set(*http.Cookie)
	Expire(string, time.Time)
	Del(string)
}

Cookies describes cookie interface

type Ctx

type Ctx struct {
	*Context
}

Ctx implements Contexter

func (*Ctx) SetContext

func (c *Ctx) SetContext(ctx *Context)

SetContext set *Context to action struct

type DefaultLogger added in v0.5.6

type DefaultLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

func NewDefaultLogger added in v0.5.6

func NewDefaultLogger(out io.Writer) *DefaultLogger

NewLogger use the default logger with special writer

func (*DefaultLogger) Debug added in v0.5.6

func (t *DefaultLogger) Debug(v ...interface{})

func (*DefaultLogger) Debugf added in v0.5.6

func (t *DefaultLogger) Debugf(format string, v ...interface{})

func (*DefaultLogger) Debugln added in v0.5.6

func (t *DefaultLogger) Debugln(v ...interface{})

func (*DefaultLogger) Error added in v0.5.6

func (t *DefaultLogger) Error(v ...interface{})

func (*DefaultLogger) Errorf added in v0.5.6

func (t *DefaultLogger) Errorf(format string, v ...interface{})

func (*DefaultLogger) Errorln added in v0.5.6

func (t *DefaultLogger) Errorln(v ...interface{})

func (*DefaultLogger) Info added in v0.5.6

func (t *DefaultLogger) Info(v ...interface{})

func (*DefaultLogger) Infof added in v0.5.6

func (t *DefaultLogger) Infof(format string, v ...interface{})

func (*DefaultLogger) Infoln added in v0.5.6

func (t *DefaultLogger) Infoln(v ...interface{})

func (*DefaultLogger) SetLevel added in v0.5.6

func (t *DefaultLogger) SetLevel(level int)

func (*DefaultLogger) Warn added in v0.5.6

func (t *DefaultLogger) Warn(v ...interface{})

func (*DefaultLogger) Warnf added in v0.5.6

func (t *DefaultLogger) Warnf(format string, v ...interface{})

func (*DefaultLogger) Warnln added in v0.5.6

func (t *DefaultLogger) Warnln(v ...interface{})

type Deflate

type Deflate struct{}

Deflate implements deflate Compresser

func (Deflate) CompressType

func (Deflate) CompressType() string

CompressType returns compress type

type ErrorKeyIsNotExist added in v0.5.6

type ErrorKeyIsNotExist struct {
	Key string
}

func (ErrorKeyIsNotExist) Error added in v0.5.6

func (e ErrorKeyIsNotExist) Error() string

type ErrorWithCode added in v0.5.6

type ErrorWithCode interface {
	error
	ErrorCode() int
}

ErrorWithCode descripts an error that with error code

type Forms added in v0.4.6

type Forms http.Request

Forms a new enhancement of http.Request

func (*Forms) Bool added in v0.4.6

func (f *Forms) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Forms) Escape added in v0.4.8

func (f *Forms) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Forms) Float32 added in v0.4.6

func (f *Forms) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Forms) Float64 added in v0.4.6

func (f *Forms) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Forms) Int added in v0.4.6

func (f *Forms) Int(key string) (int, error)

Int returns request form as int

func (*Forms) Int32 added in v0.4.6

func (f *Forms) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Forms) Int64 added in v0.4.6

func (f *Forms) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Forms) MustBool added in v0.4.6

func (f *Forms) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Forms) MustEscape added in v0.4.8

func (f *Forms) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Forms) MustFloat32 added in v0.4.6

func (f *Forms) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Forms) MustFloat64 added in v0.4.6

func (f *Forms) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Forms) MustInt added in v0.4.6

func (f *Forms) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Forms) MustInt32 added in v0.4.6

func (f *Forms) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Forms) MustInt64 added in v0.4.6

func (f *Forms) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Forms) MustString added in v0.4.6

func (f *Forms) MustString(key string, defaults ...string) string

MustString returns request form as string with default

func (*Forms) MustStrings added in v0.4.8

func (f *Forms) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as strings with default

func (*Forms) MustUint added in v0.4.6

func (f *Forms) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Forms) MustUint32 added in v0.4.6

func (f *Forms) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Forms) MustUint64 added in v0.4.6

func (f *Forms) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Forms) String added in v0.4.6

func (f *Forms) String(key string) (string, error)

String returns request form as string

func (*Forms) Strings added in v0.4.8

func (f *Forms) Strings(key string) ([]string, error)

Strings returns request form as strings

func (*Forms) Uint added in v0.4.6

func (f *Forms) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Forms) Uint32 added in v0.4.6

func (f *Forms) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Forms) Uint64 added in v0.4.6

func (f *Forms) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

func (*Forms) Values added in v0.5.0

func (f *Forms) Values() url.Values

Values returns http.Request values

type GZip

type GZip struct{}

GZip implements gzip Compresser

func (GZip) CompressType

func (GZip) CompressType() string

CompressType returns compress type

type Group

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

Group defines a route group

func NewGroup

func NewGroup() *Group

NewGroup creates a route group

func (*Group) Any

func (g *Group) Any(url string, c interface{}, middlewares ...Handler)

Any addes the default mehtods route to this group

func (*Group) Delete

func (g *Group) Delete(url string, c interface{}, middlewares ...Handler)

Delete addes a DELETE route to this group

func (*Group) Get

func (g *Group) Get(url string, c interface{}, middlewares ...Handler)

Get addes a GET route to this group

func (*Group) Group

func (g *Group) Group(p string, o interface{}, handlers ...Handler)

Group defines group's child group

func (*Group) Head

func (g *Group) Head(url string, c interface{}, middlewares ...Handler)

Head addes a HEAD route to this group

func (*Group) Options

func (g *Group) Options(url string, c interface{}, middlewares ...Handler)

Options addes a OPTIONS route to this group

func (*Group) Patch

func (g *Group) Patch(url string, c interface{}, middlewares ...Handler)

Patch addes a PATCH route to this group

func (*Group) Post

func (g *Group) Post(url string, c interface{}, middlewares ...Handler)

Post addes a POST route to this group

func (*Group) Put

func (g *Group) Put(url string, c interface{}, middlewares ...Handler)

Put addes a PUT route to this group

func (*Group) Route

func (g *Group) Route(methods interface{}, url string, c interface{}, middlewares ...Handler)

Route defines a customerize route to this group

func (*Group) Trace

func (g *Group) Trace(url string, c interface{}, middlewares ...Handler)

Trace addes a TRACE route to this group

func (*Group) Use added in v0.2.9

func (g *Group) Use(handlers ...Handler)

Use set the middlewares to apply to this group's routes

type Handler

type Handler interface {
	Handle(*Context)
}

Handler defines middleware interface

type HandlerFunc

type HandlerFunc func(ctx *Context)

HandlerFunc describes the handle function

func Compresses

func Compresses(exts []string) HandlerFunc

Compresses defines a middleware to compress HTTP response

func Contexts

func Contexts() HandlerFunc

Contexts returns a middleware to inject Context to action struct

func Errors

func Errors() HandlerFunc

Errors returns default errorhandler, you can use your self handler

func Logging

func Logging() HandlerFunc

Logging returns handler to log informations

func Param

func Param() HandlerFunc

Param returns params handle to operate param

func Prefix added in v0.2.9

func Prefix(prefix string, handler Handler) HandlerFunc

Prefix provides a middleware to wrap another middleware with a prefix URL TODO: regex prefix

func Recovery

func Recovery(debug bool) HandlerFunc

Recovery returns a middleware which catch panics and log them

func Return

func Return() HandlerFunc

Return returns a tango middleware to handler return values

func Static

func Static(opts ...StaticOptions) HandlerFunc

Static return a middleware for serving static files

func WrapAfter

func WrapAfter(handler http.Handler) HandlerFunc

WrapAfter wraps a http standard handler to tango's after action executes

func WrapBefore

func WrapBefore(handler http.Handler) HandlerFunc

WrapBefore wraps a http standard handler to tango's before action executes

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(ctx *Context)

Handle executes the handler

type JSON added in v0.5.6

type JSON struct{}

JSON describes return JSON type

func (JSON) ResponseType added in v0.5.6

func (JSON) ResponseType() int

ResponseType implementes ResponseTyper

type Json

type Json struct{}

Json describes return JSON type Deprecated: use JSON instead

func (Json) ResponseType

func (Json) ResponseType() int

ResponseType implementes ResponseTyper

type Log

type Log struct {
	Logger
}

Log implementes LogInterface

func (*Log) SetLogger

func (l *Log) SetLogger(log Logger)

SetLogger implementes LogInterface

type LogInterface

type LogInterface interface {
	SetLogger(Logger)
}

LogInterface defines logger interface to inject logger to struct

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Debug(v ...interface{})
	Debugln(v ...interface{})
	Infof(format string, v ...interface{})
	Info(v ...interface{})
	Infoln(v ...interface{})
	Warnf(format string, v ...interface{})
	Warn(v ...interface{})
	Warnln(v ...interface{})
	Errorf(format string, v ...interface{})
	Error(v ...interface{})
	Errorln(v ...interface{})
}

Logger defines the logger interface for tango use

func NewCompositeLogger added in v0.5.6

func NewCompositeLogger(logs ...Logger) Logger

NewCompositeLogger creates a composite loggers

type Paramer

type Paramer interface {
	SetParams([]param)
}

Paramer defines an interface to get params

type Params

type Params []param

Params defines params of http request

func (*Params) Bool added in v0.4.6

func (p *Params) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Params) Escape added in v0.4.8

func (p *Params) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Params) Float32 added in v0.4.6

func (p *Params) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Params) Float64 added in v0.4.6

func (p *Params) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Params) Get added in v0.4.0

func (p *Params) Get(key string) string

Get returns request form as string

func (*Params) Int added in v0.4.6

func (p *Params) Int(key string) (int, error)

Int returns request form as int

func (*Params) Int32 added in v0.4.6

func (p *Params) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Params) Int64 added in v0.4.6

func (p *Params) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Params) MustBool added in v0.4.6

func (p *Params) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Params) MustEscape added in v0.4.8

func (p *Params) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Params) MustFloat32 added in v0.4.6

func (p *Params) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Params) MustFloat64 added in v0.4.6

func (p *Params) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Params) MustInt added in v0.4.6

func (p *Params) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Params) MustInt32 added in v0.4.6

func (p *Params) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Params) MustInt64 added in v0.4.6

func (p *Params) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Params) MustString added in v0.4.6

func (p *Params) MustString(key string, defaults ...string) string

MustString returns request form as slice of string with default

func (*Params) MustStrings added in v0.4.8

func (p *Params) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as slice of string with default

func (*Params) MustUint added in v0.4.6

func (p *Params) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Params) MustUint32 added in v0.4.6

func (p *Params) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Params) MustUint64 added in v0.4.6

func (p *Params) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Params) Set added in v0.4.2

func (p *Params) Set(key, value string)

Set sets key/value to params

func (*Params) SetParams

func (p *Params) SetParams(params []param)

SetParams implemented Paramer

func (*Params) String added in v0.4.6

func (p *Params) String(key string) (string, error)

String returns request form as string

func (*Params) Strings added in v0.4.8

func (p *Params) Strings(key string) ([]string, error)

Strings returns request form as slice of string

func (*Params) Uint added in v0.4.6

func (p *Params) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Params) Uint32 added in v0.4.6

func (p *Params) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Params) Uint64 added in v0.4.6

func (p *Params) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

type Queries added in v0.5.6

type Queries http.Request

Queries a new enhancement of http.Request

func (*Queries) Bool added in v0.5.6

func (f *Queries) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Queries) Escape added in v0.5.6

func (f *Queries) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Queries) Float32 added in v0.5.6

func (f *Queries) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Queries) Float64 added in v0.5.6

func (f *Queries) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Queries) Int added in v0.5.6

func (f *Queries) Int(key string) (int, error)

Int returns request form as int

func (*Queries) Int32 added in v0.5.6

func (f *Queries) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Queries) Int64 added in v0.5.6

func (f *Queries) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Queries) MustBool added in v0.5.6

func (f *Queries) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Queries) MustEscape added in v0.5.6

func (f *Queries) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Queries) MustFloat32 added in v0.5.6

func (f *Queries) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Queries) MustFloat64 added in v0.5.6

func (f *Queries) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Queries) MustInt added in v0.5.6

func (f *Queries) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Queries) MustInt32 added in v0.5.6

func (f *Queries) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Queries) MustInt64 added in v0.5.6

func (f *Queries) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Queries) MustString added in v0.5.6

func (f *Queries) MustString(key string, defaults ...string) string

MustString returns request form as string with default

func (*Queries) MustStrings added in v0.5.6

func (f *Queries) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as strings with default

func (*Queries) MustUint added in v0.5.6

func (f *Queries) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Queries) MustUint32 added in v0.5.6

func (f *Queries) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Queries) MustUint64 added in v0.5.6

func (f *Queries) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Queries) String added in v0.5.6

func (f *Queries) String(key string) (string, error)

String returns request form as string

func (*Queries) Strings added in v0.5.6

func (f *Queries) Strings(key string) ([]string, error)

Strings returns request form as strings

func (*Queries) Uint added in v0.5.6

func (f *Queries) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Queries) Uint32 added in v0.5.6

func (f *Queries) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Queries) Uint64 added in v0.5.6

func (f *Queries) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

func (*Queries) Values added in v0.5.6

func (f *Queries) Values() url.Values

Values returns http.Request values

type ResponseTyper

type ResponseTyper interface {
	ResponseType() int
}

ResponseTyper describes reponse type

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	http.Hijacker
	// Status returns the status code of the response or 0 if the response has not been written.
	Status() int
	// Written returns whether or not the ResponseWriter has been written.
	Written() bool
	// Size returns the size of the response body.
	Size() int
}

ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.

type Route

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

Route defines HTTP route

func NewRoute

func NewRoute(v interface{}, t reflect.Type,
	method reflect.Value, tp RouteType, handlers []Handler) *Route

NewRoute returns a route

func (*Route) IsStruct

func (r *Route) IsStruct() bool

IsStruct returns if the execute is a struct

func (*Route) Method

func (r *Route) Method() reflect.Value

Method returns finalize execute method.

func (*Route) Raw added in v0.4.6

func (r *Route) Raw() interface{}

Raw returns raw data to define route.

func (*Route) RouteType

func (r *Route) RouteType() RouteType

RouteType returns route type.

type RouteType

type RouteType byte

RouteType defines route types

const (
	FuncRoute         RouteType = iota + 1 // 1 func ()
	FuncHTTPRoute                          // 2 func (http.ResponseWriter, *http.Request)
	FuncReqRoute                           // 3 func (*http.Request)
	FuncResponseRoute                      // 4 func (http.ResponseWriter)
	FuncCtxRoute                           // 5 func (*tango.Context)
	StructRoute                            // 6 func (st) <Get>()
	StructPtrRoute                         // 7 func (*struct) <Get>()
)

enumerates route types

type Router

type Router interface {
	Route(methods interface{}, path string, handler interface{}, middlewares ...Handler)
	Match(requestPath, method string) (*Route, Params)
}

Router describes the interface of route

type Set added in v0.4.6

type Set interface {
	String(key string) (string, error)
	Int(key string) (int, error)
	Int32(key string) (int32, error)
	Int64(key string) (int64, error)
	Uint(key string) (uint, error)
	Uint32(key string) (uint32, error)
	Uint64(key string) (uint64, error)
	Float32(key string) (float32, error)
	Float64(key string) (float64, error)
	Bool(key string) (bool, error)

	MustString(key string, defaults ...string) string
	MustEscape(key string, defaults ...string) string
	MustInt(key string, defaults ...int) int
	MustInt32(key string, defaults ...int32) int32
	MustInt64(key string, defaults ...int64) int64
	MustUint(key string, defaults ...uint) uint
	MustUint32(key string, defaults ...uint32) uint32
	MustUint64(key string, defaults ...uint64) uint64
	MustFloat32(key string, defaults ...float32) float32
	MustFloat64(key string, defaults ...float64) float64
	MustBool(key string, defaults ...bool) bool
}

Set describes a set interface

type StaticOptions

type StaticOptions struct {
	RootPath   string
	Prefix     string
	IndexFiles []string
	ListDir    bool
	FilterExts []string
	// FileSystem is the interface for supporting any implmentation of file system.
	FileSystem http.FileSystem
}

StaticOptions defines Static middleware's options

func (*StaticOptions) IsFilterExt added in v0.5.6

func (s *StaticOptions) IsFilterExt(rPath string) bool

IsFilterExt decribes if rPath's ext match filter ext

type StatusResult added in v0.4.8

type StatusResult struct {
	Code   int
	Result interface{}
}

StatusResult describes http response

type Tango

type Tango struct {
	http.Server
	Router

	ErrHandler Handler
	// contains filtered or unexported fields
}

Tango describes tango object

func Classic

func Classic(l ...Logger) *Tango

Classic returns the tango with default handlers and logger

func New

func New(handlers ...Handler) *Tango

New creates tango with the default logger and handlers

func NewWithLog

func NewWithLog(logger Logger, handlers ...Handler) *Tango

NewWithLog creates tango with the special logger and handlers

func (*Tango) Any

func (t *Tango) Any(url string, c interface{}, middlewares ...Handler)

Any sets a route every support method is OK.

func (*Tango) Delete

func (t *Tango) Delete(url string, c interface{}, middlewares ...Handler)

Delete sets a route with DELETE method

func (*Tango) Get

func (t *Tango) Get(url string, c interface{}, middlewares ...Handler)

Get sets a route with GET method

func (*Tango) Group

func (t *Tango) Group(p string, o interface{}, handlers ...Handler)

Group adds routines groups

func (*Tango) Head

func (t *Tango) Head(url string, c interface{}, middlewares ...Handler)

Head sets a route with HEAD method

func (*Tango) Logger

func (t *Tango) Logger() Logger

Logger returns logger interface

func (*Tango) Options

func (t *Tango) Options(url string, c interface{}, middlewares ...Handler)

Options sets a route with OPTIONS method

func (*Tango) Patch

func (t *Tango) Patch(url string, c interface{}, middlewares ...Handler)

Patch sets a route with PATCH method

func (*Tango) Post

func (t *Tango) Post(url string, c interface{}, middlewares ...Handler)

Post sets a route with POST method

func (*Tango) Put

func (t *Tango) Put(url string, c interface{}, middlewares ...Handler)

Put sets a route with PUT method

func (*Tango) Run

func (t *Tango) Run(args ...interface{})

Run the http server. Listening on os.GetEnv("PORT") or 8000 by default.

func (*Tango) RunTLS

func (t *Tango) RunTLS(certFile, keyFile string, args ...interface{})

RunTLS runs the https server with special cert and key files

func (*Tango) ServeHTTP

func (t *Tango) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implementes net/http interface so that it could run with net/http

func (*Tango) Trace

func (t *Tango) Trace(url string, c interface{}, middlewares ...Handler)

Trace sets a route with TRACE method

func (*Tango) Use

func (t *Tango) Use(handlers ...Handler)

Use addes some global handlers

func (*Tango) UseHandler

func (t *Tango) UseHandler(handler http.Handler)

UseHandler adds a standard http handler to tango's

type XML added in v0.5.6

type XML struct{}

XML descirbes return XML type

func (XML) ResponseType added in v0.5.6

func (XML) ResponseType() int

ResponseType implementes ResponseTyper

type XMLError added in v0.5.6

type XMLError struct {
	XMLName xml.Name `xml:"err"`
	Content string   `xml:"content"`
}

XMLError describes return xml error

type XMLString added in v0.5.6

type XMLString struct {
	XMLName xml.Name `xml:"string"`
	Content string   `xml:"content"`
}

XMLString describes return xml string

type Xml

type Xml struct{}

Xml descirbes return XML type Deprecated: use XML instead

func (Xml) ResponseType

func (Xml) ResponseType() int

ResponseType implementes ResponseTyper

Jump to

Keyboard shortcuts

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