server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2014 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port      int    `json:"port"`
	Templates string `json:"templates"`
	Static    string `json:"static"`
}

func Parse

func Parse() Config

Read command line variables and generate a config file

type Memory

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

func NewMemoryStore

func NewMemoryStore(n int) *Memory

func (*Memory) Create

func (m *Memory) Create(thing *Thing) (*Thing, error)

func (*Memory) Delete

func (m *Memory) Delete(thing *Thing) (*Thing, error)

func (*Memory) List

func (m *Memory) List() []*Thing

func (*Memory) Update

func (m *Memory) Update(thing *Thing) (*Thing, error)

type Message

type Message struct {
	Id      int64       `json:"id"`
	Body    string      `json:"body"`
	Content interface{} `json:"content"`
}

Messages that will be sent by the server and users

type Resource

type Resource interface{}

type ResourceMessage

type ResourceMessage struct {
	Method  string   `json:"method"`
	Content Resource `json:"content"`
}

Event messages for create-update-delete events on resources

type Server

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

Wrap HTTP methods

func New

func New(config Config, store Storage) (*Server, error)

func (*Server) AddUser

func (s *Server) AddUser(user *User)

User Events -----------

func (*Server) BroadcastMessage

func (s *Server) BroadcastMessage(msg *Message)

Broadcast method for users

func (*Server) DeleteUser

func (s *Server) DeleteUser(user *User)

func (*Server) EventsHandler

func (s *Server) EventsHandler(ws *websocket.Conn)

Main websocket handler for users Receives new events

func (*Server) HandleMessage

func (s *Server) HandleMessage(msg *ThingMessage)

Message handler

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) RootHandler

func (s *Server) RootHandler(w http.ResponseWriter, r *http.Request)

Serve the list template

type Storage

type Storage interface {
	List() []*Thing
	Create(*Thing) (*Thing, error)
	Delete(*Thing) (*Thing, error)
	Update(*Thing) (*Thing, error)
}

type Thing

type Thing struct {
	Id        int64     `json:"id"`
	Name      string    `json:"name"`
	Timestamp time.Time `json:"timestamp"`
}

A basic resource

func (*Thing) String

func (t *Thing) String() string

type ThingMessage

type ThingMessage struct {
	Method string `json:"method"`
	Item   *Thing `json:"content"`
}

Event messages for create-update-delete events specific to Thing

func (ThingMessage) String

func (t ThingMessage) String() string

type User

type User struct {
	Id   int64  `json:"id"`
	Name string `json:"name"`
	// contains filtered or unexported fields
}

func (*User) String

func (u *User) String() string

Jump to

Keyboard shortcuts

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