We have confirmed that it works with various versions: go@1.21.x, go@1.22.x, go@1.23.x
go get github.com/poteto0/poteto@v0.25.3
go mod tidy
https://github.com/poteto0/poteto-sample-api/tree/main
We support cli tool. But if you doesn't like it, you can create poteto-app w/o cli of course.
go install github.com/poteto0/poteto/cmd/poteto-cli@v0.25.3
Create file.
poteto-cli new
fast mode.
poteto-cli new --fast
Clipchamp.3.mp4
func main() {
p := poteto.New()
// Leaf >= 0.21.0
p.Leaf("/users", func(userApi poteto.Leaf) {
userApi.Register(middleware.CamaraWithConfig(middleware.DefaultCamaraConfig))
userApi.GET("/", controller.UserHandler)
userApi.GET("/:name", controller.UserIdHandler)
})
p.Run(":8000")
}
func handler(ctx poteto.Context) error {
requestId := ctx.RequestId()
}
package main
import (
"net/http"
"github.com/poteto0/poteto"
"github.com/poteto0/poteto/middleware"
)
func main() {
p := poteto.New()
// CORS
p.Register(middleware.CORSWithConfig(
middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
},
))
// Leaf >= 0.21.0
p.Leaf("/users", func(userApi poteto.Leaf) {
userApi.Register(middleware.CamaraWithConfig(middleware.DefaultCamaraConfig))
userApi.GET("/", controller.UserHandler)
userApi.GET("/:name", controller.UserNameHandler)
})
p.Run(":8000")
}
type User struct {
Name any `json:"name"`
}
func UserHandler(ctx poteto.Context) error {
user := User{
Name: "user",
}
return ctx.JSON(http.StatusOK, user)
}
func UserNameHandler(ctx poteto.Context) error {
name, _ := ctx.PathParam("name")
user := User{
Name: name,
}
return ctx.JSON(http.StatusOK, user)
}