web

package module
v0.0.0-...-e8c4747 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

Generate https tls cert/key file

go run  $GOROOT/src/crypto/tls/generate_cert.go --host localhost

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveFile

func SaveFile(fh *multipart.FileHeader, path string, name ...string) (string, int64, error)

SaveFile save file to disk

Types

type BaseHandler

type BaseHandler struct {
}

BaseHandler base httphandler

func (*BaseHandler) CONNECT

func (handle *BaseHandler) CONNECT(ctx *Context)

CONNECT method

func (*BaseHandler) DELETE

func (handle *BaseHandler) DELETE(ctx *Context)

DELETE method

func (*BaseHandler) Finish

func (*BaseHandler) Finish(*Context)

Finish finish

func (*BaseHandler) GET

func (handle *BaseHandler) GET(ctx *Context)

GET method

func (*BaseHandler) HEAD

func (handle *BaseHandler) HEAD(ctx *Context)

HEAD method

func (*BaseHandler) Init

func (*BaseHandler) Init(*Context)

Init init

func (*BaseHandler) OPTIONS

func (handle *BaseHandler) OPTIONS(ctx *Context)

OPTIONS method

func (*BaseHandler) PATCH

func (handle *BaseHandler) PATCH(ctx *Context)

PATCH method

func (*BaseHandler) POST

func (handle *BaseHandler) POST(ctx *Context)

POST method

func (*BaseHandler) PUT

func (handle *BaseHandler) PUT(ctx *Context)

PUT method

func (*BaseHandler) Prepare

func (*BaseHandler) Prepare(*Context)

Prepare prepare

func (*BaseHandler) TRACE

func (handle *BaseHandler) TRACE(ctx *Context)

TRACE method

type Context

type Context struct {
	http.ResponseWriter
	*http.Request

	Timestamp time.Time
	log.Logger
	// contains filtered or unexported fields
}

Context context

func (*Context) Download

func (ctx *Context) Download(filename string, header map[string]string)

Download support download file

func (*Context) Error

func (ctx *Context) Error(statusCode int)

Error response error

func (*Context) GetCookie

func (ctx *Context) GetCookie(name string) string

GetCookie get cookie

func (*Context) GetCookies

func (ctx *Context) GetCookies() []*http.Cookie

GetCookies get cookies

func (*Context) GetForm

func (ctx *Context) GetForm() (map[string]string, map[string]*multipart.FileHeader, error)

GetForm formdata, Content-Type must be multipart/form-data. TODO: RemoveAll removes any temporary files associated with a Form.

func (*Context) GetHeader

func (ctx *Context) GetHeader(key string, v ...string) string

func (*Context) GetJSONBody

func (ctx *Context) GetJSONBody(v interface{}) error

GetJSONBody get json body args

func (*Context) GetQuery

func (ctx *Context) GetQuery() map[string]string

GetQuery get query

func (*Context) IsFinish

func (ctx *Context) IsFinish() bool

IsFinish return handle is closed or not

func (*Context) JSON

func (ctx *Context) JSON(v interface{}, code int, err error)

JSON json api

func (*Context) RecvFile

func (ctx *Context) RecvFile(name string, path string) (string, int64, error)

RecvFile recv file

func (*Context) RecvFile2

func (ctx *Context) RecvFile2(name string, path string) error

RecvFile2 recvfile2

func (*Context) RecvFormFile

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

RecvFormFile recv form file

func (*Context) Redirect

func (ctx *Context) Redirect(url string, statusCode int)

Redirect response redirect

func (*Context) Remote

func (ctx *Context) Remote() string

Remote return request addr, copied from net/url.stripPort

func (*Context) Render

func (ctx *Context) Render(tpl string, data interface{})

Render render template no cache

func (*Context) SetStatusCode

func (ctx *Context) SetStatusCode(statusCode int)

func (*Context) Text

func (ctx *Context) Text(response []byte)

Text return resp with text format

type Entry

type Entry struct {
	MyInterface Handler
	// contains filtered or unexported fields
}

Entry route entry point

type Handler

type Handler interface {
	Init(*Context)
	Prepare(*Context)
	CONNECT(*Context)
	OPTIONS(*Context)
	HEAD(*Context)
	GET(*Context)
	POST(*Context)
	DELETE(*Context)
	PUT(*Context)
	TRACE(*Context)
	PATCH(*Context)
	Finish(*Context)
}

Handler interface

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc handler func

func (HandlerFunc) CONNECT

