directoryapi

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package directoryapi implements the public API of the directory.example microservice, including clients and data structures.

The directory microservice exposes a RESTful API for persisting personal records in a SQL database.

Index

Constants

View Source
const Hostname = "directory.example"

Hostname is the default hostname of the microservice: directory.example.

Variables

View Source
var (
	URLOfCreate      = httpx.JoinHostAndPath(Hostname, `:443/persons`)
	URLOfLoad        = httpx.JoinHostAndPath(Hostname, `:443/persons/key/{key}`)
	URLOfDelete      = httpx.JoinHostAndPath(Hostname, `:443/persons/key/{key}`)
	URLOfUpdate      = httpx.JoinHostAndPath(Hostname, `:443/persons/key/{key}`)
	URLOfLoadByEmail = httpx.JoinHostAndPath(Hostname, `:443/persons/email/{email}`)
	URLOfList        = httpx.JoinHostAndPath(Hostname, `:443/persons`)
	URLOfWebUI       = httpx.JoinHostAndPath(Hostname, `:443/web-ui`)
)

Fully-qualified URLs of the microservice's endpoints.

Functions

This section is empty.

Types

type Client

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

Client is an interface to calling the endpoints of the directory.example microservice. This simple version is for unicast calls.

func NewClient

func NewClient(caller service.Publisher) *Client

NewClient creates a new unicast client to the directory.example microservice.

func (*Client) Create

func (_c *Client) Create(ctx context.Context, httpRequestBody *Person) (key PersonKey, err error)

Create registers the person in the directory.

func (*Client) Delete

func (_c *Client) Delete(ctx context.Context, key PersonKey) (err error)

Delete removes a person from the directory.

func (*Client) ForHost

func (_c *Client) ForHost(host string) *Client

ForHost replaces the default hostname of this client.

func (*Client) List

func (_c *Client) List(ctx context.Context) (httpResponseBody []PersonKey, err error)

List returns the keys of all the persons in the directory.

func (*Client) Load

func (_c *Client) Load(ctx context.Context, key PersonKey) (httpResponseBody *Person, err error)

Load looks up a person in the directory.

func (*Client) LoadByEmail

func (_c *Client) LoadByEmail(ctx context.Context, email string) (httpResponseBody *Person, err error)

LoadByEmail looks up a person in the directory by their email.

func (*Client) Update

func (_c *Client) Update(ctx context.Context, key PersonKey, httpRequestBody *Person) (err error)

Update updates the person's data in the directory.

func (*Client) WebUI

func (_c *Client) WebUI(r *http.Request) (res *http.Response, err error)

WebUI provides a form for making web requests to the CRUD endpoints.

If a request is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint.

func (*Client) WebUI_Get

func (_c *Client) WebUI_Get(ctx context.Context, url string) (res *http.Response, err error)

WebUI_Get performs a GET request to the WebUI endpoint.

WebUI provides a form for making web requests to the CRUD endpoints.

If a URL is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint.

func (*Client) WebUI_Post

func (_c *Client) WebUI_Post(ctx context.Context, url string, contentType string, body any) (res *http.Response, err error)

WebUI_Post performs a POST request to the WebUI endpoint.

WebUI provides a form for making web requests to the CRUD endpoints.

If a URL is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

type CreateIn

type CreateIn struct {
	HTTPRequestBody *Person `json:"-"`
}

CreateIn are the input arguments of Create.

type CreateOut

type CreateOut struct {
	Key PersonKey `json:"key"`
}

CreateOut are the return values of Create.

type CreateResponse

type CreateResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

CreateResponse is the response to Create.

func (*CreateResponse) Get

func (_out *CreateResponse) Get() (key PersonKey, err error)

Get retrieves the return values.

type DeleteIn

type DeleteIn struct {
	Key PersonKey `json:"key"`
}

DeleteIn are the input arguments of Delete.

type DeleteOut

type DeleteOut struct {
}

DeleteOut are the return values of Delete.

type DeleteResponse

type DeleteResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

DeleteResponse is the response to Delete.

func (*DeleteResponse) Get

func (_out *DeleteResponse) Get() (err error)

Get retrieves the return values.

type ListIn

type ListIn struct {
}

ListIn are the input arguments of List.

type ListOut

type ListOut struct {
	HTTPResponseBody []PersonKey `json:"httpResponseBody"`
}

ListOut are the return values of List.

type ListResponse

type ListResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

ListResponse is the response to List.

func (*ListResponse) Get

func (_out *ListResponse) Get() (httpResponseBody []PersonKey, err error)

Get retrieves the return values.

type LoadByEmailIn

type LoadByEmailIn struct {
	Email string `json:"email"`
}

