app

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 47 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AutoIndex = FileServerType(iota)
	DirDeny

	TraceName = "X-OR-TRACE-ID"
)
View Source
const DefaultTempDir = "/tmp"

nacos配置中心,注册中心支持

Variables

View Source
var (
	NotFoundHandler = func(c *Context) error {
		c.responseStatus = http.StatusNotFound
		c.responseBody.Write([]byte("Not Found"))
		c.response.Header().Set("Content-Type", "text/plain; charset=utf-8")
		c.response.Header().Set("X-Content-Type-Options", "nosniff")
		return nil
	}
	MethodNotAllowedHandler = func(c *Context) error {
		c.responseStatus = http.StatusMethodNotAllowed
		c.responseBody.Write([]byte("Method Not Allowed"))
		c.response.Header().Set("Content-Type", "text/plain; charset=utf-8")
		c.response.Header().Set("X-Content-Type-Options", "nosniff")
		return nil
	}
)

Error handlers

Functions

func AppDefer

func AppDefer(deferFun ...func())

AppDefer 应用退出后置操作

func AppStart

func AppStart(client ClientSrv)

启动应用

func ConsoleStart added in v0.3.1

func ConsoleStart(srv JobSrv)

ConsoleStart 独立启动控制台应用

func ExitWaitFunDo

func ExitWaitFunDo(doFun func())

ExitWaitFunDo 退出后等待处理完成

func HttpForbidden added in v0.2.15

func HttpForbidden(w http.ResponseWriter, r *http.Request)

HttpForbidden replies to the request with an HTTP 403 Forbidden error.

func HttpNotFound added in v0.2.15

func HttpNotFound(w http.ResponseWriter, r *http.Request)

HttpNotFound replies to the request with an HTTP 404 not found error.

func JobRun added in v0.3.1

func JobRun(jobName string, runDo JobFunc, timeout time.Duration)

JobRun 注册一个控制台任务

func ListenStop

func ListenStop(stopSig chan StopSignal)

ListenStop 订阅app退出信号

func NewAssetsHandler added in v0.2.15

func NewAssetsHandler(patten string, filePath string, autoindex FileServerType)

func NewHttpHandler added in v0.2.11

func NewHttpHandler(patten string, handler http.Handler)

NewHttpHandler 新增自定义 httpHandler

func NewNacosSrv added in v0.3.1

func NewNacosSrv()

func ParseForm

func ParseForm(form url.Values, obj interface{}) error

ParseForm will parse form values to struct via tag.

func ParseJson

func ParseJson(jsonByte []byte, obj interface{}) error

Types

type ClientSrv added in v0.3.1

type ClientSrv interface {
	Register()
}

ClientSrv http应用注册接口

type Context

type Context struct {
	CsrfToken   string
	OrangeInput *request.OrangeInput
	// contains filtered or unexported fields
}

func NewCtx

func NewGrpcCtx added in v0.5.1

func NewGrpcCtx(ctx context.Context) *Context

func (*Context) AddDelayAfterDo added in v0.2.3

func (c *Context) AddDelayAfterDo(handlerFunc func(ctx *Context), delay time.Duration)

func (*Context) AddIncludeTmpl added in v0.1.9

func (c *Context) AddIncludeTmpl(viewName string)

AddIncludeTmpl添加引入模版

func (*Context) AppUpload

func (c *Context) AppUpload(formName string) (savePath string, err error)

AppUpload 匹配配置文件中的大小限制和扩展名限制

func (*Context) AppUploadSubPath added in v0.5.13

func (c *Context) AppUploadSubPath(formName, baseDir string) (savePath string, err error)

AppUploadSubPath 指定子目录存储上传文件

func (*Context) AppUploadToData added in v0.1.12

func (c *Context) AppUploadToData(formName string) (*UploadFile, error)

AppUploadToData 将上传后的文件返回 []byte 数据

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) GetCtxParam

func (c *Context) GetCtxParam(key string) (val interface{})

func (*Context) GetMs added in v0.2.12

func (c *Context) GetMs() time.Duration

func (*Context) GetMysql added in v0.5.11

func (c *Context) GetMysql(dbName string) (db *gorm.DB, err error)

GetMysql 上下文中获取MySQL连接

func (*Context) GetPathParam added in v0.2.3

