pkg

package
v0.0.0-...-4f8ca3f Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID int
	// contains filtered or unexported fields
}

Client stores a connected client.

func NewClient

func NewClient(conn *websocket.Conn) *Client

NewClient creates a new connected client.

func (*Client) Close

func (c *Client) Close()

Close the client connection.

func (*Client) Handle

func (c *Client) Handle()

func (*Client) OnReceive

func (c *Client) OnReceive(f func(msg Message))

OnReceive define the receiving callback.

func (*Client) Receive

func (c *Client) Receive(msg Message)

Receive should be called when the client receive a message.

func (*Client) Send

func (c *Client) Send(msg Message)

Send should be called when the client send a message.

type Hub

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

func NewHub

func NewHub(ch chan Message) *Hub

NewHub return a new clients hub

func (*Hub) Deregister

func (h *Hub) Deregister(c *Client)

func (*Hub) Iter

func (h *Hub) Iter(f func(*Client))

func (*Hub) Register

func (h *Hub) Register(c *Client)

func (*Hub) Start

func (h *Hub) Start()

func (*Hub) Stop

func (h *Hub) Stop()

type Item

type Item struct {
	ItemID    int64  `db:"itemId"      json:"itemId"`
	ListID    string `db:"listId"      json:"listId"`
	Text      string `db:"contentText" json:"text"`
	IsChecked bool   `db:"isChecked"   json:"isChecked"`
}

Item is a stored list item

type Message

type Message struct {
	Item
	Method string `json:"method"`
}

Message holds any communication message.

type Server

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

Server holds the server implementation.

func NewServer

func NewServer(store *Store, homeTempl *template.Template) *Server

NewServer returns a new server.

func (*Server) Listen

func (s *Server) Listen(addr *string) error

Listen on given address

type SqliteStore

type SqliteStore struct {
	DB *sql.DB
}

SqliteStore is the SQLite storge implementaion

func (*SqliteStore) AllLists

func (store *SqliteStore) AllLists() []*Item

func (*SqliteStore) Bootstrap

func (store *SqliteStore) Bootstrap()

Bootstrap the store, to create the necessary tables.

func (*SqliteStore) Create

func (store *SqliteStore) Create(item *Item) *Item

Create insert (or update) the given item.

func (*SqliteStore) Delete

func (store *SqliteStore) Delete(listID string, itemID int64) error

Delete the given item

func (*SqliteStore) Find

func (store *SqliteStore) Find(listID string, itemID int64) *Item

Find returns the item matching the given ID

func (*SqliteStore) FindAll

func (store *SqliteStore) FindAll(listID string) []*Item

FindAll returns all items matching the given list ID

type Store

type Store interface {
	Bootstrap()
	Find(listID string, itemID int64) *Item
	FindAll(listID string) []*Item
	Create(item *Item) *Item

	Delete(listID string, itemID int64) error
	AllLists() []*Item
	// contains filtered or unexported methods
}

Store is the storage backend

func NewStore

func NewStore(db *sql.DB) Store

NewStore return a new store. call .Bootstrap() to create the necessary tables.

Jump to

Keyboard shortcuts

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