server

package
v0.0.0-...-461d2ee Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Header(key, value string) func(http.Handler) http.Handler

Header creates HeaderHandler middleware.

func HighlightMatchedProducts

func HighlightMatchedProducts(hw hardwarer, matches []matching.MatchedProductDTO) error

HighlightMatchedProducts on stands.

func Log

func Log(t logger.Type) func(http.Handler) http.Handler

Log logs data to stdout with github.com/go-http-utils/logger.

Types

type APIError

type APIError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

APIError returned from endpoints in json

func NewAPIError

func NewAPIError(msg string, code int) APIError

NewAPIError is just a constructor. Nothing extraordinary

func (APIError) Send

func (e APIError) Send(w http.ResponseWriter) error

Send sends a marshaled Error with given code

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

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

type Server struct {
	Router mux.Router
	// contains filtered or unexported fields
}

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.

func (*Server) Start

func (s *Server) Start() error

Start runs server.

type StandsDTO

type StandsDTO struct {
	Stands []stands.StandDTO `json:"stands"`
}

StandsDTO stores list of stands for unmarshaling

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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