Documentation ¶
Overview ¶
Package webhttp is a generated GoMock package.
Index ¶
- Variables
- func Decode(reader io.Reader, dst interface{}) error
- func Encode(writer io.Writer, src interface{}) error
- func InjectLogger(logger logging.Logger) func(http.Handler) http.Handler
- func LogRequest() func(http.Handler) http.Handler
- func NewRouter(logger logging.Logger) chi.Router
- func NewServer(hl http.Handler) *http.Server
- func RequestContentType(contentType string) func(http.Handler) http.Handler
- func ResponseContentType(contentType string) func(http.Handler) http.Handler
- func Serve(ctx context.Context, logger logging.Logger, srv *http.Server, port int) error
- func StartServer(l net.Listener, srv *http.Server) error
- func StopServer(logger logging.Logger, srv *http.Server, gracePeriod time.Duration) error
- func WriteError(w http.ResponseWriter, logger logging.Logger, err error)
- type CreateUserReq
- type ErrorResponse
- type GetUserResp
- type InfoHandler
- type Mapper
- type MockUserService
- func (m *MockUserService) Create(ctx context.Context, user user.Entity) (string, error)
- func (m *MockUserService) Delete(ctx context.Context, id string) error
- func (m *MockUserService) EXPECT() *MockUserServiceMockRecorder
- func (m *MockUserService) Get(ctx context.Context, id string) (user.Entity, error)
- func (m *MockUserService) Update(ctx context.Context, id string, user user.Entity) error
- type MockUserServiceMockRecorder
- func (mr *MockUserServiceMockRecorder) Create(ctx, user interface{}) *gomock.Call
- func (mr *MockUserServiceMockRecorder) Delete(ctx, id interface{}) *gomock.Call
- func (mr *MockUserServiceMockRecorder) Get(ctx, id interface{}) *gomock.Call
- func (mr *MockUserServiceMockRecorder) Update(ctx, id, user interface{}) *gomock.Call
- type UpdateUserReq
- type UserBase
- type UserHandler
- func (uh *UserHandler) Create(w http.ResponseWriter, r *http.Request)
- func (uh *UserHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (uh *UserHandler) Get(w http.ResponseWriter, r *http.Request)
- func (uh *UserHandler) Register(router chi.Router)
- func (uh *UserHandler) Update(w http.ResponseWriter, r *http.Request)
- type UserService
Constants ¶
This section is empty.
Variables ¶
var AcceptsJSON = RequestContentType("application/json; charset=utf-8")
AcceptsJSON verifies request has a 'content-type' header with 'application/json' mime type.
var ProducesJSON = ResponseContentType("application/json; charset=utf-8")
ProducesJSON sets response header 'content-type' to with 'application/json' mime type.
Functions ¶
func InjectLogger ¶
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 ¶
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 ¶
NewRouter returns initialized HTTP router. It sets up all required middlewares and bindings for endpoints.
func RequestContentType ¶
RequestContentType returns a middleware function that verifies request has `content-type` header and its media type is equal to passed in value.
func ResponseContentType ¶
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 StopServer ¶
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 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 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) Delete ¶
func (m *MockUserService) Delete(ctx context.Context, id string) error
Delete mocks base method
func (*MockUserService) EXPECT ¶
func (m *MockUserService) EXPECT() *MockUserServiceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
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 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.