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
- Variables
- type Client
- func (_c *Client) Create(ctx context.Context, httpRequestBody *Person) (key PersonKey, err error)
- func (_c *Client) Delete(ctx context.Context, key PersonKey) (err error)
- func (_c *Client) ForHost(host string) *Client
- func (_c *Client) List(ctx context.Context) (httpResponseBody []PersonKey, err error)
- func (_c *Client) Load(ctx context.Context, key PersonKey) (httpResponseBody *Person, err error)
- func (_c *Client) LoadByEmail(ctx context.Context, email string) (httpResponseBody *Person, err error)
- func (_c *Client) Update(ctx context.Context, key PersonKey, httpRequestBody *Person) (err error)
- func (_c *Client) WebUI(r *http.Request) (res *http.Response, err error)
- func (_c *Client) WebUI_Get(ctx context.Context, url string) (res *http.Response, err error)
- func (_c *Client) WebUI_Post(ctx context.Context, url string, contentType string, body any) (res *http.Response, err error)
- type CreateIn
- type CreateOut
- type CreateResponse
- type DeleteIn
- type DeleteOut
- type DeleteResponse
- type ListIn
- type ListOut
- type ListResponse
- type LoadByEmailIn
- type LoadByEmailOut
- type LoadByEmailResponse
- type LoadIn
- type LoadOut
- type LoadResponse
- type MulticastClient
- func (_c *MulticastClient) Create(ctx context.Context, httpRequestBody *Person) <-chan *CreateResponse
- func (_c *MulticastClient) Delete(ctx context.Context, key PersonKey) <-chan *DeleteResponse
- func (_c *MulticastClient) ForHost(host string) *MulticastClient
- func (_c *MulticastClient) List(ctx context.Context) <-chan *ListResponse
- func (_c *MulticastClient) Load(ctx context.Context, key PersonKey) <-chan *LoadResponse
- func (_c *MulticastClient) LoadByEmail(ctx context.Context, email string) <-chan *LoadByEmailResponse
- func (_c *MulticastClient) Update(ctx context.Context, key PersonKey, httpRequestBody *Person) <-chan *UpdateResponse
- func (_c *MulticastClient) WebUI(ctx context.Context, r *http.Request) <-chan *pub.Response
- func (_c *MulticastClient) WebUI_Get(ctx context.Context, url string) <-chan *pub.Response
- func (_c *MulticastClient) WebUI_Post(ctx context.Context, url string, contentType string, body any) <-chan *pub.Response
- type Person
- type PersonKey
- type UpdateIn
- type UpdateOut
- type UpdateResponse
Constants ¶
const Hostname = "directory.example"
Hostname is the default hostname of the microservice: directory.example.
Variables ¶
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 (*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) WebUI ¶
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 ¶
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 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 ListOut ¶
type ListOut struct {
HTTPResponseBody []PersonKey `json:"httpResponseBody"`
}
ListOut are the return values of List.
type ListResponse ¶
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 ¶
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 ¶
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 ¶
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.
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.