web

package
v0.0.0-...-dddd691 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Err_Abort = errors.New("Abort by you")

	MaxStaticFileSize int64 = 1024 * 1024 * 10 // 10m
	StreamBuffSize          = 4096
	ReadTimeout             = time.Second * 600
	WriteTimeout            = time.Second * 600

	DefaultServer = &HttpServer{IsLog: true}

	XmlParser func([]byte) (map[string]interface{}, error) = nil

	Err_HandleMetUnimplemented = errors.New("The handle method is not implemented")
)

Functions

func AddFileRouter

func AddFileRouter(routerName, folder string, filter func([]string, os.FileInfo) bool)

func AddGZipStaticRouter

func AddGZipStaticRouter(routerName, folder string, openCache bool, suffixes ...string)

func AddRouter

func AddRouter(httpPath string, handlerBuilder func() IHandler)

func AddStaticRouter

func AddStaticRouter(routerName, folder string)

func AsyncRun

func AsyncRun(port int) chan error

func GZipCompress

func GZipCompress(bs []byte) []byte

func GZipUncompress

func GZipUncompress(bs []byte) (res []byte, e error)

func HandleException

func HandleException(msg string)

func RouterRunWithTimeout

func RouterRunWithTimeout(port int, readTimeout, writeTimeout time.Duration) error

func Run

func Run(port int) error

func SetTplDir

func SetTplDir(folder string)

func URLDecode

func URLDecode(s string) string

func URLEncode

func URLEncode(s string) string

Types

type Handler

type Handler struct {
	Writer  http.ResponseWriter
	Request *http.Request

	Method string

	ResCode    int
	ResHeaders map[string][]string
	ResData    interface{}
	// contains filtered or unexported fields
}

func (*Handler) GetBody

func (this *Handler) GetBody() (body []byte)

func (*Handler) GetFileParam

func (this *Handler) GetFileParam(key string) (f *MultipartFileData)

func (*Handler) GetFileParams

func (this *Handler) GetFileParams() map[string]*MultipartFileData

func (*Handler) GetGetParam

func (this *Handler) GetGetParam(key string) (res string)

func (*Handler) GetGetParamMap

func (this *Handler) GetGetParamMap() map[string]string

func (*Handler) GetHeader

func (this *Handler) GetHeader(key string) string

func (*Handler) GetHeaderArr

func (this *Handler) GetHeaderArr(key string) []string

func (*Handler) GetHeaders

func (this *Handler) GetHeaders() map[string][]string

func (*Handler) GetIO

func (this *Handler) GetIO() (*http.Request, http.ResponseWriter)

func (*Handler) GetPostIntParam

func (this *Handler) GetPostIntParam(key string, defaultVal int) int

func (*Handler) GetPostParam

func (this *Handler) GetPostParam(key string) (value interface{})

func (*Handler) GetPostParams

func (this *Handler) GetPostParams() map[string]interface{}

func (*Handler) GetPostStrParam

func (this *Handler) GetPostStrParam(key string) (value string)

func (*Handler) GetRouterPath

func (this *Handler) GetRouterPath() []string

func (*Handler) GetRouterPathAt

func (this *Handler) GetRouterPathAt(index int) string

func (*Handler) Handle

func (this *Handler) Handle()

func (*Handler) IP

func (this *Handler) IP() (ip string)

func (*Handler) NoResponse

func (this *Handler) NoResponse()

func (*Handler) ParseParams

func (this *Handler) ParseParams(pointer interface{}) error

func (*Handler) Prepare

func (this *Handler) Prepare()

func (*Handler) Redirect

func (this *Handler) Redirect(code int, url string)

func (*Handler) ResponseAccessCrossOrigin

func (this *Handler) ResponseAccessCrossOrigin(headers map[string][]string, allowHeaders, exposeHeaders []string)

func (*Handler) ResponseData

func (this *Handler) ResponseData(data interface{})

func (*Handler) ResponseHeaders

func (this *Handler) ResponseHeaders(headers map[string][]string)

func (*Handler) ResponseNothing

func (this *Handler) ResponseNothing() bool

func (*Handler) ResponseOK

func (this *Handler) ResponseOK()

func (*Handler) ResponseStatus

func (this *Handler) ResponseStatus(code int)

func (*Handler) SetStatus

func (this *Handler) SetStatus(status int)

func (*Handler) StopRun

func (this *Handler) StopRun()

func (*Handler) Tpl

func (this *Handler) Tpl(fileName string, datas interface{}, subTpls ...string) (e error)

func (*Handler) WriteString

func (this *Handler) WriteString(msg string)

type HttpServer

type HttpServer struct {
	IsLog bool
	// contains filtered or unexported fields
}

func (*HttpServer) AddFileRouter

func (this *HttpServer) AddFileRouter(routerName, folder string, filter func([]string, os.FileInfo) bool)

func (*HttpServer) AddGZipStaticRouter

func (this *HttpServer) AddGZipStaticRouter(routerName, folder string, openCache bool, suffixes ...string)

func (*HttpServer) AddRouter

func (this *HttpServer) AddRouter(httpPath string, handlerBuilder func() IHandler)

func (*HttpServer) AddStaticRouter

func (this *HttpServer) AddStaticRouter(routerName, folder string)

func (*HttpServer) AsyncRun

func (this *HttpServer) AsyncRun(port int) chan error

func (*HttpServer) Close

func (this *HttpServer) Close() error

func (*HttpServer) RouterRunWithTimeout

func (this *HttpServer) RouterRunWithTimeout(port int, readTimeout, writeTimeout time.Duration) error

func (*HttpServer) Run

func (this *HttpServer) Run(port int) error

type IHandler

type IHandler interface {
	GetIO() (*http.Request, http.ResponseWriter)
	Prepare()
	Handle()
	IP() string

	ResponseNothing() bool
	ResponseOK()
	ResponseStatus(code int)
	ResponseHeaders(headers map[string][]string)
	ResponseData(data interface{})
	// contains filtered or unexported methods
}

type MultipartFileData

type MultipartFileData struct {
	Content     []byte
	FileName    string
	ContentType string
}

type Stream

type Stream struct {
	Reader   io.ReadCloser
	BuffSize int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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