Documentation ¶
Index ¶
- Constants
- Variables
- func AsyncBroadcast(ctx context.Context, b CanvasBroadcaster, l *zap.Logger, event CanvasEvent)
- func SyncBroadcast(ctx context.Context, b CanvasBroadcaster, l *zap.Logger, event CanvasEvent)
- func TransformFloodfill(canvas *Canvas, args TransformFloodfillArgs) error
- func TransformRectangle(canvas *Canvas, args TransformRectangleArgs) error
- func UUIDGenerator() (string, error)
- type BroadcastFunc
- type Canvas
- type CanvasBroadcaster
- type CanvasEvent
- type CanvasEventName
- type CanvasRepository
- type CanvasService
- func (s CanvasService) ApplyFloodfill(ctx context.Context, id string, args TransformFloodfillArgs) (*Canvas, error)
- func (s CanvasService) ApplyRectangle(ctx context.Context, id string, args TransformRectangleArgs) (*Canvas, error)
- func (s CanvasService) Create(ctx context.Context, args CreateArgs) (*Canvas, error)
- func (s CanvasService) Delete(ctx context.Context, id string) error
- func (s CanvasService) Get(ctx context.Context, id string) (*Canvas, error)
- func (s CanvasService) List(ctx context.Context) ([]Canvas, error)
- func (s CanvasService) Observe(ctx context.Context, id string) (StopObserveFunc, <-chan CanvasEvent, error)
- type Coordinates
- type CreateArgs
- type StopObserveFunc
- type TransformFloodfillArgs
- type TransformRectangleArgs
- type UUIDGeneratorFunc
Constants ¶
const ObserveALL = "all"
ObserveALL is a special keyword to observe all events
Variables ¶
var ( // ErrInvalidInput is for validation errors ErrInvalidInput = errors.New("invalid input") // ErrNotFound is when we cannot find something ErrNotFound = errors.New("item not found") // ErrOutOfBounds is when a cooridnate is out of bounds ErrOutOfBounds = errors.New("out of bounds") )
var IndexHTML []byte
Functions ¶
func AsyncBroadcast ¶
func AsyncBroadcast(ctx context.Context, b CanvasBroadcaster, l *zap.Logger, event CanvasEvent)
AsyncBroadcast uses a go routine
func SyncBroadcast ¶
func SyncBroadcast(ctx context.Context, b CanvasBroadcaster, l *zap.Logger, event CanvasEvent)
SyncBroadcast is blocking - useful for testing
func TransformFloodfill ¶
func TransformFloodfill(canvas *Canvas, args TransformFloodfillArgs) error
func TransformRectangle ¶
func TransformRectangle(canvas *Canvas, args TransformRectangleArgs) error
Types ¶
type BroadcastFunc ¶
type BroadcastFunc func(ctx context.Context, b CanvasBroadcaster, l *zap.Logger, event CanvasEvent)
BroadcastFunc denotes functions used for wrapping broadcasting features
type Canvas ¶
type Canvas struct { Id string `json:"id"` Name string `json:"name"` Content string `json:"content"` Width int `json:"width"` Height int `json:"height"` }
Canvas is an ascii art drawing
func (Canvas) AsLogFields ¶
AsLogFields is a helper for logging
func (Canvas) Contains ¶
func (c Canvas) Contains(coords Coordinates) bool
type CanvasBroadcaster ¶
type CanvasBroadcaster interface { Observe(ctx context.Context, id string) (StopObserveFunc, <-chan CanvasEvent, error) Broadcast(ctx context.Context, event CanvasEvent) error }
CanvasBroadcaster allows changes to be published or observed on a specific canvas
type CanvasEvent ¶
type CanvasEvent struct { Name CanvasEventName Canvas Canvas }
CanvasEvent emitted by a CanvasBroadcaster
type CanvasEventName ¶
type CanvasEventName string
CanvasEventName is the type of event emitted by CanvasEvent
const ( // CanvasEventCreated is emitted when a new Canvas has been created CanvasEventCreated CanvasEventName = "CREATED" // CanvasEventUpdated is emitted when an existing Canvas has been updated CanvasEventUpdated CanvasEventName = "UPDATED" // CanvasEventDeleted is emitted when an existing Canvas has been deleted CanvasEventDeleted CanvasEventName = "DELETED" )
type CanvasRepository ¶
type CanvasRepository interface { Create(ctx context.Context, canvas Canvas) error Update(ctx context.Context, canvas Canvas) error Get(ctx context.Context, id string) (*Canvas, error) List(ctx context.Context) ([]Canvas, error) Delete(ctx context.Context, id string) error }
CanvasRepository is for canvas persistence
type CanvasService ¶
type CanvasService struct { Repo CanvasRepository BroadCaster CanvasBroadcaster Logger *zap.Logger GenerateID UUIDGeneratorFunc Broadcast BroadcastFunc }
CanvasService provides applicative features
func (CanvasService) ApplyFloodfill ¶
func (s CanvasService) ApplyFloodfill(ctx context.Context, id string, args TransformFloodfillArgs) (*Canvas, error)
func (CanvasService) ApplyRectangle ¶
func (s CanvasService) ApplyRectangle(ctx context.Context, id string, args TransformRectangleArgs) (*Canvas, error)
ApplyRectangle loads a Canvas and uses TransformRectangle on it
func (CanvasService) Create ¶
func (s CanvasService) Create(ctx context.Context, args CreateArgs) (*Canvas, error)
Create a new Canvas
func (CanvasService) Delete ¶
func (s CanvasService) Delete(ctx context.Context, id string) error
Delete a specific Canvas item
func (CanvasService) List ¶
func (s CanvasService) List(ctx context.Context) ([]Canvas, error)
List all available Canvas items
func (CanvasService) Observe ¶
func (s CanvasService) Observe(ctx context.Context, id string) (StopObserveFunc, <-chan CanvasEvent, error)
type Coordinates ¶
Coordinates on a cartesian plane
func (Coordinates) String ¶
func (c Coordinates) String() string
type CreateArgs ¶
type CreateArgs struct { Name string `json:"name"` Fill string `json:"fill"` Width int `json:"width"` Height int `json:"height"` }
func (CreateArgs) AsLogFields ¶
func (a CreateArgs) AsLogFields() []zap.Field
AsLogFields is a helper for logging
func (CreateArgs) Validate ¶
func (a CreateArgs) Validate() error
type StopObserveFunc ¶
type StopObserveFunc func()
StopObserveFunc can be used to stop listening after calling Observe
type TransformFloodfillArgs ¶
type TransformFloodfillArgs struct { Start Coordinates `json:"start"` Fill string `json:"fill"` }
func (TransformFloodfillArgs) Validate ¶
func (a TransformFloodfillArgs) Validate() error
type TransformRectangleArgs ¶
type TransformRectangleArgs struct { TopLeft Coordinates `json:"top_left"` Width int `json:"width"` Height int `json:"height"` Fill string `json:"fill"` Outline string `json:"outline"` }
func (TransformRectangleArgs) Validate ¶
func (a TransformRectangleArgs) Validate() error
type UUIDGeneratorFunc ¶
UUIDGeneratorFunc denotes functions that can provide uuids
func StaticUUIDGenerator ¶
func StaticUUIDGenerator(id string, err error) UUIDGeneratorFunc
StaticUUIDGenerator generates predefined uuid and err; useful for testing