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.
57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"net/http"
|
|
|
|
"zero/core/conf"
|
|
"zero/core/logx"
|
|
"zero/core/service"
|
|
"zero/example/tracing/remote/portal"
|
|
"zero/rest"
|
|
"zero/rest/httpx"
|
|
"zero/rpcx"
|
|
)
|
|
|
|
var (
|
|
configFile = flag.String("f", "config.json", "the config file")
|
|
client *rpcx.RpcClient
|
|
)
|
|
|
|
func handle(w http.ResponseWriter, r *http.Request) {
|
|
conn := client.Conn()
|
|
greet := portal.NewPortalClient(conn)
|
|
resp, err := greet.Portal(r.Context(), &portal.PortalRequest{
|
|
Name: "kevin",
|
|
})
|
|
if err != nil {
|
|
httpx.WriteJson(w, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
|
} else {
|
|
httpx.OkJson(w, resp.Response)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var c rpcx.RpcClientConf
|
|
conf.MustLoad(*configFile, &c)
|
|
client = rpcx.MustNewClient(c)
|
|
engine := rest.MustNewServer(rest.RestConf{
|
|
ServiceConf: service.ServiceConf{
|
|
Log: logx.LogConf{
|
|
Mode: "console",
|
|
},
|
|
},
|
|
Port: 3333,
|
|
})
|
|
defer engine.Stop()
|
|
|
|
engine.AddRoute(rest.Route{
|
|
Method: http.MethodGet,
|
|
Path: "/",
|
|
Handler: handle,
|
|
})
|
|
engine.Start()
|
|
}
|