Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poteto-go/poteto
WebAPI Framework for golang
https://github.com/poteto-go/poteto
go go-library golang poteto webapi webframework
Last synced: 16 days ago
JSON representation
WebAPI Framework for golang
- Host: GitHub
- URL: https://github.com/poteto-go/poteto
- Owner: poteto-go
- License: mit
- Created: 2024-08-29T05:11:06.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-02T09:09:51.000Z (28 days ago)
- Last Synced: 2025-01-02T10:24:49.887Z (28 days ago)
- Topics: go, go-library, golang, poteto, webapi, webframework
- Language: Go
- Homepage:
- Size: 327 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# Poteto
## Simple Web Framework of GoLang
We have confirmed that it works with various versions: [email protected], [email protected], [email protected]
```bash
go get github.com/poteto-go/poteto@latest
# or
go mod tidy
```## Example App For Poteto
https://github.com/poteto-go/poteto-examples
## Poteto-Cli
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.
```sh
go install github.com/poteto-go/poteto-cli/cmd/poteto-cli@latest
```OR build from docker image
https://hub.docker.com/repository/docker/poteto17/poteto-go/general
```sh
docker pull poteto17/poteto-go
docker -it --rm poteto17/poteto-go:1.23 bash
```detail on:
https://github.com/poteto-go/poteto-cli
## Feature
### JSONRPCAdapter (`>=0.26.0`)
KeyNote: You can serve JSONRPC server easily.
```go
type (
Calculator struct{}
AdditionArgs struct {
Add, Added int
}
)func (tc *TestCalculator) Add(r *http.Request, args *AdditionArgs) int {
return args.Add + args.Added
}func main() {
p := New()rpc := TestCalculator{}
// you can access "/add/Calculator.Add"
p.POST("/add", func(ctx Context) error {
return PotetoJsonRPCAdapter[Calculator, AdditionArgs](ctx, &rpc)
})p.Run("8080")
}
```### Leaf router & middlewareTree (`>=0.21.0`)
```go
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("127.0.0.1:8000")
}
```### Get RequestId Easily
```go
func handler(ctx poteto.Context) error {
requestId := ctx.RequestId()
}
```## How to use
```go:main.go
package mainimport (
"net/http""github.com/poteto-go/poteto"
"github.com/poteto-go/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("127.0.0.1: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)
}```