HTTPKit implements a code generator which automatically generates go packages for a http CRUD implementations for annotated structs.
go get -u github.com/gokit/httpkit
See Examples for demonstrations of httpkit code generation.
Running the following commands instantly generates all necessary files and packages for giving code gen.
> httpkit generate
You annotate any giving struct with @httpapi
which marks giving struct has a target for code generation.
It also respects attributes like New
and Update
on the @httpapi
annotation, these two provide information to the generator for:
- What struct to be used as representing a new data for struct type.
- What struct contain information for representing the update data for struct type.
Sample below:
// User is a type defining the given user related fields for a given.
//@httpapi(New => NewUser, Update => UpdatedUser)
type User struct {
Username string `json:"username"`
PublicID string `json:"public_id"`
PrivateID string `json:"private_id"`
Hash string `json:"hash"`
TwoFactorAuth bool `json:"two_factor_auth"`
Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"`
}