Just write normal functions, and Gen generates efficient routing source code and documentation for it
Because the source code is generated, none of this affects runtime performance
The differences caused by each change in the tool are shown directly in the generated source code
generating clients is also supported
'#' is the annotation, the annotation is the golang tag syntax, the only difference here is '#' wraps not '`'.
// ItemService #path:"/item/"#
type ItemService struct {}
// Create a Item #route:"POST /"#
func (s *ItemService) Create(item *Item) (err error) {}
// Update the Item #route:"PUT /{item_id}"#
func (s *ItemService) Update(itemID int /* #name:"item_id"# */, item *Item) (err error) {}
// Delete the Item #route:"DELETE /{item_id}"#
func (s *ItemService) Delete(itemID int /* #name:"item_id"# */) (err error) {}
// Get the Item #route:"GET /{item_id}"#
func (s *ItemService) Get(itemID int /* #name:"item_id"# */) (item *ItemWithID, err error) {}
// List of the Item #route:"GET /"#
func (s *ItemService) List(offset, limit int) (items []*ItemWithID, err error) {}
- Install gen tool
go get -v github.com/wzshiming/gen/cmd/gen
- Add gen tool to $PATH
- Start it
gen run github.com/wzshiming/gen-examples/service/...
- Open http://127.0.0.1:8080/swagger/?url=./openapi.json# with your browser
Or try to quickly build services from scratch
- Make a directory
mkdir -p $(go env GOPATH)/src/gentest
- Change directory
cd $(go env GOPATH)/src/gentest/
- Define models
cat > models.go <<EOF
package gentest
type Gentest struct {
Name string \`json:"name"\`
Age int \`json:"age"\`
}
EOF
- Generated from CRUD template
gen crud -t mock -n Gentest
- Start it
GO111MODULE=off gen run gentest
- Generate documentation
- RESTful
- Generate Go router
- Security
- apiKey
- http
- basic
- bearer
- oauth2
- openIdConnet
- Content
- Query
- Path
- Header
- Cookie
- Body
- JSON
- XML
- Formdata
- File
- Value
- URLEncode
- Security
- Generate Go client
- Security
- apiKey
- http
- basic
- bearer
- oauth2
- openIdConnet
- Content
- Query
- Path
- Header
- Cookie
- Body
- JSON
- XML
- Formdata
- File
- Value
- URLEncode
- Security
- Other Client
- Generate Go router
- gRPC & Proto3
Pouch is licensed under the MIT License. See LICENSE for the full license text.