Documentation ¶
Index ¶
- func NewRedisClient(addr string) (*redis.Client, error)
- func UnmarshalRedis(id string, items map[string]int, order *Order) error
- type Item
- type Order
- type Response
- type Server
- func (s *Server) InitPromReg()
- func (s *Server) RedisGetNextOrderID(ctx context.Context) (int64, error)
- func (s *Server) RedisGetOrder(ctx context.Context, id int64) (*Order, error)
- func (s *Server) RedisScanOrders(ctx context.Context) ([]int64, error)
- func (s *Server) RedisSetOrder(ctx context.Context, o *Order) error
- func (s *Server) Respond(ctx context.Context, status int, m string, c int, data []*Order, ...)
- func (s *Server) Run() error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Stop()
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRedisClient ¶
NewRedisClient creates a new go-redis/redis client according to passed options. Address needs to be a valid redis URL, e.g. redis://127.0.0.1:6379/0 or redis://:qwerty@localhost:6379/1
Types ¶
type Item ¶
Item holds stripped down information of a regular item, to be used in an Order.
type Order ¶
Order defines a placed order with identifier and items. An Order ID of -1 means that the item can be
func NewOrder ¶
NewOrder creates a new order according to arguments. This will sort the passed items.
func (*Order) MarshalRedis ¶
MarshalRedis marshals an Order to hand over to go-redis.
type Response ¶
type Response struct { Status int `json:"status"` Message string `json:"message"` Count int `json:"count"` Data []*Order `json:"data"` }
Response defines an API response.
func NewResponse ¶
NewResponse returns a Response with a passed message string and slice of Data. TODO: make d variadic
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a wrapper for a HTTP server, with dependencies attached.
func NewServer ¶
func NewServer(options ...ServerOptions) (*Server, error)
NewServer creates a new Server according to options.
func (*Server) InitPromReg ¶ added in v0.2.1
func (s *Server) InitPromReg()
InitPromReg initializes a custom Prometheus registry with Collectors.
func (*Server) RedisGetNextOrderID ¶
RedisGetNextOrderID retrieves increments the order ID counter in redis and returns it.
func (*Server) RedisGetOrder ¶
RedisGetOrder retrieves a single order from Redis.
func (*Server) RedisScanOrders ¶
RedisScanOrders retrieves the IDs (keys) of all orders.
func (*Server) RedisSetOrder ¶
RedisSetOrder creates or updates a new order in Redis.
func (*Server) Respond ¶
func (s *Server) Respond(ctx context.Context, status int, m string, c int, data []*Order, w http.ResponseWriter)
Respond sends a JSON-encoded response.
type ServerOptions ¶
ServerOptions sets options when creating a new server.
func SetItemServiceAddress ¶
func SetItemServiceAddress(address string) ServerOptions
SetItemServiceAddress sets the address to reach the Item service.
func SetLogLevel ¶
func SetLogLevel(level string) ServerOptions
SetLogLevel sets the log level to either debug, warn, error or info. Info is default.
func SetRedisAddress ¶
func SetRedisAddress(address string) ServerOptions
SetRedisAddress sets a custom address for the redis connection.
func SetServerAddress ¶
func SetServerAddress(address string) ServerOptions
SetServerAddress sets the server address.
func SetServerEndpoint ¶
func SetServerEndpoint(address string) ServerOptions
SetServerEndpoint sets the server endpoint address for other services to call it.