LoadByEmailIn are the input arguments of LoadByEmail.

type LoadByEmailOut

type LoadByEmailOut struct {
	HTTPResponseBody *Person `json:"httpResponseBody"`
}

LoadByEmailOut are the return values of LoadByEmail.

type LoadByEmailResponse

type LoadByEmailResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

LoadByEmailResponse is the response to LoadByEmail.

func (*LoadByEmailResponse) Get

func (_out *LoadByEmailResponse) Get() (httpResponseBody *Person, err error)

Get retrieves the return values.

type LoadIn

type LoadIn struct {
	Key PersonKey `json:"key"`
}

LoadIn are the input arguments of Load.

type LoadOut

type LoadOut struct {
	HTTPResponseBody *Person `json:"httpResponseBody"`
}

LoadOut are the return values of Load.

type LoadResponse

type LoadResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

LoadResponse is the response to Load.

func (*LoadResponse) Get

func (_out *LoadResponse) Get() (httpResponseBody *Person, err error)

Get retrieves the return values.

type MulticastClient

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

MulticastClient is an interface to calling the endpoints of the directory.example microservice. This advanced version is for multicast calls.

func NewMulticastClient

func NewMulticastClient(caller service.Publisher) *MulticastClient

NewMulticastClient creates a new multicast client to the directory.example microservice.

func (*MulticastClient) Create

func (_c *MulticastClient) Create(ctx context.Context, httpRequestBody *Person) <-chan *CreateResponse

Create registers the person in the directory.

func (*MulticastClient) Delete

func (_c *MulticastClient) Delete(ctx context.Context, key PersonKey) <-chan *DeleteResponse

Delete removes a person from the directory.

func (*MulticastClient) ForHost

func (_c *MulticastClient) ForHost(host string) *MulticastClient

ForHost replaces the default hostname of this client.

func (*MulticastClient) List

func (_c *MulticastClient) List(ctx context.Context) <-chan *ListResponse

List returns the keys of all the persons in the directory.

func (*MulticastClient) Load

func (_c *MulticastClient) Load(ctx context.Context, key PersonKey) <-chan *LoadResponse

Load looks up a person in the directory.

func (*MulticastClient) LoadByEmail

func (_c *MulticastClient) LoadByEmail(ctx context.Context, email string) <-chan *LoadByEmailResponse

LoadByEmail looks up a person in the directory by their email.

func (*MulticastClient) Update

func (_c *MulticastClient) Update(ctx context.Context, key PersonKey, httpRequestBody *Person) <-chan *UpdateResponse

Update updates the person's data in the directory.

func (*MulticastClient) WebUI

func (_c *MulticastClient) WebUI(ctx context.Context, r *http.Request) <-chan *pub.Response

WebUI provides a form for making web requests to the CRUD endpoints.

If a request is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint.

func (*MulticastClient) WebUI_Get

func (_c *MulticastClient) WebUI_Get(ctx context.Context, url string) <-chan *pub.Response

WebUI_Get performs a GET request to the WebUI endpoint.

WebUI provides a form for making web requests to the CRUD endpoints.

If a URL is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint.

func (*MulticastClient) WebUI_Post

func (_c *MulticastClient) WebUI_Post(ctx context.Context, url string, contentType string, body any) <-chan *pub.Response

WebUI_Post performs a POST request to the WebUI endpoint.

WebUI provides a form for making web requests to the CRUD endpoints.

If a URL is not provided, it defaults to the URL of the endpoint. Otherwise, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

type Person

type Person struct {
	Birthday  timex.Timex `json:"birthday,omitempty"`
	Email     string      `json:"email,omitempty"`
	FirstName string      `json:"firstName,omitempty"`
	Key       PersonKey   `json:"key,omitempty"`
	LastName  string      `json:"lastName,omitempty"`
}

Person is a personal record that is registered in the directory. First and last name and email are required. Birthday is optional.

func (*Person) Validate

func (person *Person) Validate() error

Validate validates the field of the person. First and last name and email are required. Optional birthday must be in the past.

type PersonKey

type PersonKey int

PersonKey is the primary key of the person.

type UpdateIn

type UpdateIn struct {
	Key             PersonKey `json:"key"`
	HTTPRequestBody *Person   `json:"-"`
}

UpdateIn are the input arguments of Update.

type UpdateOut

type UpdateOut struct {
}

UpdateOut are the return values of Update.

type UpdateResponse

type UpdateResponse struct {
	HTTPResponse *http.Response
	// contains filtered or unexported fields
}

UpdateResponse is the response to Update.

func (*UpdateResponse) Get

func (_out *UpdateResponse) Get() (err error)

Get retrieves the return values.

Jump to

Keyboard shortcuts

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