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 CreateShortenReq
- type ErrorResponse
- type GetShortenResp
- type InfoHandler
- type ListShortenResp
- type Mapper
- type MockShortenService
- func (m *MockShortenService) Create(ctx context.Context, entity shorten.Entity) (int64, error)
- func (m *MockShortenService) Delete(ctx context.Context, id int64) error
- func (m *MockShortenService) EXPECT() *MockShortenServiceMockRecorder
- func (m *MockShortenService) Get(ctx context.Context, id int64) (shorten.Entity, error)
- func (m *MockShortenService) List(ctx context.Context, pager shorten.Pager) ([]shorten.Entity, error)
- func (m *MockShortenService) Resolve(ctx context.Context, hash string) (string, error)
- type MockShortenServiceMockRecorder
- func (mr *MockShortenServiceMockRecorder) Create(ctx, entity interface{}) *gomock.Call
- func (mr *MockShortenServiceMockRecorder) Delete(ctx, id interface{}) *gomock.Call
- func (mr *MockShortenServiceMockRecorder) Get(ctx, id interface{}) *gomock.Call
- func (mr *MockShortenServiceMockRecorder) List(ctx, pager interface{}) *gomock.Call
- func (mr *MockShortenServiceMockRecorder) Resolve(ctx, hash interface{}) *gomock.Call
- type ParamInt64Opts
- type ParamOpts
- type Resolver
- type ResolverHandler
- type ShortenHandler
- func (uh ShortenHandler) Create(w http.ResponseWriter, r *http.Request)
- func (uh ShortenHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (uh ShortenHandler) Get(w http.ResponseWriter, r *http.Request)
- func (uh ShortenHandler) List(w http.ResponseWriter, r *http.Request)
- func (uh ShortenHandler) Register(router chi.Router)
- type ShortenService
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingRequired = errors.New("missing required") ErrBadFormat = errors.New("bad format") )
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 baseHandler
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 CreateShortenReq ¶
type CreateShortenReq struct {
URL string `json:"url"`
}
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 GetShortenResp ¶
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 ListShortenResp ¶
type ListShortenResp []GetShortenResp
type MockShortenService ¶
type MockShortenService struct {
// contains filtered or unexported fields
}
MockShortenService is a mock of ShortenService interface
func NewMockShortenService ¶
func NewMockShortenService(ctrl *gomock.Controller) *MockShortenService
NewMockShortenService creates a new mock instance
func (*MockShortenService) Delete ¶
func (m *MockShortenService) Delete(ctx context.Context, id int64) error
Delete mocks base method
func (*MockShortenService) EXPECT ¶
func (m *MockShortenService) EXPECT() *MockShortenServiceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockShortenServiceMockRecorder ¶
type MockShortenServiceMockRecorder struct {
// contains filtered or unexported fields
}
MockShortenServiceMockRecorder is the mock recorder for MockShortenService
func (*MockShortenServiceMockRecorder) Create ¶
func (mr *MockShortenServiceMockRecorder) Create(ctx, entity interface{}) *gomock.Call
Create indicates an expected call of Create
func (*MockShortenServiceMockRecorder) Delete ¶
func (mr *MockShortenServiceMockRecorder) Delete(ctx, id interface{}) *gomock.Call
Delete indicates an expected call of Delete
func (*MockShortenServiceMockRecorder) Get ¶
func (mr *MockShortenServiceMockRecorder) Get(ctx, id interface{}) *gomock.Call
Get indicates an expected call of Get
func (*MockShortenServiceMockRecorder) List ¶
func (mr *MockShortenServiceMockRecorder) List(ctx, pager interface{}) *gomock.Call
List indicates an expected call of List
func (*MockShortenServiceMockRecorder) Resolve ¶
func (mr *MockShortenServiceMockRecorder) Resolve(ctx, hash interface{}) *gomock.Call
Resolve indicates an expected call of Resolve
type ParamInt64Opts ¶
type ResolverHandler ¶
type ResolverHandler struct {
// contains filtered or unexported fields
}
ResolverHandler redirects incoming requests by using request uri as a hash of the longer path.
func NewResolverHandler ¶
func NewResolverHandler(resolver Resolver) ResolverHandler
func (ResolverHandler) Register ¶
func (rh ResolverHandler) Register(router chi.Router)
func (ResolverHandler) Resolve ¶
func (rh ResolverHandler) Resolve(w http.ResponseWriter, r *http.Request)
type ShortenHandler ¶
type ShortenHandler struct {
// contains filtered or unexported fields
}
ShortenHandler handles request for the user entity(-ies).
func NewShortenHandler ¶
func NewShortenHandler(shortenService ShortenService) ShortenHandler
NewShortenHandler returns HTTP baseHandler initialized with provided service abstraction.
func (ShortenHandler) Create ¶
func (uh ShortenHandler) Create(w http.ResponseWriter, r *http.Request)
func (ShortenHandler) Delete ¶
func (uh ShortenHandler) Delete(w http.ResponseWriter, r *http.Request)
func (ShortenHandler) Get ¶
func (uh ShortenHandler) Get(w http.ResponseWriter, r *http.Request)
func (ShortenHandler) List ¶
func (uh ShortenHandler) List(w http.ResponseWriter, r *http.Request)
func (ShortenHandler) Register ¶
func (uh ShortenHandler) Register(router chi.Router)
Register creates a binding between method handlers and endpoints.
type ShortenService ¶
type ShortenService interface { // Create creates a new shorten and returns its unique identifier. Create(ctx context.Context, entity shorten.Entity) (int64, error) // Get returns a single shorten by its unique identifier. Get(ctx context.Context, id int64) (shorten.Entity, error) // List returns subset of all shortens. List(ctx context.Context, pager shorten.Pager) ([]shorten.Entity, error) // Delete removes shorten by its unique identifier. Delete(ctx context.Context, id int64) error // Resolve returns a full URL accessioned with the hash. Resolve(ctx context.Context, hash string) (string, error) }
ShortenService provides set of operations available to operate on the user entity.