example

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package example is the fixture of the generator. Its generated file is committed, so the gate compiles and runs the code that the generator writes.

Every supported type and every rule of the SDD appears here one time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	// BoardID comes from the path, which wins over every other source.
	BoardID string `path:"board_id" validate:"required,uuid"`
	// Title comes from the form or from the body.
	Title string `json:"title" form:"title" validate:"required,min=3,max=50"`
	// Email covers the email rule.
	Email string `json:"email" form:"email" validate:"required,email"`
	// Role covers the oneof rule.
	Role string `json:"role" form:"role" validate:"oneof=admin member viewer"`
	// Page covers a signed integer and the numeric bounds.
	Page int `query:"page" validate:"min=1,max=100"`
	// Size covers a sized integer.
	Size int64 `query:"size"`
	// Ratio covers a float.
	Ratio float64 `query:"ratio"`
	// Notify covers a boolean. A boolean never carries the required rule.
	Notify bool `json:"notify" form:"notify" query:"notify"`
	// Timeout covers a duration.
	Timeout time.Duration `query:"timeout"`
	// StartsAt covers a time.
	StartsAt time.Time `query:"starts_at" json:"starts_at"`
	// Tags covers a repeated value.
	Tags []string `query:"tags" json:"tags"`
	// Computed binds from nothing. The handler fills it.
	Computed string `avero:"-"`
}

CreateInput covers every source and every rule.

func (*CreateInput) Bind

func (in *CreateInput) Bind(c *router.Ctx) error

Bind fills CreateInput from the request.

The sources are the JSON body, the form, the query and the path, in that order. A later source replaces an earlier one, so the path wins.

func (*CreateInput) Check

func (in *CreateInput) Check(_ *router.Ctx, f *router.Fields)

Check is the custom rule. The generated Validate calls it last, so it reads every field that the tags already checked.

func (*CreateInput) Validate

func (in *CreateInput) Validate(c *router.Ctx, f *router.Fields)

Validate checks CreateInput and records one message for each field that failed.

type ListInput

type ListInput struct {
	// Query comes from the query string only.
	Query string `query:"q" validate:"max=64"`
}

ListInput covers a type with no custom rule.

func (*ListInput) Bind

func (in *ListInput) Bind(c *router.Ctx) error

Bind fills ListInput from the request.

The sources are the JSON body, the form, the query and the path, in that order. A later source replaces an earlier one, so the path wins.

func (*ListInput) Validate

func (in *ListInput) Validate(c *router.Ctx, f *router.Fields)

Validate checks ListInput and records one message for each field that failed.

type Module

type Module struct{}

Module holds the handlers of the fixture.

func (*Module) Create

func (m *Module) Create(_ *router.Ctx, in CreateInput) (router.Response, error)

Create is a handler. The generator finds CreateInput from this signature.

func (*Module) List

func (m *Module) List(_ *router.Ctx, in ListInput) (router.Response, error)

List is a second handler.

func (*Module) Summaries added in v0.3.1

func (m *Module) Summaries() map[string]string

Summaries returns the summary of each handler of Module.

The comment of a handler states it. Change the comment and run `avero generate`.

func (*Module) Upload added in v0.6.0

func (m *Module) Upload(_ *router.Ctx, in UploadInput) (router.Response, error)

Upload is a handler that reads a multipart form.

type UploadInput added in v0.6.0

type UploadInput struct {
	// BoardID comes from the path.
	BoardID string `path:"board_id" validate:"required,uuid"`
	// Note comes from the same multipart body as the file.
	Note string `form:"note" validate:"max=140"`
	// Image covers one file, its size and its media type.
	Image *multipart.FileHeader `form:"image" validate:"required,maxsize=5MB,accept=image/png image/jpeg"`
	// Attachments covers a repeated file.
	Attachments []*multipart.FileHeader `form:"attachments" validate:"maxsize=1MB,accept=application/pdf"`
}

UploadInput covers a file of a multipart form.

func (*UploadInput) Bind added in v0.6.0

func (in *UploadInput) Bind(c *router.Ctx) error

Bind fills UploadInput from the request.

The sources are the JSON body, the form, the query and the path, in that order. A later source replaces an earlier one, so the path wins.

func (*UploadInput) Validate added in v0.6.0

func (in *UploadInput) Validate(c *router.Ctx, f *router.Fields)

Validate checks UploadInput and records one message for each field that failed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL