You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/tools/goctl/api/demo/handler/getuserhandler.go

34 lines
501 B
Go

4 years ago
package handler
import (
"net/http"
"zero/core/httpx"
)
type (
request struct {
User string `form:"user,optional"`
}
response struct {
Code int `json:"code"`
Greet string `json:"greet"`
From string `json:"from,omitempty"`
}
)
func GreetHandler(w http.ResponseWriter, r *http.Request) {
var req request
err := httpx.Parse(r, &req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
httpx.OkJson(w, response{
Code: 0,
Greet: "hello",
})
}