1 Star 1 Fork 2

kristas / booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
def.go 3.13 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-07-28 17:48 . refactor
package web
import (
"context"
"gitee.com/kristas/booting-go/framework/core/bean"
"mime/multipart"
"net/http"
"reflect"
)
type Rest struct{}
type FS struct{}
type Container interface {
bean.Bean
RestHandler() RestHandler
FsHandler() FsHandler
ListenAndServe(port int)
}
type Service func(w http.ResponseWriter, r *http.Request) error
type FilterChain interface {
GetFilter() Filter
SetNext(chain FilterChain)
GetNext() FilterChain
DoFilter(w http.ResponseWriter, r *http.Request) error
SetService(service Service)
DoService(w http.ResponseWriter, r *http.Request) error
}
type Filter interface {
bean.Bean
Order() int
UrlPatterns() Patterns
DoFilter(w http.ResponseWriter, r *http.Request, chain FilterChain) error
}
type Patterns []string
type Configure struct {
bean.Component
Charset string `yaml:"charset"`
}
func (c *Configure) Prefix() string {
return "application.web"
}
const (
Path = "path"
Query = "query"
Body = "body"
Header = "header"
Form = "form"
Multipart = "multipart"
Context = "context"
Request = "request"
Response = "response"
Stream = "stream"
)
var (
MethodDefine = []string{
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodConnect,
http.MethodOptions,
http.MethodTrace,
}
SourceDefine = []string{Path, Query, Body, Form, Header, Multipart, Context, Request, Response, Stream}
DefaultSource = Query
)
type ApiInfo struct {
HttpMethod string
URL string
ApiDesc string
Params []Param
}
type Param struct {
Name string
Source string
Type reflect.Type
}
type ServiceMethod struct {
Type *reflect.Method
Value *reflect.Value
}
type RestHandler func(apiInfo *ApiInfo, svm *ServiceMethod)
type FsHandler func(url, dir string)
type ParamMapper interface {
//PathParamMapper
GetStringFromPath(param Param) (string, error)
GetIntFromPath(param Param) (int, error)
GetBoolFromPath(param Param) (bool, error)
GetFloatFromPath(param Param) (float64, error)
//QueryParamMapper
GetStringFromQuery(param Param) (string, error)
GetIntFromQuery(param Param) (int, error)
GetBoolFromQuery(param Param) (bool, error)
GetFloatFromQuery(param Param) (float64, error)
GetStructFromQuery(param Param) (interface{}, error)
//BodyParamMapper
GetStructFromBody(param Param) (interface{}, error)
GetMapFromBody(param Param) (interface{}, error)
//HeaderParamMapper
GetStringFromHeader(param Param) (string, error)
//FormParamMapper
GetStringFromForm(param Param) (string, error)
GetIntFromForm(param Param) (int, error)
GetBoolFromForm(param Param) (bool, error)
GetFloatFromForm(param Param) (float64, error)
GetMapFromForm() (map[string][]string, error)
//UploadMapper
GetStringFromMultipart(param Param) (string, error)
GetMultipartHeader(param Param) (*multipart.FileHeader, error)
GetMultipartFile(param Param) (multipart.File, error)
GetStream() ([]byte, error)
//HttpMapper
GetRequest() (*http.Request, error)
GetResponseWriter() (http.ResponseWriter, error)
//Context
GetContext() (context.Context, error)
//ExtendedParamMapper
Get(param Param) (interface{}, error)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.3.6

搜索帮助

344bd9b3 5694891 D2dac590 5694891