Documentation
¶
Index ¶
- Variables
- func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint[DeleteAddressRequest, DeleteAddressResponse]
- func MakeDeleteProfileEndpoint(s Service) endpoint.Endpoint[DeleteProfileRequest, DeleteProfileResponse]
- func MakeGetAddressEndpoint(s Service) endpoint.Endpoint[GetAddressRequest, GetAddressResponse]
- func MakeGetAddressesEndpoint(s Service) endpoint.Endpoint[GetAddressesRequest, GetAddressesResponse]
- func MakeGetProfileEndpoint(s Service) endpoint.Endpoint[GetProfileRequest, GetProfileResponse]
- func MakeHTTPHandler(s Service, logger log.Logger) http.Handler
- func MakePatchProfileEndpoint(s Service) endpoint.Endpoint[PatchProfileRequest, PatchProfileResponse]
- func MakePostAddressEndpoint(s Service) endpoint.Endpoint[PostAddressRequest, PostAddressResponse]
- func MakePostProfileEndpoint(s Service) endpoint.Endpoint[PostProfileRequest, PostProfileResponse]
- func MakePutProfileEndpoint(s Service) endpoint.Endpoint[PutProfileRequest, PutProfileResponse]
- type Address
- type DeleteAddressRequest
- type DeleteAddressResponse
- type DeleteProfileRequest
- type DeleteProfileResponse
- type Endpoints
- func (e Endpoints) DeleteAddress(ctx context.Context, profileID string, addressID string) error
- func (e Endpoints) DeleteProfile(ctx context.Context, id string) error
- func (e Endpoints) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error)
- func (e Endpoints) GetAddresses(ctx context.Context, profileID string) ([]Address, error)
- func (e Endpoints) GetProfile(ctx context.Context, id string) (Profile, error)
- func (e Endpoints) PatchProfile(ctx context.Context, id string, p Profile) error
- func (e Endpoints) PostAddress(ctx context.Context, profileID string, a Address) error
- func (e Endpoints) PostProfile(ctx context.Context, p Profile) error
- func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error
- type GetAddressRequest
- type GetAddressResponse
- type GetAddressesRequest
- type GetAddressesResponse
- type GetProfileRequest
- type GetProfileResponse
- type Middleware
- type PatchProfileRequest
- type PatchProfileResponse
- type PostAddressRequest
- type PostAddressResponse
- type PostProfileRequest
- type PostProfileResponse
- type Profile
- type PutProfileRequest
- type PutProfileResponse
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( ErrInconsistentIDs = errors.New("inconsistent IDs") ErrAlreadyExists = errors.New("already exists") ErrNotFound = errors.New("not found") )
var ( // ErrBadRouting is returned when an expected path variable is missing. // It always indicates programmer error. ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)") )
Functions ¶
func MakeDeleteAddressEndpoint ¶
func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint[DeleteAddressRequest, DeleteAddressResponse]
MakeDeleteAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeDeleteProfileEndpoint ¶
func MakeDeleteProfileEndpoint(s Service) endpoint.Endpoint[DeleteProfileRequest, DeleteProfileResponse]
MakeDeleteProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetAddressEndpoint ¶
func MakeGetAddressEndpoint(s Service) endpoint.Endpoint[GetAddressRequest, GetAddressResponse]
MakeGetAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetAddressesEndpoint ¶
func MakeGetAddressesEndpoint(s Service) endpoint.Endpoint[GetAddressesRequest, GetAddressesResponse]
MakeGetAddressesEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetProfileEndpoint ¶
func MakeGetProfileEndpoint(s Service) endpoint.Endpoint[GetProfileRequest, GetProfileResponse]
MakeGetProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeHTTPHandler ¶
MakeHTTPHandler mounts all of the service endpoints into an http.Handler. Useful in a profilesvc server.
func MakePatchProfileEndpoint ¶
func MakePatchProfileEndpoint(s Service) endpoint.Endpoint[PatchProfileRequest, PatchProfileResponse]
MakePatchProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakePostAddressEndpoint ¶
func MakePostAddressEndpoint(s Service) endpoint.Endpoint[PostAddressRequest, PostAddressResponse]
MakePostAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakePostProfileEndpoint ¶
func MakePostProfileEndpoint(s Service) endpoint.Endpoint[PostProfileRequest, PostProfileResponse]
MakePostProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakePutProfileEndpoint ¶
func MakePutProfileEndpoint(s Service) endpoint.Endpoint[PutProfileRequest, PutProfileResponse]
MakePutProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.
Types ¶
type Address ¶
Address is a field of a user profile. ID should be unique within the profile (at a minimum).
type DeleteAddressRequest ¶ added in v0.18.0
type DeleteAddressResponse ¶ added in v0.18.0
type DeleteAddressResponse struct {
Err error `json:"err,omitempty"`
}
type DeleteProfileRequest ¶ added in v0.18.0
type DeleteProfileRequest struct {
ID string
}
type DeleteProfileResponse ¶ added in v0.18.0
type DeleteProfileResponse struct {
Err error `json:"err,omitempty"`
}
type Endpoints ¶
type Endpoints struct {
PostProfileEndpoint endpoint.Endpoint[PostProfileRequest, PostProfileResponse]
GetProfileEndpoint endpoint.Endpoint[GetProfileRequest, GetProfileResponse]
PutProfileEndpoint endpoint.Endpoint[PutProfileRequest, PutProfileResponse]
PatchProfileEndpoint endpoint.Endpoint[PatchProfileRequest, PatchProfileResponse]
DeleteProfileEndpoint endpoint.Endpoint[DeleteProfileRequest, DeleteProfileResponse]
GetAddressesEndpoint endpoint.Endpoint[GetAddressesRequest, GetAddressesResponse]
GetAddressEndpoint endpoint.Endpoint[GetAddressRequest, GetAddressResponse]
PostAddressEndpoint endpoint.Endpoint[PostAddressRequest, PostAddressResponse]
DeleteAddressEndpoint endpoint.Endpoint[DeleteAddressRequest, DeleteAddressResponse]
}
Endpoints collects all of the endpoints that compose a profile service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.
In a server, it's useful for functions that need to operate on a per-endpoint basis. For example, you might pass an Endpoints to a function that produces an http.Handler, with each method (endpoint) wired up to a specific path. (It is probably a mistake in design to invoke the Service methods on the Endpoints struct in a server.)
In a client, it's useful to collect individually constructed endpoints into a single type that implements the Service interface. For example, you might construct individual endpoints using transport/http.NewClient, combine them into an Endpoints, and return it to the caller as a Service.
func MakeClientEndpoints ¶
MakeClientEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the remote instance, via a transport/http.Client. Useful in a profilesvc client.
func MakeServerEndpoints ¶
MakeServerEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Useful in a profilesvc server.
func (Endpoints) DeleteAddress ¶
DeleteAddress implements Service. Primarily useful in a client.
func (Endpoints) DeleteProfile ¶
DeleteProfile implements Service. Primarily useful in a client.
func (Endpoints) GetAddress ¶
func (e Endpoints) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error)
GetAddress implements Service. Primarily useful in a client.
func (Endpoints) GetAddresses ¶
GetAddresses implements Service. Primarily useful in a client.
func (Endpoints) GetProfile ¶
GetProfile implements Service. Primarily useful in a client.
func (Endpoints) PatchProfile ¶
PatchProfile implements Service. Primarily useful in a client.
func (Endpoints) PostAddress ¶
PostAddress implements Service. Primarily useful in a client.
func (Endpoints) PostProfile ¶
PostProfile implements Service. Primarily useful in a client.
type GetAddressRequest ¶ added in v0.18.0
type GetAddressResponse ¶ added in v0.18.0
type GetAddressesRequest ¶ added in v0.18.0
type GetAddressesRequest struct {
ProfileID string
}
type GetAddressesResponse ¶ added in v0.18.0
type GetProfileRequest ¶ added in v0.18.0
type GetProfileRequest struct {
ID string
}
type GetProfileResponse ¶ added in v0.18.0
type Middleware ¶
Middleware describes a service (as opposed to endpoint) middleware.
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger) Middleware
type PatchProfileRequest ¶ added in v0.18.0
type PatchProfileResponse ¶ added in v0.18.0
type PatchProfileResponse struct {
Err error `json:"err,omitempty"`
}
type PostAddressRequest ¶ added in v0.18.0
type PostAddressResponse ¶ added in v0.18.0
type PostAddressResponse struct {
Err error `json:"err,omitempty"`
}
type PostProfileRequest ¶ added in v0.18.0
type PostProfileRequest struct {
Profile Profile
}
type PostProfileResponse ¶ added in v0.18.0
type PostProfileResponse struct {
Err error `json:"err,omitempty"`
}
type Profile ¶
type Profile struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Addresses []Address `json:"addresses,omitempty"`
}
Profile represents a single user profile. ID should be globally unique.
type PutProfileRequest ¶ added in v0.18.0
type PutProfileResponse ¶ added in v0.18.0
type PutProfileResponse struct {
Err error `json:"err,omitempty"`
}
type Service ¶
type Service interface {
PostProfile(ctx context.Context, p Profile) error
GetProfile(ctx context.Context, id string) (Profile, error)
PutProfile(ctx context.Context, id string, p Profile) error
PatchProfile(ctx context.Context, id string, p Profile) error
DeleteProfile(ctx context.Context, id string) error
GetAddresses(ctx context.Context, profileID string) ([]Address, error)
GetAddress(ctx context.Context, profileID string, addressID string) (Address, error)
PostAddress(ctx context.Context, profileID string, a Address) error
DeleteAddress(ctx context.Context, profileID string, addressID string) error
}
Service is a simple CRUD interface for user profiles.
func NewInmemService ¶
func NewInmemService() Service
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides a profilesvc client based on a predefined Consul service name and relevant tags.
|
Package client provides a profilesvc client based on a predefined Consul service name and relevant tags. |
|
cmd
|
|
|
profilesvc
command
|