Documentation ¶
Index ¶
- Variables
- func MakeDeletePeopleEndpoint(s Service) endpoint.Endpoint
- func MakeGetAPIStatusEndpoint(s Service) endpoint.Endpoint
- func MakeGetAllPeopleEndpoint(s Service) endpoint.Endpoint
- func MakeGetPeopleEndpoint(s Service) endpoint.Endpoint
- func MakeHTTPHandler(s Service, logger log.Logger) http.Handler
- func MakePatchPeopleEndpoint(s Service) endpoint.Endpoint
- func MakePostPeopleEndpoint(s Service) endpoint.Endpoint
- func MakePutPeopleEndpoint(s Service) endpoint.Endpoint
- type Endpoints
- func (e Endpoints) DeletePeople(ctx context.Context, uuid uuid.UUID) error
- func (e Endpoints) GetAPIStatus(ctx context.Context) (string, error)
- func (e Endpoints) GetAllPeople(ctx context.Context) ([]People, error)
- func (e Endpoints) GetPeople(ctx context.Context, uuid uuid.UUID) (People, error)
- func (e Endpoints) PatchPeople(ctx context.Context, uuid uuid.UUID, p People) error
- func (e Endpoints) PostPeople(ctx context.Context, p People) error
- func (e Endpoints) PutPeople(ctx context.Context, uuid uuid.UUID, p People) error
- type Middleware
- type People
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( ErrInconsistentUUIDs = errors.New("inconsistent UUIDs") ErrAlreadyExists = errors.New("already exists") ErrNotFound = errors.New("not found") )
Response errors
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 MakeDeletePeopleEndpoint ¶
MakeDeletePeopleEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetAPIStatusEndpoint ¶
MakeGetAPIStatusEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetAllPeopleEndpoint ¶
MakeGetAllPeopleEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakeGetPeopleEndpoint ¶
MakeGetPeopleEndpoint 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.
func MakePatchPeopleEndpoint ¶
MakePatchPeopleEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakePostPeopleEndpoint ¶
MakePostPeopleEndpoint returns an endpoint via the passed service. Primarily useful in a server.
func MakePutPeopleEndpoint ¶
MakePutPeopleEndpoint returns an endpoint via the passed service. Primarily useful in a server.
Types ¶
type Endpoints ¶
type Endpoints struct { PostPeopleEndpoint endpoint.Endpoint GetPeopleEndpoint endpoint.Endpoint PutPeopleEndpoint endpoint.Endpoint PatchPeopleEndpoint endpoint.Endpoint DeletePeopleEndpoint endpoint.Endpoint GetAllPeopleEndpoint endpoint.Endpoint GetAPIStatusEndpoint endpoint.Endpoint }
Endpoints collects all of the endpoints that compose a People 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 cs client.
func MakeServerEndpoints ¶
MakeServerEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Useful in a cs service server.
func (Endpoints) DeletePeople ¶
DeletePeople implements Service. Primarily useful in a client.
func (Endpoints) GetAPIStatus ¶
GetAPIStatus implements Service. Primarily useful in a client.
func (Endpoints) GetAllPeople ¶
GetAllPeople implements Service. Primarily useful in a client.
func (Endpoints) PatchPeople ¶
PatchPeople implements Service. Primarily useful in a client.
func (Endpoints) PostPeople ¶
PostPeople implements Service. Primarily useful in a client.
type Middleware ¶
Middleware describes the cs service (as opposed to endpoint) middleware.
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger) Middleware
LoggingMiddleware provides basic logging Middleware
type People ¶
type People struct { UUID uuid.UUID `json:"uuid,omitempty"` Survived *bool `json:"survived,omitempty"` Pclass *int `json:"pclass,omitempty"` Name string `json:"name,omitempty"` Sex string `json:"sex,omitempty"` Age *int `json:"age,omitempty"` SiblingsSpousesAbroad *bool `json:"siblings_spouses_abroad,omitempty"` ParentsChildrenAboard *bool `json:"parents_children_aboard,omitempty"` Fare *float32 `json:"fare,omitempty"` }
People represents a single passenger (People). UUID should be globally unique.
type Service ¶
type Service interface { PostPeople(ctx context.Context, p People) error GetPeople(ctx context.Context, uuid uuid.UUID) (People, error) PutPeople(ctx context.Context, uuid uuid.UUID, p People) error PatchPeople(ctx context.Context, uuid uuid.UUID, p People) error DeletePeople(ctx context.Context, uuid uuid.UUID) error GetAllPeople(ctx context.Context) ([]People, error) GetAPIStatus(ctx context.Context) (string, error) }
Service is a CRUD interface for People in the Titanic collection.