-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (33 loc) · 1014 Bytes
/
main.go
File metadata and controls
42 lines (33 loc) · 1014 Bytes
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
package main
import (
"net/http"
"github.com/poteto0/poteto"
"github.com/poteto0/poteto-sample-api/controller"
"github.com/poteto0/poteto-sample-api/middles"
"github.com/poteto0/poteto/middleware"
)
func main() {
p := poteto.New()
// logger
logConfig := middleware.DefaultRequestLoggerConfig
logConfig.LogHandleFunc = middles.MyHTTPLoggerFunc
p.Register(middleware.RequestLoggerWithConfig(logConfig))
// CORS
p.Register(middleware.CORSWithConfig(
middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
},
))
// User Router
p.Leaf("/users", func(userApi poteto.Leaf) {
userApi.Register(middleware.CamaraWithConfig(middleware.DefaultCamaraConfig))
userApi.GET("/", controller.UserHandler)
userApi.GET("/:name", controller.UserIdHandler)
})
p.GET("/users", controller.UserHandler)
p.Run(":8080")
}
type User struct {
Name any `json:"name"`
}