profilesvcgrpc

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 9 Imported by: 0

README

profilesvcgrpc

This example illustrates how to expose profilesvc as gRPC APIs.

Prerequisites

  • Protocol buffer compiler v3
  • Go plugins for the protocol compiler

See gRPC Go Quickstart for installation instructions.

Generate the code

$ go generate

Test the server

Run the server:

$ go run cmd/main.go
2021/07/04 22:32:02 server listening at [::]:8080

Consume by grpcurl:

$ grpcurl -plaintext -d '{"profile": {"id": "1234", "name": "kun"}}' :8080 pb.Service/PostProfile
{

}
$ grpcurl -plaintext -d '{"id": "1234"}' :8080 pb.Service/GetProfile
{
  "profile": {
    "id": "1234",
    "name": "kun"
  }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInconsistentIDs = errors.New("inconsistent IDs")
	ErrAlreadyExists   = errors.New("already exists")
	ErrNotFound        = errors.New("not found")
)

Functions

func MakeEndpointOfDeleteAddress

func MakeEndpointOfDeleteAddress(s Service) endpoint.Endpoint

MakeEndpointOfDeleteAddress creates the endpoint for s.DeleteAddress.

func MakeEndpointOfDeleteProfile

func MakeEndpointOfDeleteProfile(s Service) endpoint.Endpoint

MakeEndpointOfDeleteProfile creates the endpoint for s.DeleteProfile.

func MakeEndpointOfGetAddress

func MakeEndpointOfGetAddress(s Service) endpoint.Endpoint

MakeEndpointOfGetAddress creates the endpoint for s.GetAddress.

func MakeEndpointOfGetAddresses

func MakeEndpointOfGetAddresses(s Service) endpoint.Endpoint

MakeEndpointOfGetAddresses creates the endpoint for s.GetAddresses.

func MakeEndpointOfGetProfile

func MakeEndpointOfGetProfile(s Service) endpoint.Endpoint

MakeEndpointOfGetProfile creates the endpoint for s.GetProfile.

func MakeEndpointOfPatchProfile

func MakeEndpointOfPatchProfile(s Service) endpoint.Endpoint

MakeEndpointOfPatchProfile creates the endpoint for s.PatchProfile.

func MakeEndpointOfPostAddress

func MakeEndpointOfPostAddress(s Service) endpoint.Endpoint

MakeEndpointOfPostAddress creates the endpoint for s.PostAddress.

func MakeEndpointOfPostProfile

func MakeEndpointOfPostProfile(s Service) endpoint.Endpoint

MakeEndpointOfPostProfile creates the endpoint for s.PostProfile.

func MakeEndpointOfPutProfile

func MakeEndpointOfPutProfile(s Service) endpoint.Endpoint

MakeEndpointOfPutProfile creates the endpoint for s.PutProfile.

func NewGRPCServer

func NewGRPCServer(svc Service, codecs grpccodec.Codecs) pb.ServiceServer

func ValidateDeleteAddressRequest

func ValidateDeleteAddressRequest(newSchema func(*DeleteAddressRequest) validating.Schema) httpoption.Validator

ValidateDeleteAddressRequest creates a validator for DeleteAddressRequest.

func ValidateDeleteProfileRequest

func ValidateDeleteProfileRequest(newSchema func(*DeleteProfileRequest) validating.Schema) httpoption.Validator

ValidateDeleteProfileRequest creates a validator for DeleteProfileRequest.

func ValidateGetAddressRequest

func ValidateGetAddressRequest(newSchema func(*GetAddressRequest) validating.Schema) httpoption.Validator

ValidateGetAddressRequest creates a validator for GetAddressRequest.

func ValidateGetAddressesRequest

func ValidateGetAddressesRequest(newSchema func(*GetAddressesRequest) validating.Schema) httpoption.Validator

ValidateGetAddressesRequest creates a validator for GetAddressesRequest.

func ValidateGetProfileRequest

func ValidateGetProfileRequest(newSchema func(*GetProfileRequest) validating.Schema) httpoption.Validator

ValidateGetProfileRequest creates a validator for GetProfileRequest.

func ValidatePatchProfileRequest

func ValidatePatchProfileRequest(newSchema func(*PatchProfileRequest) validating.Schema) httpoption.Validator

ValidatePatchProfileRequest creates a validator for PatchProfileRequest.

func ValidatePostAddressRequest

func ValidatePostAddressRequest(newSchema func(*PostAddressRequest) validating.Schema) httpoption.Validator

ValidatePostAddressRequest creates a validator for PostAddressRequest.

func ValidatePostProfileRequest

func ValidatePostProfileRequest(newSchema func(*PostProfileRequest) validating.Schema) httpoption.Validator

ValidatePostProfileRequest creates a validator for PostProfileRequest.

func ValidatePutProfileRequest

func ValidatePutProfileRequest(newSchema func(*PutProfileRequest) validating.Schema) httpoption.Validator

ValidatePutProfileRequest creates a validator for PutProfileRequest.

Types

type Address

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 DeleteAddressRequest

type DeleteAddressRequest struct {
	Id        string `json:"id"`
	AddressID string `json:"address_id"`
}

type DeleteAddressResponse

type DeleteAddressResponse struct {
	Err error `json:"-"`
}

func (*DeleteAddressResponse) Body

func (r *DeleteAddressResponse) Body() interface{}

func (*DeleteAddressResponse) Failed

func (r *DeleteAddressResponse) Failed() error

Failed implements endpoint.Failer.

type DeleteProfileRequest

type DeleteProfileRequest struct {
	Id string `json:"id"`
}

type DeleteProfileResponse

type DeleteProfileResponse struct {
	Err error `json:"-"`
}

func (*DeleteProfileResponse) Body

func (r *DeleteProfileResponse) Body() interface{}

func (*DeleteProfileResponse) Failed

func (r *DeleteProfileResponse) Failed() error

Failed implements endpoint.Failer.

type GetAddressRequest

type GetAddressRequest struct {
	Id        string `json:"id"`
	AddressID string `json:"address_id"`
}

type GetAddressResponse

type GetAddressResponse struct {
	Address Address `json:"address"`
	Err     error   `json:"-"`
}

func (*GetAddressResponse) Body

func (r *GetAddressResponse) Body() interface{}

func (*GetAddressResponse) Failed

func (r *GetAddressResponse) Failed() error

Failed implements endpoint.Failer.

type GetAddressesRequest

type GetAddressesRequest struct {
	Id string `json:"id"`
}

type GetAddressesResponse

type GetAddressesResponse struct {
	Addresses []Address `json:"addresses"`
	Err       error     `json:"-"`
}

func (*GetAddressesResponse) Body

func (r *GetAddressesResponse) Body() interface{}

func (*GetAddressesResponse) Failed

func (r *GetAddressesResponse) Failed() error

Failed implements endpoint.Failer.

type GetProfileRequest

type GetProfileRequest struct {
	Id string `json:"id"`
}

type GetProfileResponse

type GetProfileResponse struct {
	Profile Profile `json:"profile"`
	Err     error   `json:"-"`
}

func (*GetProfileResponse) Body

func (r *GetProfileResponse) Body() interface{}

func (*GetProfileResponse) Failed

func (r *GetProfileResponse) Failed() error

Failed implements endpoint.Failer.

type PatchProfileRequest

type PatchProfileRequest struct {
	Id      string  `json:"id"`
	Profile Profile `json:"profile"`
}

type PatchProfileResponse

type PatchProfileResponse struct {
	Err error `json:"-"`
}

func (*PatchProfileResponse) Body

func (r *PatchProfileResponse) Body() interface{}

func (*PatchProfileResponse) Failed

func (r *PatchProfileResponse) Failed() error

Failed implements endpoint.Failer.

type PostAddressRequest

type PostAddressRequest struct {
	Id      string  `json:"id"`
	Address Address `json:"address"`
}

type PostAddressResponse

type PostAddressResponse struct {
	Err error `json:"-"`
}

func (*PostAddressResponse) Body

func (r *PostAddressResponse) Body() interface{}

func (*PostAddressResponse) Failed

func (r *PostAddressResponse) Failed() error

Failed implements endpoint.Failer.

type PostProfileRequest

type PostProfileRequest struct {
	Profile Profile `json:"profile"`
}

type PostProfileResponse

type PostProfileResponse struct {
	Err error `json:"-"`
}

func (*PostProfileResponse) Body

func (r *PostProfileResponse) Body() interface{}

func (*PostProfileResponse) Failed

func (r *PostProfileResponse) Failed() error

Failed implements endpoint.Failer.

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

type PutProfileRequest struct {
	Id      string  `json:"id"`
	Profile Profile `json:"profile"`
}

type PutProfileResponse

type PutProfileResponse struct {
	Err error `json:"-"`
}

func (*PutProfileResponse) Body

func (r *PutProfileResponse) Body() interface{}

func (*PutProfileResponse) Failed

func (r *PutProfileResponse) Failed() error

Failed implements endpoint.Failer.

type Service

type Service interface {
	//kun:grpc
	PostProfile(ctx context.Context, profile Profile) (err error)

	//kun:grpc
	GetProfile(ctx context.Context, id string) (profile Profile, err error)

	//kun:grpc
	PutProfile(ctx context.Context, id string, profile Profile) (err error)

	//kun:grpc
	PatchProfile(ctx context.Context, id string, profile Profile) (err error)

	//kun:grpc
	DeleteProfile(ctx context.Context, id string) (err error)

	//kun:grpc
	GetAddresses(ctx context.Context, id string) (addresses []Address, err error)

	//kun:grpc
	GetAddress(ctx context.Context, id string, addressID string) (address Address, err error)

	//kun:grpc
	PostAddress(ctx context.Context, id string, address Address) (err error)

	//kun:grpc
	DeleteAddress(ctx context.Context, id string, addressID string) (err error)
}

Service is a simple CRUD interface for user profiles.

func NewInmemService

func NewInmemService() Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL