server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: 404,
	Body: ErrResponseBody{
		StatusText: "Resource not found.",
	},
}

ErrNotFound is 404

Functions

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem)

FileServer conveniently sets up a http.FileServer handler to serve static files from a http.FileSystem. Used for Swagger-UI and swagger.json files.

Types

type Config

type Config struct {
	Address        string `mapstructure:"address"`
	RequestTimeout int    `mapstructure:"request_timeout"`
}

Config defines webserver configuration

type ErrResponse

type ErrResponse struct {
	HTTPStatusCode int `json:"-"` // http response status code
	// in: body
	Body ErrResponseBody
}

ErrResponse renderer type for handling all sorts of errors. swagger:response ErrResponse

func ErrInternal

func ErrInternal(err error) *ErrResponse

ErrInternal returns internal server error

func ErrInvalidRequest

func ErrInvalidRequest(err error) *ErrResponse

ErrInvalidRequest returns failure due to incorrect request parameters or methods

func ErrRender

func ErrRender(err error) *ErrResponse

ErrRender returns error for rendering

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request)

Render forms output for ErrResponse

type ErrResponseBody

type ErrResponseBody struct {
	// user-level status message
	StatusText string `json:"status"`
	// application-level error message, for debugging
	ErrorText string `json:"error,omitempty"`
}

ErrResponseBody is readable output to application/human about error

type FeedRequest

type FeedRequest struct {
	Body FeedRequestBody
}

FeedRequest defines update/create request for single feed

type FeedRequestBody

type FeedRequestBody struct {
	*entity.Feed
}

FeedRequestBody defines data of request body

func (*FeedRequestBody) Bind

func (b *FeedRequestBody) Bind(r *http.Request) error

Bind implements Bind interface for chi Bind to map request body to request body struct

func (FeedRequestBody) Validate

func (b FeedRequestBody) Validate() error

Validate request body

type FeedResponse

type FeedResponse struct {
	// in: body
	Body FeedResponseBody
}

FeedResponse defines Feed response with Body and any additional headers swagger:response

func NewFeedResponse

func NewFeedResponse(f *entity.Feed) *FeedResponse

NewFeedResponse creates new response struct body for feed

func (*FeedResponse) Render

func (fp *FeedResponse) Render(w http.ResponseWriter, r *http.Request)

Render converts FeedResponseBody to json and sends it to client

type FeedResponseBody

type FeedResponseBody struct {
	// swagger:allOf
	*entity.Feed
}

FeedResponseBody is returned on successfull operations to get, create or delete feed.

type FeedsRepository

type FeedsRepository interface {
	Create(*entity.Feed) error
	Update(*entity.Feed) error
	Delete(uuid.UUID) error
	GetAll() ([]entity.Feed, error)
	GetByPublicationUUID(uuid.UUID) (*entity.Feed, error)
}

FeedsRepository defines repository methods used to manage feeds

type RSSFeedsUpdateProducer

type RSSFeedsUpdateProducer interface {
	SendUpdateOne(uuid.UUID) error
	SendUpdateAll() error
}

RSSFeedsUpdateProducer provides methods to call update (refresh news from) RSS Feed via messaging subsystem

type Server

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

Server defines HTTP application

func New

func New(serverConfig Config, logger logger.Logger, feedRepository FeedsRepository, messageProducer RSSFeedsUpdateProducer) *Server

New creates new server configuration and configurates middleware

func (*Server) StartAndServe

func (s *Server) StartAndServe()

startAndServe configures routers and starts http server

Jump to

Keyboard shortcuts

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