coffeeshop

package module
v0.0.0-...-a534038 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 13 Imported by: 0

README

Go Go Report Card GitHub GitHub go.mod Go version

coffeeshop

coffeeshop is a tiny web service for testing Terraform providers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delay

func Delay(d time.Duration) func(next http.Handler) http.Handler

func Run

func Run() error

func WithLatency

func WithLatency(l string) option

Types

type MemoryStore

type MemoryStore struct {
	Products Products
	// contains filtered or unexported fields
}

MemoryStore represents a storage for products in the CoffeeShop.

Use memory store for testing and development. For production use a SQL or NoSQL database.

func (*MemoryStore) GetAll

func (ms *MemoryStore) GetAll() []Product

GetAll returns all products in the store.

func (*MemoryStore) GetCoffee

func (ms *MemoryStore) GetCoffee() []Product

func (*MemoryStore) GetProduct

func (ms *MemoryStore) GetProduct(id string) (Product, error)

func (*MemoryStore) GetTea

func (ms *MemoryStore) GetTea() []Product

type Product

type Product struct {
	ID         string     `json:"id"`
	Type       string     `json:"type"`
	Brand      string     `json:"brand"`
	Name       string     `json:"name"`
	Unit       string     `json:"unit,omitempty"`
	Quantity   string     `json:"quantity,omitempty"`
	Price      string     `json:"price,omitempty"`
	Properties []Property `json:"properties,omitempty"`
}

Product represents a product in the inventory.

type Products

type Products map[string]Product

func (Products) MarshalJSON

func (p Products) MarshalJSON() ([]byte, error)

func (*Products) UnmarshalJSON

func (p *Products) UnmarshalJSON(data []byte) error

type Property

type Property struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Property holds additional, dynamic information about the product.

type Server

type Server struct {
	HTTPServer *http.Server
	URL        string
	Latency    time.Duration
	Store      Store
}

func New

func New(addr string, store Store, options ...option) (*Server, error)

func (*Server) GetCoffee

func (cs *Server) GetCoffee(w http.ResponseWriter, r *http.Request)

func (*Server) GetProduct

func (cs *Server) GetProduct(w http.ResponseWriter, r *http.Request)

func (*Server) GetProducts

func (cs *Server) GetProducts(w http.ResponseWriter, r *http.Request)

func (*Server) GetTea

func (cs *Server) GetTea(w http.ResponseWriter, r *http.Request)

func (*Server) ListenAndServe

func (cs *Server) ListenAndServe() error

func (*Server) Shutdown

func (cs *Server) Shutdown(ctx context.Context) error

type Store

type Store interface {
	GetAll() []Product
	GetProduct(id string) (Product, error)
	GetCoffee() []Product
	GetTea() []Product
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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