func (t TestObj) TestHandleUploadFile(ctx *kmgHttp.Context) {
	fileInfo := ctx.MustInFile("UFile")
	file, err := fileInfo.Open()
	if err != nil {
		panic(err)
	}
	defer file.Close()
	content, err := ioutil.ReadAll(file)
	if err != nil {
		panic(err)
	}
	a := ctx.InStr("a")
	ctx.WriteString(fileInfo.Filename)
	ctx.WriteString(" ")
	ctx.WriteString(a)
	ctx.WriteString(" ")
	ctx.WriteString(string(content))
}
Beispiel #2
0
func Dispatcher(ctx *kmgHttp.Context, processorList []HttpProcessor) {
	apiName := ctx.InStr("n")
	if apiName == "" && EnterPointApiName != "" {
		if ctx.GetRequestUrl() == "/favicon.ico" {
			// 避免网站图标请求,占用大量资源.
			ctx.NotFound("api not found")
			return
		}
		apiName = EnterPointApiName
	}
	apiFunc, ok := controllerObjMap[apiName]
	if !ok {
		ctx.NotFound("api not found")
		return
	}

	apiFunc(ctx)
	return
}