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.
34 lines
501 B
Go
34 lines
501 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"zero/ngin/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",
|
|
})
|
|
}
|