MapyWeb/web/router.go

41 lines
927 B
Go

package web
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/savsgio/atreugo/v11"
"mapyweb/config"
)
func main() {
webconf := atreugo.Config{
Addr: fmt.Sprintf("%s:%s", config.HTTPBindAddr, config.HTTPBindPort),
TLSEnable: true,
CertKey: config.SSLKeyFile,
CertFile: config.SSLCertFile,
Name: "MapyWeb",
Debug: config.Debug,
Compress: true,
MaxConnsPerIP: 10,
MaxRequestsPerConn: 4,
}
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")
}