fastrest
fast restful framework for golang.
- Create your app directory, like
mkdir myapp; cd myapp; go mod init myapp;
- Create initial config.toml in a folder
initassets
, example--- addr: ":14142"
- Create main code, example
package main import ( "embed" "github.com/bingoohuang/fastrest" ) //go:embed initassets var InitAssets embed.FS func main() { // 注册路由 router := fastrest.New(map[string]fastrest.Service{ "GET /status": &fastrest.Status{}, "POST /p1sign": &fastrest.P1Sign{}, }) args := fastrest.ParseArgs(&InitAssets) args.Run(router) }
- Create Makefile, example
- Build
make
- Create initial conf.toml and ctl:
myapp -init
- Startup
./ctl start
, you can set envexport GOLOG_STDOUT=true
before startup to view the log in stdout for debugging. - Performance testing using berf:
berf :14142/status -d15s -v
easyjson marshalling and unmarshalling
- Install easyjson tool
- Tag the model, see the following example.
- Generate easyjson codes:
easyjson yourmodel.go
//easyjson:json
type Service1Req struct {
Source string
BizType string
}
//easyjson:json
type Service1Rsp struct {
Source string
}