client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package client turns the operations of the Go model into an HTTP client: the client type with its options, the request options of every operation, the methods that call the API, and the response envelopes of the HasEnvelopes methods.

Index

Constants

View Source
const (
	PartCore       layout.PartID = "client.core"
	PartOptions    layout.PartID = "client.options"
	PartOperations layout.PartID = "client.operations"
	PartResponses  layout.PartID = "client.responses"
)

The client parts.

Variables

This section is empty.

Functions

func Blocks

func Blocks() []string

Blocks lists the blocks of the client templates a config may override.

func IsOtherSuccess

func IsOtherSuccess(r gomodel.Response, success string) bool

IsOtherSuccess reports a documented 2xx response besides the status success. The plain method does not read its body, so it returns none.

func IsStreamOnly

func IsStreamOnly(op *gomodel.Operation) bool

IsStreamOnly reports an operation whose 2xx responses have bodies in sequential media types only, so that only its Stream method can read them: the plain method blocks until the server hangs up.

func SuccessBody

func SuccessBody(op *gomodel.Operation) (gomodel.Response, gomodel.Content, bool)

SuccessBody is the lowest documented 2xx response with a body the client decodes, with the body the plain method returns: its JSON one, else its first the client decodes.

func Templates

func Templates() render.Set

Templates is the client template set.

Types

type BodyView

type BodyView struct {
	IsSet     string
	Encoder   string
	Value     string
	MediaType string
	Encoding  string
	IsJSON    bool
}

BodyView is one body field: the expression that says it is set, the builder method that sends it with the expression of its value, and the quoted media type the method takes, empty for one that needs none. Encoding is the runtime.Encoding a form or multipart body is sent with; IsJSON marks a JSON body, sent with the client's marshal function. An empty Encoder is a body the client cannot send, whose media type it reports.

type CheckView

type CheckView struct {
	Field string
	Path  string
}

CheckView validates the Field of the options under Path, a quoted name, when it is set.

type CoreView

type CoreView struct {
	Name         string
	Option       string
	Interface    string
	Header       HeaderView
	Context      string
	HTTP         string
	Time         string
	URL          string
	JSON         string
	HTTPClient   string
	Timeout      string
	HasStreams   bool
	HasEnvelopes bool
	Signatures   []SignatureView
	User         map[string]any
}

CoreView is the data of the core part: the client type, its option type, the interface it implements with a signature per operation, the names the packages are imported under, the default timeout as a duration expression, empty for none, and whether the client has a Stream method. Header is the data of the client.interface-header block.

type EnvelopeView

type EnvelopeView struct {
	Name   string
	Type   string
	Fields []FieldView
}

EnvelopeView is the envelope of one operation: a field per documented body the client decodes and per struct of typed headers, after the response and its raw body.

type FieldView

type FieldView struct {
	Name string
	Type string
	Doc  string
}

FieldView is one field of a generated struct.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator builds the template data of every client part. It skips webhooks, which are incoming.

func New

func New(m *gomodel.Model, opts Options) (*Generator, []diag.Diagnostic)

New returns the generator of m's operations, with the warnings of each, see warnings.

func (*Generator) Interface

func (g *Generator) Interface() string

Interface is the name of the interface the client implements.

func (*Generator) Parts

func (g *Generator) Parts() []layout.Part

Parts returns the client parts with the parts each refers to, in the order a file holds them: the types the client takes and returns, then the client with its interface, then its methods. The operations add methods to the client type, so they share the folder of the core.

func (*Generator) View

func (g *Generator) View(part layout.PartID, s *gocode.Scope) any

View returns the data of part, with names written as the file of s spells them.

type GroupView

type GroupView struct {
	Field  string
	Params []ParamView
}

GroupView is the parameters of one location: the options field that holds them and how each is added to the request.

type HeaderView

type HeaderView struct {
	Name string
	User map[string]any
}

HeaderView is the data of the client.interface-header block: Name is the client interface.

type OperationView

type OperationView struct {
	SignatureView
	Method          string
	Path            string
	Groups          []GroupView
	QueryString     *ParamView
	Bodies          []BodyView
	IsBodyRequired  bool
	IsSendable      bool
	Zero            string
	Accept          string
	Targets         []TargetView
	EnvelopeTargets []TargetView
	Stream          *StreamView
}

OperationView is one operation: the request it builds, the method that returns the body of its success response, and with HasEnvelopes the method that returns its envelope. Method is the net/http constant or a quoted method; Path is quoted. IsSendable is false when the body is required and the client can send none of its media types, so the request is never built. Zero is the value the plain method returns on an error. Accept is the quoted Accept header the plain and envelope methods send. Targets are what the plain method decodes, with the other documented 2xx statuses when it has a Result, EnvelopeTargets what the HasEnvelopes method decodes into the envelope Response. Stream is the Stream method of an operation that answers in a sequential media type, nil without HasStreams.

type OperationsView

type OperationsView struct {
	Client       string
	Context      string
	HTTP         string
	Runtime      string
	HTTPClient   string
	Slices       string
	HasEnvelopes bool
	User         map[string]any
	Operations   []OperationView
}

OperationsView is the data of the operations part. Client is the client type as the file writes it.

type Options

type Options struct {
	Name         string
	Namer        *naming.Namer
	Timeout      time.Duration
	Descriptions bool
	HasEnvelopes bool
	HasStreams   bool
	User         map[string]any
}

Options are the settings of the client generator. Name is the client type; Timeout is what the default http.Client gives up after; HasEnvelopes adds the envelopes and the WithResponse methods; HasStreams adds the Stream methods of the operations that answer with a sequential media type; User is the config's user-context. Descriptions copies the summary and description of each operation into its comment.

type OptionsView

type OptionsView struct {
	Operations []RequestOptionsView
}

OptionsView is the data of the options part: the request options type of every operation.

type ParamView

type ParamView struct {
	Encoder    string
	Value      string
	Name       string
	Style      string
	IsExplode  bool
	IsRequired bool
	IsJSON     bool
	IsReserved bool
}

ParamView is one parameter: the builder method that adds it, the expression of its value and its runtime.Param. Name is quoted, Style a runtime constant.

type RequestOptionsView

type RequestOptionsView struct {
	Name       string
	Type       string
	Validation string
	Fields     []FieldView
	Checks     []CheckView
}

RequestOptionsView is the request options of one operation: a field per parameter group and per body, and the checks Validate runs. Validation is set when there are checks.

type ResponsesView

type ResponsesView struct {
	HTTP       string
	Operations []EnvelopeView
}

ResponsesView is the data of the responses part: the envelope of every operation.

type SignatureView

type SignatureView struct {
	Name       string
	Route      string
	Doc        string
	Options    string
	Result     string
	Response   string
	StreamType string
}

SignatureView is what the interface and the methods of one operation share. Route is the method and the path as the spec writes them; Doc is the comment of the plain method. Result is the type of the body the plain method returns, empty for none; Response is the envelope, empty without HasEnvelopes; StreamType is what the Stream method returns, empty for no Stream method.

type StreamView

type StreamView struct {
	MediaType string
	Frame     string
	Targets   []TargetView
	Field     string
}

StreamView is the Stream method of an operation. MediaType is the sequential media type it asks for; Frame is the type of one frame; Targets are the error bodies it decodes; Field is the envelope field that holds the stream.

type TargetView

type TargetView struct {
	Status    string
	MediaType string
	Dst       string
	IsHeaders bool
}

TargetView is one httpclient.ResponseTarget: the status and media type, and the address of what the body is decoded into, empty for a status whose body is not read; IsHeaders marks the typed headers of the status.

Jump to

Keyboard shortcuts

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