types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: LGPL-3.0 Imports: 12 Imported by: 0

README

This folder contains the types that will be sent to the frontend. They are not the types which are recieved from the raw APIs - those should be kept in their respective parser files.

The type files should also contain the implemented Serialize() function for that specific type (so that it implements the InternalAPI interface)

Documentation

Index

Constants

View Source
const (
	APIWeather   string = "weather"
	APIText             = "text"
	APIClock            = "clock"
	APISlideshow        = "slideshow"
	APITwitter          = "twitter"
	APISysinfo          = "sysinfo"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	// Configure settings from raw json message
	Configure(message ClientMessage) error

	// Main loop that faciliates interaction between outside world and the client widet
	Run()

	// Data gets the data to send
	Data() (interface{}, error)

	GetName() string
	GetUUID() uuid.UUID
	GetSockets() map[Socket]bool
	GetPosition() Position
	SetPosition(Position)
	Stop()
	Send(interface{}, error)
	Running() bool

	AddSocket(Socket)
}

API is the entrance point of all apis to connect to a client

type BaseAPI

type BaseAPI struct {
	Position
	Name       string
	UUID       uuid.UUID
	Sockets    map[Socket]bool    `json:"-"`
	Pool       Pool               `json:"-"`
	CloseChan  chan CloseType     `json:"-"`
	ConfigChan chan ClientMessage `json:"-"`
	StopChans  []chan bool        `json:"-"`
	// contains filtered or unexported fields
}

BaseAPI base for all APIs

func (*BaseAPI) AddSocket

func (b *BaseAPI) AddSocket(socket Socket)

AddSocket to the api's internal socket list

func (*BaseAPI) AddStopChan

func (b *BaseAPI) AddStopChan() chan bool

func (*BaseAPI) Configure

func (b *BaseAPI) Configure(message ClientMessage) error

Configure based on an incoming client message

func (*BaseAPI) Data

func (b *BaseAPI) Data() (interface{}, error)

func (*BaseAPI) GetName

func (b *BaseAPI) GetName() string

GetName returns the name (or type) of the api

func (*BaseAPI) GetPosition

func (b *BaseAPI) GetPosition() Position

GetPosition returns position

func (*BaseAPI) GetSockets

func (b *BaseAPI) GetSockets() map[Socket]bool

GetSockets returns the apis socket connection

func (*BaseAPI) GetUUID

func (b *BaseAPI) GetUUID() uuid.UUID

GetUUID returns the uuid

func (*BaseAPI) Init

func (b *BaseAPI) Init(name string, sockets map[Socket]bool, pool Pool, id uuid.UUID)

Init Initialization

func (*BaseAPI) Run

func (b *BaseAPI) Run()

func (*BaseAPI) Running

func (b *BaseAPI) Running() bool

func (*BaseAPI) Send

func (b *BaseAPI) Send(data interface{}, err error)

Send to websocket

func (*BaseAPI) SetPosition

func (b *BaseAPI) SetPosition(pos Position)

SetPosition configures position

func (*BaseAPI) Stop

func (b *BaseAPI) Stop()

Stop the api

func (*BaseAPI) String

func (b *BaseAPI) String() string

type BaseMessage

type BaseMessage struct {
	Position
	Status MessageStatus
	Error  string      `json:",omitempty"`
	Data   interface{} `json:",omitempty"`
}

BaseMessage is the base message we are sending to frontend All structs being send to the frontend should inherit from this

type ClientAction

type ClientAction string

ClientAction is fun

const (
	ConfigureAPI      ClientAction = "ConfigureAPI"
	ConfigurePosition ClientAction = "ConfigurePosition"
	Delete            ClientAction = "Delete"
	ChangeAPI         ClientAction = "ChangeAPI"
	Initialize        ClientAction = "Init"
)

Types of actions

type ClientMessage

type ClientMessage struct {
	Action   ClientAction
	Position Position
	Config   json.RawMessage
	Name     string
}

ClientMessage for configuring

type ClockConfig

type ClockConfig struct {
	Location string
}

ClockConfig configuration arguments for clock api

type ClockResponse

type ClockResponse struct {
	ClockConfig
	Time int64
}

ClockResponse main format for data coming out of clock api

type CloseType

type CloseType struct {
	Sockets map[Socket]bool
	Save    bool
}

CloseType represents when a socket closes, or a forceful close if Socket is nil

type Clouds

type Clouds struct {
	All float64
}

Clouds contains cloud info

type Coord

type Coord struct {
	Lon float64
	Lat float64
}

Coord contains the lat and long

type DataObject

