You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

2 years ago
package main
import (
2 years ago
"flag"
2 years ago
"fmt"
11 months ago
user "git.diulo.com/mogfee/kit/api"
"git.diulo.com/mogfee/kit/example/service"
"git.diulo.com/mogfee/kit/rest"
"git.diulo.com/mogfee/kit/rest/httpx"
11 months ago
"net/http"
2 years ago
)
func main() {
2 years ago
flag.Parse()
11 months ago
srv := rest.NewServer(rest.RestConf{
Host: "localhost",
Port: 8998,
}, rest.WithCors("*"))
11 months ago
srv.Use(func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
11 months ago
//tokenStr := `fS6HZv4HoMo+OnaNsLuM7O4Kx9L4UrM2TdnJB/J5qK75mJiEsuTyELYxaZXkFMnqjZp1lZ4V1vNATA4Tdhhfc/chcYQISAaWTmqjSoHROIMEGFg9x1+d/6MR6scX6g9JkX5beXKvgpeQhi2Q2SLjquBgWaPbaaPbM2owVYUICg4Z5aSNpd1n4dQfnRIkOCpIo7EFFy9ZRBD05xGs8/kPPBVe10ZEXpgcSBgKPkVVT1a0C0XZ2AwMfHU/dKf5gEJh`
11 months ago
next(w, r)
}
12 months ago
})
srv.AddRoute(rest.Route{
Method: "GET",
Path: "/api/v2/user/me",
Handler: func(w http.ResponseWriter, r *http.Request) {
httpx.OkJson(w, map[string]any{
"name": "tom",
})
},
})
11 months ago
user.RegisterUserHTTPServer(srv, service.NewUserService("sfe023f_9fd&fwfl"))
11 months ago
fmt.Println(srv.Start())
2 years ago
}