my shit
This commit is contained in:
+14
-5
@@ -1,11 +1,20 @@
|
||||
package models
|
||||
|
||||
import "context"
|
||||
|
||||
type Bridge struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Driver DriverKind `json:"driver"`
|
||||
Address string `json:"address"`
|
||||
Token string `json:"token"`
|
||||
ID int `json:"id" db:"id"`
|
||||
Name string `json:"name" db:"name"`
|
||||
Driver DriverKind `json:"driver" db:"driver"`
|
||||
Address string `json:"address" db:"address"`
|
||||
Token string `json:"-" db:"token"`
|
||||
}
|
||||
|
||||
type BridgeRepository interface {
|
||||
Find(ctx context.Context, id int) (Bridge, error)
|
||||
FetchAll(ctx context.Context) ([]Bridge, error)
|
||||
Save(ctx context.Context, bridge *Bridge) error
|
||||
Delete(ctx context.Context, bridge *Bridge) error
|
||||
}
|
||||
|
||||
type DriverKind string
|
||||
|
||||
@@ -2,7 +2,9 @@ package models
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrNotFound = errors.New("not found")
|
||||
var ErrInvalidName = errors.New("invalid name")
|
||||
var ErrBadInput = errors.New("bad input")
|
||||
var ErrBadColor = errors.New("bad color")
|
||||
var ErrInternal = errors.New("internal")
|
||||
var ErrUnknownColorFormat = errors.New("unknown color format")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package models
|
||||
|
||||
import "strconv"
|
||||
|
||||
type Event struct {
|
||||
Name string `json:"name"`
|
||||
Payload map[string]string `json:"payload,omitempty"`
|
||||
@@ -16,3 +18,10 @@ func (e *Event) AddPayload(key, value string) {
|
||||
func (e *Event) HasPayload(key string) bool {
|
||||
return e.Payload != nil && e.Payload[key] != ""
|
||||
}
|
||||
|
||||
func BridgeConnectedEvent(bridge Bridge) Event {
|
||||
e := Event{Name: "BridgeConnected"}
|
||||
e.AddPayload("id", strconv.Itoa(bridge.ID))
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user