MapyWeb/web/router.go

41 lines
927 B
Go
Raw Normal View History

2021-09-20 10:36:20 +00:00
package web
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/savsgio/atreugo/v11"
2021-12-31 15:22:03 +00:00
"mapyweb/config"
2021-09-20 10:36:20 +00:00
)
func main() {
webconf := atreugo.Config{
Addr: fmt.Sprintf("%s:%s", config.HTTPBindAddr, config.HTTPBindPort),
TLSEnable: true,
2021-12-31 15:22:03 +00:00
CertKey: config.SSLKeyFile,
CertFile: config.SSLCertFile,
2021-09-20 10:36:20 +00:00
Name: "MapyWeb",
Debug: config.Debug,
Compress: true,
2021-12-31 15:22:03 +00:00
MaxConnsPerIP: 10,
MaxRequestsPerConn: 4,
2021-09-20 10:36:20 +00:00
}
server := atreugo.New(webconf)
server.GET("/", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse("Hello World")
})
server.GET("/echo/{path:*}", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse("Echo message: " + ctx.UserValue("path").(string))
})
v1 := server.NewGroupPath("/v1")
v1.GET("/", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse("Hello V1 Group")
})
log.Error().Str("caller", "http").Err(server.ListenAndServe()).Msg("failed to listen")
}