-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (43 loc) · 958 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/go-leo/gors/example/api/protodemo"
"github.com/go-leo/gors/example/internal/app/api/svc"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"net"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-leo/gors"
)
func main() {
engine := gin.New()
engine = gors.AppendRoutes(
engine,
protodemo.ProtoDemoServerRoutes(
new(svc.ProtoDemoServer),
gors.ResponseWrapper(func(resp any) any {
switch t := resp.(type) {
case *gors.Status:
return &protodemo.CommonReply{
Code: int32(t.Code),
Msg: t.Message,
}
default:
a, _ := anypb.New(resp.(proto.Message))
return &protodemo.CommonReply{
Code: 200,
Msg: "ok",
Data: a,
}
}
}))...)
srv := http.Server{Handler: engine}
listen, err := net.Listen("tcp", ":8088")
if err != nil {
panic(err)
}
err = srv.Serve(listen)
if err != nil {
panic(err)
}
}