devices

package
v0.0.0-...-80f9fc5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyLength = 32
)

Variables

View Source
var (
	ErrDeviceNotFound = internal.NewError(internal.ENOTFOUND, "Device not found", "device.not_found")
)

Functions

func GenerateAPIKey

func GenerateAPIKey(length int) (key string, err error)

Types

type Device

type Device struct {
	ID       string         `json:"id"`
	Name     string         `json:"name"`
	OwnerID  uint           `json:"owner_id"`
	LinkedAt time.Time      `json:"linked_at"`
	ApiKey   DeviceApiKey   `json:"api_key"`
	Webhook  *DeviceWebhook `json:"webhook"`
}

func (Device) Phone

func (d Device) Phone() string

type DeviceApiKey

type DeviceApiKey struct {
	ID        uint      `json:"id"`
	DeviceID  string    `json:"device_id"`
	Name      string    `json:"name"`
	Token     string    `json:"token"`
	CreatedAt time.Time `json:"created_at"`
}

type DeviceWebhook

type DeviceWebhook struct {
	DeviceID string
	URL      string
}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(provider StorageProvider, pbCli pb.ControllerServiceClient) *Storage

func (*Storage) ChangeID

func (s *Storage) ChangeID(id, newID string) error

On reconnect we need to change the device id to the new one

func (*Storage) Delete

func (s *Storage) Delete(id string) error

func (*Storage) GenNewDevAPIKey

func (s *Storage) GenNewDevAPIKey(deviceID string) error

func (*Storage) GetByAPIToken

func (s *Storage) GetByAPIToken(token string) (*Device, error)

func (*Storage) GetByID

func (s *Storage) GetByID(id string) (*Device, error)

func (*Storage) ListByOwnerID

func (s *Storage) ListByOwnerID(ownerID uint) ([]Device, error)

func (*Storage) Rename

func (s *Storage) Rename(id, newName string) error

func (*Storage) Save

func (s *Storage) Save(d *Device) error

func (*Storage) SaveWebhook

func (s *Storage) SaveWebhook(wh *DeviceWebhook) error

type StorageProvider

type StorageProvider interface {
	ListByOwnerID(uint) ([]Device, error)
	GetByID(string) (*Device, error)
	Save(*Device) error
	Patch(*Device) error
	Delete(string) error
	SaveAPIKey(*DeviceApiKey) error
	GetByAPIToken(string) (*Device, error)
	SaveWebhook(*DeviceWebhook) error // Deprecated
	ChangeID(id, newID string) error
}

type WebhookData

type WebhookData struct {
	From    string `json:"from"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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