func (c *Context) GetPathParam(name string) (val string)

func (*Context) GetPathParamToInt added in v0.2.3

func (c *Context) GetPathParamToInt(name string) (val int)

func (*Context) GetRedis added in v0.5.11

func (c *Context) GetRedis(dbName string) (db redis.Conn, err error)

GetRedis 上下文中获取Redis连接

func (*Context) Header

func (c *Context) Header() http.Header

func (*Context) HttpError added in v0.1.3

func (c *Context) HttpError(error string, code int)

func (*Context) Input

func (c *Context) Input() url.Values

Input returns the input data map from POST or PUT request body and query string.

func (*Context) ParseForm

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

ParseForm maps input data map to obj struct.

func (*Context) PromeIncServiceErr added in v0.4.0

func (c *Context) PromeIncServiceErr(serviceName string)

PromeIncServiceErr 服务异常报错写入Prometheus

func (*Context) Redirect added in v0.1.9

func (c *Context) Redirect(tourl string) error

func (*Context) Request

func (c *Context) Request() *http.Request

func (*Context) ResponseBody added in v0.2.3

func (c *Context) ResponseBody() []byte

func (*Context) ResponseHeader

func (c *Context) ResponseHeader() http.Header

func (*Context) ResponseReset added in v0.1.4

func (c *Context) ResponseReset()

func (*Context) ResponseStatus added in v0.2.12

func (c *Context) ResponseStatus() int

func (*Context) ResponseWrite

func (c *Context) ResponseWrite(b []byte) error

func (*Context) ResponseWriteHeader added in v0.1.3

func (c *Context) ResponseWriteHeader(code int)

func (*Context) RoutePath added in v0.2.10

func (c *Context) RoutePath() string

func (*Context) RunHttpHandler added in v0.5.6

func (c *Context) RunHttpHandler(h http.Handler)

RunHttpHandler 执行自定义 http handler

func (*Context) Session

func (c *Context) Session() session.Store

func (*Context) SetContext added in v0.2.9

func (c *Context) SetContext(ctx context.Context) context.Context

func (*Context) SetCookie

func (c *Context) SetCookie(cookie *http.Cookie)

func (*Context) SetCtxParam

func (c *Context) SetCtxParam(key string, value interface{})

func (*Context) SetPanic added in v0.2.13

func (c *Context) SetPanic(panicMsg interface{})

func (*Context) SetRW

func (c *Context) SetRW(w http.ResponseWriter, r *http.Request)

func (*Context) SetResponseStatus added in v0.2.13

func (c *Context) SetResponseStatus(status int)

func (*Context) ShareAssign added in v0.1.9

func (c *Context) ShareAssign(key string, viewData interface{})

ShareAssign 全局通用模板变量

func (*Context) ShouldBind added in v0.2.25

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

ShouldBind is an alias for ParseForm

func (*Context) ToFile added in v0.2.15

func (c *Context) ToFile(filePath string, fileName string) error

通过文件流方式输出

func (*Context) ToImage added in v0.2.15

func (c *Context) ToImage(filePath string) error

通过文件流方式输出图片

func (*Context) ToJson

func (c *Context) ToJson(data interface{}) error

func (*Context) ToString

func (c *Context) ToString(data string) error

func (*Context) UploadFromFile

func (c *Context) UploadFromFile(formName string, saveDir string, verifyFunc func(file *UploadFile) error) (fileName string, err error)

UploadFromFile

func (*Context) UploadFromFileToData added in v0.1.12

func (c *Context) UploadFromFileToData(formName string, saveDir string, verifyFunc func(file *UploadFile) error) (fileInfo *UploadFile, err error)

UploadFromFileToData

func (*Context) ViewHtml added in v0.1.4

func (c *Context) ViewHtml(viewName string, viewDatas ...interface{}) error

ViewHtml 快速渲染html视图

func (*Context) ViewText added in v0.1.4

func (c *Context) ViewText(viewName string, viewDatas ...interface{}) error

ViewHtml 快速渲染text视图

type ErrNoFile

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

func (ErrNoFile) Error

func (e ErrNoFile) Error() string

type FileServerType added in v0.2.15

type FileServerType int

type HandlerFunc

type HandlerFunc func(*Context) error

