Documentation ¶
Index ¶
- Constants
- Variables
- func FileServer(r chi.Router, path string, root http.FileSystem)
- type Config
- type ErrResponse
- type ErrResponseBody
- type Logger
- type PublicationConfig
- type PublicationRequest
- type PublicationRequestBody
- type PublicationResponse
- type PublicationResponseBody
- type PublicationsRepository
- type PublisherRequest
- type PublisherRequestBody
- type PublisherResponse
- type PublisherResponseBody
- type RSSFeedsAPIClient
- type RSSPublicationConfig
- type Server
Constants ¶
const PublicationTypeRSS string = "rss"
Variables ¶
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 (*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 Logger ¶
type Logger interface { Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) }
Logger interface
type PublicationConfig ¶
type PublicationConfig interface{}
PublicationConfig is used to pass around different config structs
type PublicationRequest ¶
type PublicationRequest struct { // in: body Body PublicationRequestBody }
PublicationRequest defines Publication create/update request with required Body and any additional headers
type PublicationRequestBody ¶
type PublicationRequestBody struct { // swagger:allOf Name string `json:"name"` Description string `json:"description"` LanguageCode string `json:"language_code"` PublisherUUID uuid.UUID `json:"publisher_uuid"` Type string `json:"publication_type"` // Config content is different for different publication types. // when parsing, we decide on Type Config PublicationConfig `json:"config"` }
PublicationRequestBody contains information on publication creation
func (*PublicationRequestBody) Validate ¶
func (b *PublicationRequestBody) Validate() error
Validate body
type PublicationResponse ¶
type PublicationResponse struct { // in: body Body PublicationResponseBody }
PublicationResponse defines response with data body and any additional headers swagger:response
func (*PublicationResponse) Render ¶
func (pr *PublicationResponse) Render(w http.ResponseWriter, r *http.Request)
Render converts PublicationResponseBody to json and sends it to client
type PublicationResponseBody ¶
type PublicationResponseBody struct { // swagger:allOf *entity.Publication }
PublicationResponseBody is returned on successfull operations to get, create publication.
type PublicationsRepository ¶
type PublicationsRepository interface { CreatePublication(context.Context, *entity.Publication) error UpdatePublication(context.Context, *entity.Publication) error DeletePublication(context.Context, uuid.UUID) error GetPublication(context.Context, uuid.UUID) (*entity.Publication, error) GetPublications(context.Context) ([]*entity.Publication, error) GetPublicationsByPublisher(context.Context, uuid.UUID) ([]*entity.Publication, error) CreatePublisher(context.Context, *entity.Publisher) error UpdatePublisher(context.Context, *entity.Publisher) error DeletePublisher(context.Context, uuid.UUID) error GetPublisher(context.Context, uuid.UUID) (*entity.Publisher, error) GetPublishers(context.Context) ([]*entity.Publisher, error) Healthcheck(context.Context) error }
PublicationsRepository represents repository for both publishers and publications
type PublisherRequest ¶
type PublisherRequest struct { // in: body Body PublisherRequestBody }
PublisherRequest defines Publisher request with Body and any additional headers
type PublisherRequestBody ¶
type PublisherRequestBody struct { // swagger:allOf Name string `json:"name"` URL string `json:"url"` }
PublisherRequestBody contains information on publisher creation
type PublisherResponse ¶
type PublisherResponse struct { // in: body Body PublisherResponseBody }
PublisherResponse defines Feed response with Body and any additional headers swagger:response
func (*PublisherResponse) Render ¶
func (pr *PublisherResponse) Render(w http.ResponseWriter, r *http.Request)
Render converts PublisherResponseBody to json and sends it to client
type PublisherResponseBody ¶
PublisherResponseBody is returned on successfull operations to get, create publisher.
type RSSFeedsAPIClient ¶
type RSSFeedsAPIClient interface { CreateRSSFeed(context.Context, uuid.UUID, string, string) error UpdateRSSFeed(context.Context, uuid.UUID, string, string) error DeleteRSSFeed(context.Context, uuid.UUID) error }
RSSFeedsAPIClient is used to call RSS Feeds service
type RSSPublicationConfig ¶
type RSSPublicationConfig struct {
URL string `json:"url"`
}
RSSPublicationConfig defines config for RSS Feeds
func (*RSSPublicationConfig) Validate ¶
func (c *RSSPublicationConfig) Validate() error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server defines HTTP application
func New ¶
func New(serverConfig Config, logger Logger, repository PublicationsRepository, rssFeedsAPIClient RSSFeedsAPIClient) *Server
New creates new server configuration and configurates middleware
func (*Server) StartAndServe ¶
func (s *Server) StartAndServe()
StartAndServe starts http server with signal control