webhttp

package
v0.0.0-...-0fe9a67 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package webhttp is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var AcceptsJSON = RequestContentType("application/json; charset=utf-8")

AcceptsJSON verifies request has a 'content-type' header with 'application/json' mime type.

View Source
var ProducesJSON = ResponseContentType("application/json; charset=utf-8")

ProducesJSON sets response header 'content-type' to with 'application/json' mime type.

Functions

func Decode

func Decode(reader io.Reader, dst interface{}) error

func Encode

func Encode(writer io.Writer, src interface{}) error

func InjectLogger

func InjectLogger(logger logging.Logger) func(http.Handler) http.Handler

InjectLogger returns a middleware function that injects a logger into request's context. It also propagates logger with a request unique sequence number, so all the logs for a particular request could be grouped together.

func LogRequest

func LogRequest() func(http.Handler) http.Handler

LogRequest returns a middleware function that logs each incoming request. TODO: make logging level configurable so we could control log severity for each handler

func NewRouter

func NewRouter(logger logging.Logger) chi.Router

NewRouter returns initialized HTTP router. It sets up all required middlewares and bindings for endpoints.

func NewServer

func NewServer(hl http.Handler) *http.Server

func RequestContentType

func RequestContentType(contentType string) func(http.Handler) http.Handler

RequestContentType returns a middleware function that verifies request has `content-type` header and its media type is equal to passed in value.

func ResponseContentType

func ResponseContentType(contentType string) func(http.Handler) http.Handler

ResponseContentType returns a middleware function that sets passed in value as a `content-type` header to the HTTP response in case is not yet set.

func Serve

func Serve(ctx context.Context, logger logging.Logger, srv *http.Server, port int) error

func StartServer

func StartServer(l net.Listener, srv *http.Server) error

func StopServer

func StopServer(logger logging.Logger, srv *http.Server, gracePeriod time.Duration) error

func WriteError

func WriteError(w http.ResponseWriter, logger logging.Logger, err error)

WriteError sends an error response back to the client.

Types

type CreateUserReq

type CreateUserReq struct {
	UserBase
	Password string `json:"password,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	// StatusCode status code that should be returned.
	StatusCode int
	// Cause is an error that needs to be placed as a message describing what was wrong.
	Cause error
}

ErrorResponse aggregates error information into the struct and know how to send it back to the client.

func (ErrorResponse) Write

func (er ErrorResponse) Write(logger logging.Logger, w http.ResponseWriter)

type GetUserResp

type GetUserResp struct {
	UserBase
}

type InfoHandler

type InfoHandler struct{}

InfoHandler handles requests about service status.

func (InfoHandler) Liveness

func (InfoHandler) Liveness(w http.ResponseWriter, _ *http.Request)

Liveness returns HTTP status `200` for each request. It is used to determine if the service is healthy.

func (InfoHandler) Readiness

func (InfoHandler) Readiness(w http.ResponseWriter, _ *http.Request)

Readiness returns HTTP status `200` for each request. It is used to determine if the service is ready to start receiving requests.

func (InfoHandler) Register

func (ih InfoHandler) Register(router chi.Router)

Register creates a binding between method handlers and endpoints.

func (InfoHandler) Version

func (InfoHandler) Version(w http.ResponseWriter, _ *http.Request)

Version return information about binary: version, commit sha, timestamp of compilation

type Mapper

type Mapper struct{}

type MockUserService

type MockUserService struct {
	// contains filtered or unexported fields
}

MockUserService is a mock of UserService interface

func NewMockUserService

func NewMockUserService(ctrl *gomock.Controller) *MockUserService

NewMockUserService creates a new mock instance

func (*MockUserService) Create

func (m *MockUserService) Create(ctx context.Context, user user.Entity) (string, error)

Create mocks base method

func (*MockUserService) Delete

func (m *MockUserService) Delete(ctx context.Context, id string) error

Delete mocks base method

func (*MockUserService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockUserService) Get

func (m *MockUserService) Get(ctx context.Context, id string) (user.Entity, error)

Get mocks base method

func (*MockUserService) Update

func (m *MockUserService) Update(ctx context.Context, id string, user user.Entity) error

Update mocks base method

type MockUserServiceMockRecorder

type MockUserServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockUserServiceMockRecorder is the mock recorder for MockUserService

func (*MockUserServiceMockRecorder) Create

func (mr *MockUserServiceMockRecorder) Create(ctx, user interface{}) *gomock.Call

Create indicates an expected call of Create

func (*MockUserServiceMockRecorder) Delete

func (mr *MockUserServiceMockRecorder) Delete(ctx, id interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockUserServiceMockRecorder) Get

func (mr *MockUserServiceMockRecorder) Get(ctx, id interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockUserServiceMockRecorder) Update

func (mr *MockUserServiceMockRecorder) Update(ctx, id, user interface{}) *gomock.Call

Update indicates an expected call of Update

type UpdateUserReq

type UpdateUserReq struct {
	UserBase
}

type UserBase

type UserBase struct {
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Nickname  string `json:"nickname,omitempty"`
	Email     string `json:"email,omitempty"`
	Country   string `json:"country,omitempty"`
}

type UserHandler

type UserHandler struct {
	// contains filtered or unexported fields
}

UserHandler handles request for the user entity(-ies).

func NewUsersHandler

func NewUsersHandler(userService UserService) *UserHandler

NewUsersHandler returns HTTP handler initialized with provided service abstraction.

func (*UserHandler) Create

func (uh *UserHandler) Create(w http.ResponseWriter, r *http.Request)

func (*UserHandler) Delete

func (uh *UserHandler) Delete(w http.ResponseWriter, r *http.Request)

func (*UserHandler) Get

func (uh *UserHandler) Get(w http.ResponseWriter, r *http.Request)

func (*UserHandler) Register

func (uh *UserHandler) Register(router chi.Router)

Register creates a binding between method handlers and endpoints.

func (*UserHandler) Update

func (uh *UserHandler) Update(w http.ResponseWriter, r *http.Request)

type UserService

type UserService interface {
	// Create creates a new user entity and returns its unique identifier.
	Create(ctx context.Context, user user.Entity) (string, error)
	// Get returns user entity by its unique identifier.
	Get(ctx context.Context, id string) (user.Entity, error)
	// Update updates user entity found by unique identifier.
	Update(ctx context.Context, id string, user user.Entity) error
	// Delete removes user entity by its unique identifier.
	Delete(ctx context.Context, id string) error
}

UserService provides set of operations available to operate on the user entity.

Jump to

Keyboard shortcuts

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