Documentation ¶
Index ¶
- func Header(key, value string) func(http.Handler) http.Handler
- func HighlightMatchedProducts(hw hardwarer, matches []matching.MatchedProductDTO) error
- func Log(t logger.Type) func(http.Handler) http.Handler
- type APIError
- type AnswersDTO
- type Config
- type HeaderHandler
- type JSONData
- type Middleware
- type ProductCacheService
- type ProductWithAttributesDTO
- type ProductsWithAttributesDTO
- type QuestionDTO
- type ResultsDTO
- type Server
- type StandsDTO
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HighlightMatchedProducts ¶
func HighlightMatchedProducts(hw hardwarer, matches []matching.MatchedProductDTO) error
HighlightMatchedProducts on stands.
Types ¶
type APIError ¶
APIError returned from endpoints in json
func NewAPIError ¶
NewAPIError is just a constructor. Nothing extraordinary
type AnswersDTO ¶
type AnswersDTO struct {
Tags []string `json:"answers"`
}
AnswersDTO contains answers sent to the server.
type Config ¶
type Config struct { Port int `envconfig:"default=8080"` IP string `envconfig:"default=0.0.0.0"` Logger struct { Type logger.Type `envconfig:"default=3"` // TODO: consider changing logger to include request date } }
Config for server.
type HeaderHandler ¶
type HeaderHandler struct {
// contains filtered or unexported fields
}
HeaderHandler acts as middleware adding headers.
func (HeaderHandler) ServeHTTP ¶
func (h HeaderHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTP serves HTML document.
type JSONData ¶
type JSONData struct {
Array []QuestionDTO `json:"questions"`
}
JSONData stores array of QuestionDTOs.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware holds different chains of middleware and merges them as needed.
func (*Middleware) API ¶
func (m *Middleware) API(h http.HandlerFunc) http.Handler
API returns middleware chain containing common and api chain.
func (*Middleware) HTML ¶
func (m *Middleware) HTML(h http.HandlerFunc) http.Handler
HTML returns middleware chain containing common and html chain.
type ProductCacheService ¶
type ProductCacheService interface { GetProductDetailsByID(ID string) (ec.ProductDTO, error) UpdateProducts() error ForceUpdateProducts() error ForceUpdateProductByID(ID string) error }
ProductCacheService fetches products' data from repository. If no data is available then appropriate services are called. Introduced in order to reduce amount of calls to external services.
type ProductWithAttributesDTO ¶
type ProductWithAttributesDTO struct { ID string `json:"id"` Attributes []attributes.Attribute `json:"attributes"` }
ProductWithAttributesDTO contains information about product's ID and it's assigned attributes.
type ProductsWithAttributesDTO ¶
type ProductsWithAttributesDTO struct {
Products []ProductWithAttributesDTO `json:"mapping"`
}
ProductsWithAttributesDTO stores collection of ProductWithAttributesDTO.
type QuestionDTO ¶
type QuestionDTO struct { Text string `db:"question" json:"text"` Answers []string `db:"answers" json:"answers"` }
QuestionDTO is used to store questions and answers from JSON.
type ResultsDTO ¶
type ResultsDTO struct { Matched []matching.MatchedProductDTO `json:"matched"` HighlightedProduct int `json:"highlightedProduct"` }
ResultsDTO contains information about products matched by the service and index highlighted product.
type Server ¶
Server struct holds connectors and settings
func NewServer ¶
func NewServer(config *Config, productCacheService ProductCacheService, standsRepository standsRepository, standService standService, matchingService matchingService, attributesRepository attributesRepository, hardwareService hardwareService, questionsRepository questionsRepository) *Server
NewServer initializes server with needed connectors and default settings.