kit: github.com/go-kit/kit/examples/profilesvc Index | Files | Directories

package profilesvc

import "github.com/go-kit/kit/examples/profilesvc"

Index

Package Files

endpoints.go middlewares.go service.go transport.go

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)")
)

func MakeDeleteAddressEndpoint Uses

func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint

MakeDeleteAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakeDeleteProfileEndpoint Uses

func MakeDeleteProfileEndpoint(s Service) endpoint.Endpoint

MakeDeleteProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakeGetAddressEndpoint Uses

func MakeGetAddressEndpoint(s Service) endpoint.Endpoint

MakeGetAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakeGetAddressesEndpoint Uses

func MakeGetAddressesEndpoint(s Service) endpoint.Endpoint

MakeGetAddressesEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakeGetProfileEndpoint Uses

func MakeGetProfileEndpoint(s Service) endpoint.Endpoint

MakeGetProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakeHTTPHandler Uses

func MakeHTTPHandler(s Service, logger log.Logger) http.Handler

MakeHTTPHandler mounts all of the service endpoints into an http.Handler. Useful in a profilesvc server.

func MakePatchProfileEndpoint Uses

func MakePatchProfileEndpoint(s Service) endpoint.Endpoint

MakePatchProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakePostAddressEndpoint Uses

func MakePostAddressEndpoint(s Service) endpoint.Endpoint

MakePostAddressEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakePostProfileEndpoint Uses

func MakePostProfileEndpoint(s Service) endpoint.Endpoint

MakePostProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.

func MakePutProfileEndpoint Uses

func MakePutProfileEndpoint(s Service) endpoint.Endpoint

MakePutProfileEndpoint returns an endpoint via the passed service. Primarily useful in a server.

type Address Uses

type Address struct {
    ID       string `json:"id"`
    Location string `json:"location,omitempty"`
}

Address is a field of a user profile. ID should be unique within the profile (at a minimum).

type Endpoints Uses

type Endpoints struct {
    PostProfileEndpoint   endpoint.Endpoint
    GetProfileEndpoint    endpoint.Endpoint
    PutProfileEndpoint    endpoint.Endpoint
    PatchProfileEndpoint  endpoint.Endpoint
    DeleteProfileEndpoint endpoint.Endpoint
    GetAddressesEndpoint  endpoint.Endpoint
    GetAddressEndpoint    endpoint.Endpoint
    PostAddressEndpoint   endpoint.Endpoint
    DeleteAddressEndpoint endpoint.Endpoint
}

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 Uses

func MakeClientEndpoints(instance string) (Endpoints, error)

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 Uses

func MakeServerEndpoints(s Service) Endpoints

MakeServerEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Useful in a profilesvc server.

func (Endpoints) DeleteAddress Uses

func (e Endpoints) DeleteAddress(ctx context.Context, profileID string, addressID string) error

DeleteAddress implements Service. Primarily useful in a client.

func (Endpoints) DeleteProfile Uses

func (e Endpoints) DeleteProfile(ctx context.Context, id string) error

DeleteProfile implements Service. Primarily useful in a client.

func (Endpoints) GetAddress Uses

func (e Endpoints) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error)

GetAddress implements Service. Primarily useful in a client.

func (Endpoints) GetAddresses Uses

func (e Endpoints) GetAddresses(ctx context.Context, profileID string) ([]Address, error)

GetAddresses implements Service. Primarily useful in a client.

func (Endpoints) GetProfile Uses

func (e Endpoints) GetProfile(ctx context.Context, id string) (Profile, error)

GetProfile implements Service. Primarily useful in a client.

func (Endpoints) PatchProfile Uses

func (e Endpoints) PatchProfile(ctx context.Context, id string, p Profile) error

PatchProfile implements Service. Primarily useful in a client.

func (Endpoints) PostAddress Uses

func (e Endpoints) PostAddress(ctx context.Context, profileID string, a Address) error

PostAddress implements Service. Primarily useful in a client.

func (Endpoints) PostProfile Uses

func (e Endpoints) PostProfile(ctx context.Context, p Profile) error

PostProfile implements Service. Primarily useful in a client.

func (Endpoints) PutProfile Uses

func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error

PutProfile implements Service. Primarily useful in a client.

type Middleware Uses

type Middleware func(Service) Service

Middleware describes a service (as opposed to endpoint) middleware.

func LoggingMiddleware Uses

func LoggingMiddleware(logger log.Logger) Middleware

type Profile Uses

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 Service Uses

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 Uses

func NewInmemService() Service

Directories

PathSynopsis
clientPackage client provides a profilesvc client based on a predefined Consul service name and relevant tags.

Package profilesvc imports 14 packages (graph) and is imported by 4 packages. Updated 2017-07-13. Refresh now. Tools for package owners.