type DataObject interface {
	// Build builds the data object
	Update(interface{}) error

	// Transform turns the data object into a front-end parsable object
	Transform() interface{}
}

DataObject holds the data from the external API

type ImageDB

type ImageDB struct {
	// A map of tags to file locations?
	Images     []TaggedImage
	NumImages  int
	UniqueTags []string // the tag "all" means to show all?
}

ImageDB holds the images that we have access to

func NewImageDB

func NewImageDB() *ImageDB

func (*ImageDB) AddImage

func (db *ImageDB) AddImage(filepath string, file multipart.File, tagsList []string) error

func (*ImageDB) GetNumImages

func (db *ImageDB) GetNumImages() int

type Main

type Main struct {
	Temp      float64
	FeelsLike float64
	TempMin   float64
	TempMax   float64
	Pressure  float64
	Humidity  float64
}

Main contains a quick description of weather

type MessageStatus

type MessageStatus string

MessageStatus indicates the broad type of message sent back to the client

const (
	StatusSuccess MessageStatus = "success"
	StatusFailure MessageStatus = "failure"
)

Enumerates different possible message statuses

type Pool

type Pool interface {
	Register(API)
	Unregister(Unregister)
	Switch(API, ClientMessage) error
	Save()
	Add(string, uuid.UUID, map[Socket]bool) (API, error)
	GetImageDB() *ImageDB
	SaveImageDB()
}

Pool pool

type Position

type Position struct {
	X int    `json:"x"`
	Y int    `json:"y"`
	W int    `json:"w"`
	H int    `json:"h"`
	I string `json:"i"`
}

Position information for api widgets

type Rain

type Rain struct {
	OneHR float64 `json:"1h"`
}

Rain contains rain info

type SlideShowConfig

type SlideShowConfig struct {
	Speed        int
	IncludedTags []string
	UniqueTags   []string
}

type SlideShowResponse

type SlideShowResponse struct {
	SlideShowConfig
	FileImages []string
}

type Socket

type Socket interface {
	// Read information from the client
	Read()

	// Send information to the client
	Send(interface{})

	CloseChan() chan bool
	ConfigChan() chan ClientMessage

	// SendErrorMessage sends error message
	SendErrorMessage(error)
	SendSuccess(interface{}, Position)

	// Wrappers around underlying websocket connection
	Close() error
	RemoteAddr() net.Addr
}

Socket interface, needed to avoid circular dependency with Socket package

type Sys

type Sys struct {
	Type    float64
	ID      float64
	Country string
	Sunrise float64
	Sunset  float64
}

Sys contains info about the system?

type SysInfoConfig

type SysInfoConfig struct {
}

type SysInfoResponse

type SysInfoResponse struct {
	MemUsed         uint64
	MemTotal        uint64
	MemUsedPercent  float64
	DiskUsed        uint64
	DiskTotal       uint64
	DiskFree        uint64
	DiskUsedPercent float64
}

type TaggedImage

type TaggedImage struct {
	Tags     []string
	FilePath string
}

TaggedImage is an instance of an image with tags

type TextConfig

type TextConfig struct {
	Title string
	Text  string
}

type TextResponse

type TextResponse struct {
	TextConfig
}

type TwitterConfig

type TwitterConfig struct {
	ConsumerKey    string
	ConsumerSecret string
	AccessToken    string
	AccessSecret   string
	UserHandle     string
	TweetCount     int
}

TwitterConfig configuration arguments for twitter api

type TwitterResponse

type TwitterResponse struct {
	TwitterConfig
	Tweets []twitter.Tweet
}

TwitterResponse main format for data coming out of twitter api

type Unregister

type Unregister struct {
	API  API
	Save bool
}

Unregister stores info about which api to unregister, and weather the pool should be saved

type Weather

type Weather struct {
	ID          float64
	Description string
	Main        string
	Icon        string
}

Weather contains the current weather

type WeatherConfig

type WeatherConfig struct {
	Zip    int
	APIKey string
}

WeatherConfig are the config settings for the API

type WeatherResponse

type WeatherResponse struct {
	WeatherConfig
	Coord      Coord
	Weather    []Weather
	Base       string
	Main       Main
	Visibility float64
	Wind       Wind
	Rain       Rain
	Clouds     Clouds
	DT         float64
	Sys        Sys
	Timezone   float64
	ID         float64
	Name       string
	COD        float64
	Zipcode    float64
}

WeatherResponse is the struct that encodes the API data from our weather API

type Wind

type Wind struct {
	Speed float64
	Deg   float64
}

Wind contains wind information

Jump to

Keyboard shortcuts

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