example

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package example holds the client that the tests of the generator drive. The generated file beside it is the output of `avero generate`. See the SDD, S13.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Example

type Example interface {
	//avero:GET /things/{id}
	GetThing(ctx context.Context, id string) (Thing, error)

	//avero:GET /things
	ListThings(ctx context.Context, opts ListOptions) (List, error)

	//avero:POST /things
	CreateThing(ctx context.Context, body NewThing) (*Thing, error)

	//avero:DELETE /things/{id}
	DeleteThing(ctx context.Context, id string) error

	//avero:GET /accounts/{account}/things/{id}
	GetAccountThing(ctx context.Context, account int, id string) (Thing, error)
}

Example is the interface that the directive turns into a client. The generated implementation lives in the file beside this one.

func NewExample

func NewExample(opts ...client.Option) (Example, error)

NewExample returns a client of the Example service.

The directive states the base address https://api.example.com. An option after it replaces a default, so a test points the client at httptest.

type List

type List struct {
	// Things holds the page.
	Things []Thing `json:"things"`
	// Total is the number of rows of the whole set.
	Total int `json:"total"`
}

List is the answer of a list call.

type ListOptions

type ListOptions struct {
	// Page is the page number.
	Page int `query:"page"`
	// Search filters the set. An empty value sends no parameter.
	Search string `query:"q,omitempty"`
	// Full asks for the whole row.
	Full bool `query:"full"`
	// Limit bounds the page. A nil value sends no parameter.
	Limit *int `query:"limit"`
	// Key is the API key of the caller.
	Key string `header:"X-Api-Key"`
	// Trace names the call in the log of the service.
	Trace string `header:"X-Trace,omitempty"`
}

ListOptions holds the query of a list call and the headers of the request.

type NewThing

type NewThing struct {
	// Title is the name of the new thing.
	Title string `json:"title"`
}

NewThing is the body of a create call.

type Thing

type Thing struct {
	// ID identifies the thing.
	ID string `json:"id"`
	// Title is the name that a person reads.
	Title string `json:"title"`
}

Thing is one row of the service.

Jump to

Keyboard shortcuts

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