func (f HandlerFunc) CONNECT(ctx *Context)

CONNECT CONNECT

func (HandlerFunc) DELETE

func (f HandlerFunc) DELETE(ctx *Context)

DELETE DELETE

func (HandlerFunc) Finish

func (f HandlerFunc) Finish(ctx *Context)

Finish Finish

func (HandlerFunc) GET

func (f HandlerFunc) GET(ctx *Context)

GET GET

func (HandlerFunc) HEAD

func (f HandlerFunc) HEAD(ctx *Context)

HEAD HEAD

func (HandlerFunc) Init

func (f HandlerFunc) Init(ctx *Context)

Init init

func (HandlerFunc) OPTIONS

func (f HandlerFunc) OPTIONS(ctx *Context)

OPTIONS OPTIONS

func (HandlerFunc) PATCH

func (f HandlerFunc) PATCH(ctx *Context)

PATCH PATCH

func (HandlerFunc) POST

func (f HandlerFunc) POST(ctx *Context)

POST POST

func (HandlerFunc) PUT

func (f HandlerFunc) PUT(ctx *Context)

PUT PUT

func (HandlerFunc) Prepare

func (f HandlerFunc) Prepare(ctx *Context)

Prepare Prepare

func (HandlerFunc) TRACE

func (f HandlerFunc) TRACE(ctx *Context)

TRACE TRACE

type Multiplexer

type Multiplexer []*Entry

Multiplexer mux

func NewMultiplexer

func NewMultiplexer() Multiplexer

NewMultiplexer new mux

func (Multiplexer) FindRoute

func (mux Multiplexer) FindRoute(path string) *Entry

FindRoute find router

func (*Multiplexer) Handle

func (mux *Multiplexer) Handle(path string, handler http.Handler)

Handle std http handle

func (*Multiplexer) HandleFunc

func (mux *Multiplexer) HandleFunc(path string, f http.HandlerFunc)

HandleFunc handlefunc

func (*Multiplexer) Route

func (mux *Multiplexer) Route(path string, handler Handler)

Route handle

func (*Multiplexer) RouteFunc

func (mux *Multiplexer) RouteFunc(path string, f HandlerFunc)

RouteFunc route handlerFunc

func (Multiplexer) String

func (mux Multiplexer) String() string

type Option

type Option func(*Options)

Option func

func Address

func Address(addr string) Option

Address address

func StaticPath

func StaticPath(urlpath string, webpath ...string) Option

StaticPath StaticPath

type Options

type Options struct {
	Address           string `yaml:"address" json:"address,omitempty"`
	CertFile          string
	KeyFile           string
	ReadTimeout       int
	ReadHeaderTimeout int
	WriteTimeout      int
	IdleTimeout       int
	MaxHeaderBytes    int
	StaticPaths       map[string]string //静态文件路径头 strings.Trim(path, staticPath)
}

Options options

type Web

type Web struct {
	Log  log.Logger
	Mids []func(*Context)
	Mux  Multiplexer
	*http.Server
	sync.Pool
	// contains filtered or unexported fields
}

Web service

func New

func New(opts ...Option) *Web

New new service

func (*Web) Close

func (s *Web) Close() error

Close close

func (*Web) DebugPprof

func (s *Web) DebugPprof()

DebugPprof debugPprof

func (*Web) Handle

func (s *Web) Handle(path string, handler http.Handler)

Handle http handle

func (*Web) HandleFs

func (s *Web) HandleFs(srtipPath, path string)

HandleFs filesystem

func (*Web) HandleFunc

func (s *Web) HandleFunc(path string, f http.HandlerFunc)

HandleFunc http Handle func

func (*Web) Init

func (s *Web) Init(opts ...Option)

Init initialises options.

func (*Web) Load

func (s *Web) Load(v interface{}) error

Load load config

func (*Web) Route

func (s *Web) Route(path string, handle Handler)

Route handle

func (*Web) RouteFunc

func (s *Web) RouteFunc(path string, f HandlerFunc)

RouteFunc route handlerfunc

func (*Web) Run

func (s *Web) Run(ctx context.Context) error

Run run

func (*Web) ServeHTTP

func (s *Web) ServeHTTP(resp http.ResponseWriter, req *http.Request)

func (*Web) SetLog

func (s *Web) SetLog(log log.Logger)

SetLog set log

func (*Web) String

func (s *Web) String() string

func (*Web) Use

func (s *Web) Use(f ...func(*Context))

Use append middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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