Пример #1
0
func (UserController) Update(req *http.Request, res http.ResponseWriter) string {
	res.Header().Set("Content-Type", "application/json")
	p, _ := utils.GetSucessResult(struct {
		Name string
		Age  int
	}{"val", 18})

	return p
}
Пример #2
0
func (UserController) GetList(req *http.Request, res http.ResponseWriter) string {
	fmt.Println("GetList")
	val := req.FormValue("key")
	res.Header().Set("Content-Type", "application/json")
	p, _ := utils.GetSucessResult(struct {
		Name string
		Age  int
	}{val, 18})

	return p
}
Пример #3
0
func (UserController) Create(req *http.Request, res http.ResponseWriter) string {
	result, _ := ioutil.ReadAll(req.Body)
	defer req.Body.Close()

	var user models.User
	json.Unmarshal(result, &user)

	if user.Name == "" || user.Nick == "" {
		return utils.GetFailResult("name or nick is empty")
	}

	user.ID = 0
	models.DB.Create(&user)

	r, _ := utils.GetSucessResult(user)

	return r
}
Пример #4
0
func (ArticleController) Create(req *http.Request, res http.ResponseWriter) string {
	fmt.Println("create")
	val := req.FormValue("key")
	res.Header().Set("Content-Type", "application/json")
	p, _ := utils.GetSucessResult(struct {
		Name string
		Age  int
	}{val, 18})

	user := models.User{
		Name:      "zhanglei",
		Nick:      val,
		Age:       1,
		CreatedAt: int(time.Now().Unix()),
	}

	models.DB.Create(&user)

	return p
}