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(ctx context.Context, method string, relURL string, contentType string, ...) (res *http.Response, err error)
- func (_c Client) WithOptions(opts ...pub.Option) Client
- 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, method string, relURL string, contentType string, ...) <-chan *pub.Response
- func (_c MulticastClient) WithOptions(opts ...pub.Option) MulticastClient
- 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 a lightweight proxy for making unicast calls to the directory.example microservice.
func NewClient ¶
NewClient creates a new unicast client proxy to the directory.example microservice.
func (Client) ForHost ¶
ForHost returns a copy of the client with a different hostname to be applied to requests.
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 ¶
func (_c Client) WebUI(ctx context.Context, method string, relURL string, contentType string, body any) (res *http.Response, err error)
WebUI provides a form for making web requests to the CRUD endpoints.
If a URL is provided, 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 a lightweight proxy for making multicast calls to the directory.example microservice.
func NewMulticastClient ¶
func NewMulticastClient(caller service.Publisher) MulticastClient
NewMulticastClient creates a new multicast client proxy 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 returns a copy of the client with a different hostname to be applied to requests.
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, method string, relURL string, contentType string, body any) <-chan *pub.Response
WebUI provides a form for making web requests to the CRUD endpoints.
If a URL is provided, 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.
func (MulticastClient) WithOptions ¶ added in v1.13.1
func (_c MulticastClient) WithOptions(opts ...pub.Option) MulticastClient
WithOptions returns a copy of the client with options to be applied to requests.
type Person ¶
type Person struct {
Birthday time.Time `json:"birthday,omitzero"`
Email string `json:"email,omitzero"`
FirstName string `json:"firstName,omitzero"`
Key PersonKey `json:"key,omitzero"`
LastName string `json:"lastName,omitzero"`
}
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.