feat: complete API-driven projects with infrastructure and business acceptance
This commit is contained in:
30
contract/README.md
Normal file
30
contract/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# contract
|
||||
|
||||
Generated API projects use this package to compile Go field tags once and bind
|
||||
each request without depending on a specific HTTP server. `New[T]` validates a
|
||||
struct and returns an immutable Binder. `ForType` provides the same compiler to
|
||||
the CLI. `BodySchema`, `Parameters`, and `ResponseSchema` return detached OpenAPI
|
||||
snapshots. `MustNew[T]` is intended for generated, already checked declarations.
|
||||
|
||||
```go
|
||||
type Request struct {
|
||||
ID int64 `path:"id,range=[1:100]"`
|
||||
Name string `json:"name" binding:"required,max=50"`
|
||||
}
|
||||
|
||||
var request = contract.MustNew[Request]()
|
||||
|
||||
func Handle(c *httpx.Context) error {
|
||||
var req Request
|
||||
if err := request.Bind(c.Request(), httpx.RouteParams(c.Context()), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.OK(req.Name)
|
||||
}
|
||||
```
|
||||
|
||||
The default body limit is 1 MiB. An optional positive final argument to Bind
|
||||
overrides it. Application transport read timeouts still control slow clients.
|
||||
See [API.md](../API.md) for source tags, validation rules, null/presence behavior,
|
||||
strict decoding and supported type limits. This API leaves the existing
|
||||
`Context.BindJSON/BindQuery/BindURI` behavior unchanged.
|
||||
Reference in New Issue
Block a user