type HttpSrv added in v0.3.1

type HttpSrv interface {
	ServeMux()
	Register()
}

HttpSrv http应用注册接口

type Job added in v0.3.1

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

func (*Job) AppendJob added in v0.3.1

func (j *Job) AppendJob(jobName string, handler JobHandler)

AppendJob

func (*Job) GetJob added in v0.3.1

func (j *Job) GetJob(jobName string) (handler JobHandler, err error)

GetJob

type JobFunc added in v0.3.1

type JobFunc func(ctx *context.Context) error

type JobHandler added in v0.3.1

type JobHandler struct {
	Action  JobFunc
	Timeout time.Duration
}

type JobSrv added in v0.3.1

type JobSrv interface {
	JobDispatch()
	Register()
}

JobSrv 控制台任务应用注册接口

type MiddleWare

type MiddleWare interface {
	Func() MiddlewareFunc
}

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc defines a function to process middleware.

type OrangeServer added in v0.1.6

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

func NewSrv added in v0.1.6

func NewSrv(httpSrv *http.Server) *OrangeServer

func (*OrangeServer) AppListenAndServe added in v0.1.6

func (app *OrangeServer) AppListenAndServe() error

func (*OrangeServer) GetListener added in v0.1.6

func (app *OrangeServer) GetListener() *net.TCPListener

func (*OrangeServer) GrpcListenAndStart added in v0.5.1

func (app *OrangeServer) GrpcListenAndStart() (err error)

GrpcListenAndStart 启动通用grpc服务

func (*OrangeServer) GrpcShutDown added in v0.5.1

func (app *OrangeServer) GrpcShutDown()

OrangeServer_GrpcShutDown 关闭grpc服务

func (*OrangeServer) ShutdownDo added in v0.1.6

func (app *OrangeServer) ShutdownDo(ctx context.Context) error

type Router added in v0.2.3

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

func (*Router) Find added in v0.2.3

func (r *Router) Find(method, path string, ctx *Context) (httpHandler HandlerFunc, httpMiddleware []MiddleWare)

Find 路由查找匹配到符合条件的url

type RouterGroup added in v0.2.3

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

func NewRouter

func NewRouter(prefix string, middlewares ...MiddleWare) *RouterGroup

func (*RouterGroup) ALL added in v0.2.3

func (r *RouterGroup) ALL(patten string, handler func(ctx *Context) error)

ALL 兼容所有请求

func (*RouterGroup) ASSETS added in v0.2.15

func (r *RouterGroup) ASSETS(patten string, fielPath string, autoindex FileServerType)

Assets 注册静态资源目录

func (*RouterGroup) DELETE added in v0.2.3

func (r *RouterGroup) DELETE(patten string, handler func(ctx *Context) error)

DELETE 注册 delete 请求

func (*RouterGroup) GET added in v0.2.3

func (r *RouterGroup) GET(patten string, handler func(ctx *Context) error)

GET 注册 get 请求

func (*RouterGroup) GRPC added in v0.5.1

func (r *RouterGroup) GRPC(patten string, handler func(ctx *Context) error)

GRPC 注册 grpc 请求,只有grpc客户端才能调用

func (*RouterGroup) GroupRouter added in v0.2.3

func (r *RouterGroup) GroupRouter(prefix string, middlewares ...MiddleWare) *RouterGroup

GroupRouter 子群组路由

func (*RouterGroup) OPTION added in v0.2.21

func (r *RouterGroup) OPTION(patten string, handler func(ctx *Context) error)

OPTION 注册 option 请求

func (*RouterGroup) PATCH added in v0.3.3

func (r *RouterGroup) PATCH(patten string, handler func(ctx *Context) error)

PATCH 注册 patch 请求

func (*RouterGroup) POST added in v0.2.3

func (r *RouterGroup) POST(patten string, handler func(ctx *Context) error)

POST 注册 post 请求

func (*RouterGroup) PUT added in v0.2.3

func (r *RouterGroup) PUT(patten string, handler func(ctx *Context) error)

PUT 注册 put 请求

type StopSignal

type StopSignal int32

type UploadFile

type UploadFile struct {
	FileName  string
	Extension string
	FileSize  int64
	FileByte  []byte
	SavePath  string
}

Jump to

Keyboard shortcuts

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