server

package
v0.0.0-...-c835f56 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const PublicationTypeRSS string = "rss"

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 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

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

func (*PublisherRequestBody) Bind

func (p *PublisherRequestBody) Bind(r *http.Request) error

Bind implements Bind interface for chi Bind to map request body to request body struct, with simple validator

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

type PublisherResponseBody struct {
	// swagger:allOf
	*entity.Publisher
}

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

Jump to

Keyboard shortcuts

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