Documentation ¶
Index ¶
- Variables
- func AddHTTPBasicAuth(username, password string)
- func AddHTTPBasicAuthWithFilter(username, password string, needAuthFilter func(ctx *kmgHttp.Context) bool)
- func ContextHandle(ctx *kmgHttp.Context)
- func Dispatcher(ctx *kmgHttp.Context, processorList []HttpProcessor)
- func GetControllerNameList() []string
- func HttpHandlerFunc(w http.ResponseWriter, req *http.Request)
- func PanicHandler(ctx *kmgHttp.Context, processorList []HttpProcessor)
- func RegisterController(obj interface{})
- func RegisterControllerFunc(name string, f func(ctx *kmgHttp.Context))
- func RequestLogger(ctx *kmgHttp.Context, processorList []HttpProcessor)
- func StartHttpServer(addr string)
- func StartServer(sReq ServerRequest)
- func StartServerAsync(serverAddress string) (closer func() error)
- func StartServerCommand()
- type HttpProcessor
- type ServerRequest
- type ServerType
Constants ¶
This section is empty.
Variables ¶
View Source
var EnterPointApiName = ""
EnterPointApiName 最前面不要加 /?n=
View Source
var HttpHandler = http.HandlerFunc(HttpHandlerFunc)
View Source
var HttpProcessorList = []HttpProcessor{ PanicHandler, Dispatcher, }
Functions ¶
func AddHTTPBasicAuth ¶
func AddHTTPBasicAuth(username, password string)
* Example: 在 kmgControllerRunner.StartServerCommand() 前调用 needAuthFilter 返回 true 表示需要验证身份 下面这个例子是:只有在访问前缀是 "/?n=Admin.User.Info" 时才验证身份
kmgControllerRunner.AddHTTPBasicAuthenticationDispatcher("UserName", "Password", func(ctx *kmgHttp.Context) bool { return strings.HasPrefix(ctx.GetRequestUrl(), "/?n=Admin.User.Info") })
func ContextHandle ¶
func Dispatcher ¶
func Dispatcher(ctx *kmgHttp.Context, processorList []HttpProcessor)
func GetControllerNameList ¶
func GetControllerNameList() []string
func PanicHandler ¶
func PanicHandler(ctx *kmgHttp.Context, processorList []HttpProcessor)
func RegisterController ¶
func RegisterController(obj interface{})
注册controller,请先注册后使用,该函数不能并发调用,不能在http开始处理之后再注册(data race问题) 允许重复注册.
func RegisterControllerFunc ¶
此处可以随意定义Api的名称,用来解决调用者的名称向前兼容问题. 普通情况下可以使用 RegisterController,减少信息重复.
func RequestLogger ¶
func RequestLogger(ctx *kmgHttp.Context, processorList []HttpProcessor)
默认不用这个,容易搞的测试里面到处都是log. TODO 静态文件的log问题 TODO 尝试搞出更好用的log系统.
func StartHttpServer ¶
func StartHttpServer(addr string)
func StartServerAsync ¶
func StartServerCommand ¶
func StartServerCommand()
以命令行方式运行应用.这个函数会阻塞执行. http方式运行 ./MainApp -http=:80 https 方式 加http跳转运行 (必须绑一个域名,如果有更复杂的需求,此处无法完成)
./MainApp -https=:443 -http=:80 -type=Both -certFile=xxx.crt -keyFile=xxx.key domain=xxx.com
Types ¶
type HttpProcessor ¶
type HttpProcessor func(ctx *kmgHttp.Context, processorList []HttpProcessor)
type ServerRequest ¶
type ServerType ¶
type ServerType string
const ( ServerTypeHttp ServerType = "Http" //只有http ServerTypeBoth ServerType = "Both" //http跳转到https )
Click to show internal directories.
Click to hide internal directories.