Esempio n. 1
0
File: data.go Progetto: jango2015/wk
func DataTopHandle(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	if count, ok := ctx.RouteData.Int("count"); !ok {
		err = errors.New("parameter invalid:" + "count")
	} else {
		data := DataTop(count)
		result = wk.Json(data)
	}
	return
}
Esempio n. 2
0
File: file.go Progetto: jango2015/wk
func FileAjax(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	ctx.Request.ParseMultipartForm(32 << 20) // 32 MB
	status := UploadStatus{make([]FileInfo, 0)}
	for _, headers := range ctx.Request.MultipartForm.File {
		for _, header := range headers {
			info := fileInfo(header)
			status.Files = append(status.Files, info)
		}
	}
	return wk.Json(status), nil
}
Esempio n. 3
0
func TestJsonResult(t *testing.T) {
	data := defaultUser()
	j := wk.Json(data)
	var result wk.HttpResult = j
	t.Log("JsonResult", result)

	header := make(http.Header)
	body := &bytes.Buffer{}
	var render wk.Render = j

	err := render.Write(header, body)
	success(t, "json write", err)
	equal(t, "json header", wk.ContentTypeJson, header.Get(wk.HeaderContentType))
	equal(t, "json body", tojson(data), body.String())
}
Esempio n. 4
0
File: user.go Progetto: jango2015/wk
// get: /user/delete/1
func (uc *UserController) Delete(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	var res ApiRes

	if id, ok := ctx.RouteData.Int("arg"); ok {
		res = ApiRes{
			Code: "",
			Data: userRepo.Delete(id),
		}
	} else {
		res = ApiRes{
			Code:    "1",
			Message: " Invalid Argument",
		}
	}

	return wk.Json(res), nil
}
Esempio n. 5
0
// url: /basic/all/
func (c *BasicController) All(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	return wk.Json(c.data), nil
}
Esempio n. 6
0
// url: /basic/int/32
func (c *BasicController) Int(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	if id, ok := ctx.RouteData.Int("id"); ok {
		return wk.Json(c.getByInt(id)), nil
	}
	return wk.Data(""), nil
}