lorem

package
v0.0.0-...-d5bb415 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2017 License: GPL-3.0 Imports: 11 Imported by: 1

README

lorem

This is simple service module. Only for showing the micro service with HTTP and return json. The purpose for this service is only generating lorem ipsum paragraph and return the payload.

I am fully using all three functions from the golorem library.

Required libraries

go get github.com/go-kit/kit
go get github.com/drhodes/golorem
go get github.com/gorilla/mux
service.go

Business logic will be put here

endpoint.go

Endpoint will be created here

transport.go

Handling about encode and decode json

lorem.d

Go main function will be located under this folder. The dot d means daemon.

execute
cd $GOPATH
go run src/github.com/ru-rocker/gokit-playground/lorem/lorem.d/main.go

Documentation

Index

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 MakeHttpHandler

func MakeHttpHandler(ctx context.Context, endpoint Endpoints, logger log.Logger) http.Handler

Make Http Handler

func MakeLoremEndpoint

func MakeLoremEndpoint(svc Service) endpoint.Endpoint

creating Lorem Ipsum Endpoint

Types

type Endpoints

type Endpoints struct {
	LoremEndpoint endpoint.Endpoint
}

endpoints wrapper

type LoremRequest

type LoremRequest struct {
	RequestType string
	Min         int
	Max         int
}

request

type LoremResponse

type LoremResponse struct {
	Message string `json:"message"`
	Err     error  `json:"err,omitempty"`
}

response

type LoremService

type LoremService struct {
}

Implement service with empty struct

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
}

Define service interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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