go get -u github.com/poteto-go/poteto@latestIf you try latest experiment version
https://github.com/poteto-go/poteto/blob/main/EXPERIMENT.md
go get -u github.com/poteto-go/poteto@exp<version>https://deepwiki.com/poteto-go/poteto
func main() {
p := poteto.New()
p.Register(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}))
p.GET("/", func(ctx poteto.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{
"message": "Hello World",
})
})
userApi := poteto.Api("/users", func(leaf poteto.Leaf) {
leaf.GET("/:id", func(ctx poteto.Context) error {
id, _ := p.PathParam("id")
return ctx.JSON(http.StatusOK, map[string]string{
"id": id,
})
})
})
p.AddApi(userApi)
p.Run("3000")
}Note
Poteto developers can easily test without setting up a server.
func main() {
p := poteto.New()
p.GET("/users", func(ctx poteto.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{
"id": "1",
"name": "tester",
})
})
res := p.Play(http.MethodGet, "/users")
resBodyStr := res.Body.String
// => {"id":"1","name":"tester"}
}use poteto-extensions/middleware
go get github.com/poteto-go/poteto-extensionspoteto provides easily oidc middleware.
- verify signature
- jwt schema (if idp google).
func main() {
p := poteto.New()
oidcConfig := middleware.OidcConfig {
Idp: "google",
ContextKey: "googleToken",
CacheMode: true,
JwksUrl: "https://www.googleapis.com/oauth2/v3/certs",
CachedVerifyTokenSignature: oidc.CachedVerifyTokenSignature,
}
p.Register(
middleware.OidcWithConfig(
oidcConfig,
)
)
p.POST("/login", func(ctx poteto.Context) error {
var claims oidc.GoogleOidcClaims
token, _ := ctx.Get("googleToken")
json.Unmarshal(token.([]byte), &claims)
...
return ctx.JSON(200, map[string]string{"message": "success"})
})
}TODO
We support cli tool. But if you doesn't like it, you can create poteto-app w/o cli of course.
You can start hot-reload poteto app.
go install github.com/poteto-go/poteto-cli/cmd/poteto-cli@latestOR build from docker image
https://hub.docker.com/repository/docker/poteto17/poteto-go/general
docker pull poteto17/poteto-go
docker -it --rm poteto17/poteto-go:1.23 bashdetail on: