Documentation ¶
Index ¶
- Variables
- func DecodeLoremRequest(_ context.Context, r *http.Request) (interface{}, error)
- func EncodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error
- func Hystrix(commandName string, fallbackMesg string, logger log.Logger) endpoint.Middleware
- func MakeHealthEndpoint(svc Service) endpoint.Endpoint
- func MakeHttpHandler(_ context.Context, endpoint Endpoints, logger log.Logger) http.Handler
- func MakeLoremLoggingEndpoint(svc Service) endpoint.Endpoint
- func Register(consulAddress string, consulPort string, advertiseAddress string, ...) (registar sd.Registrar)
- type Endpoints
- type HealthRequest
- type HealthResponse
- type LoremRequest
- type LoremResponse
- type LoremService
- type Service
- type ServiceMiddleware
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrBadRouting is returned when an expected path variable is missing. ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)") )
View Source
var (
ErrRequestTypeNotFound = errors.New("Request type only valid for word, sentence and paragraph")
)
Functions ¶
func DecodeLoremRequest ¶
decode url path variables into request
func EncodeResponse ¶
func EncodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error
encodeResponse is the common method to encode all response types to the client.
func MakeHealthEndpoint ¶
creating health endpoint
func MakeHttpHandler ¶
Make Http Handler
func MakeLoremLoggingEndpoint ¶
creating Lorem Ipsum Endpoint
Types ¶
type LoremRequest ¶
type LoremRequest struct { RequestType string `json:"requestType"` Min int `json:"min"` Max int `json:"max"` }
Lorem Request
type LoremResponse ¶
Lorem Response
type LoremService ¶
type LoremService struct { }
Implement service with empty struct
func (LoremService) HealthCheck ¶
func (LoremService) HealthCheck() bool
func (LoremService) Paragraph ¶
func (LoremService) Paragraph(min, max int) string
func (LoremService) Sentence ¶
func (LoremService) Sentence(min, max int) string
func (LoremService) Word ¶
func (LoremService) Word(min, max int) string
Implement service functions
type Service ¶
type Service interface { // generate a word with at least min letters and at most max letters. Word(min, max int) string // generate a sentence with at least min words and at most max words. Sentence(min, max int) string // generate a paragraph with at least min sentences and at most max sentences. Paragraph(min, max int) string // health check HealthCheck() bool }
Define service interface
type ServiceMiddleware ¶
create type that return function. this will be needed in main.go
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger) ServiceMiddleware
implement function to return ServiceMiddleware
Source Files ¶
Click to show internal directories.
Click to hide internal directories.