-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
main.go
35 lines (29 loc) · 829 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/gotomicro/ego"
"github.com/gotomicro/ego/core/elog"
"github.com/gotomicro/ego/server/egin"
)
// export EGO_DEBUG=true && go run main.go --config=config.toml
func main() {
if err := ego.New().Serve(func() *egin.Component {
server := egin.Load("server.http").Build()
server.GET("/panic", func(ctx *gin.Context) {
<-ctx.Request.Context().Done()
panic(ctx.Request.Context().Err())
})
server.GET("/200", func(ctx *gin.Context) {
<-ctx.Request.Context().Done()
fmt.Println(ctx.Request.Context().Err())
ctx.String(200, "hello")
})
server.GET("/hello", func(ctx *gin.Context) {
ctx.JSON(200, "Hello client: "+ctx.GetHeader("app"))
})
return server
}()).Run(); err != nil {
elog.Panic("startup", elog.FieldErr(err))
}
}