models

package
v0.0.0-...-72a5972 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	ServerMessageID int
	// contains filtered or unexported fields
}

Document represents the structure, operations, and server state for a file.

func NewDocument

func NewDocument() *Document

NewDocument creates a new empty document.

func (*Document) Apply

func (d *Document) Apply(op operations.Operation) error

Apply updates the document based on an operation and records that operation in its history.

func (*Document) String

func (d *Document) String() string

String returns the contents of the document as a string.

type Message

type Message struct {
	Operation       operations.Operation `json:"operation"`
	ClientMessageID int                  `json:"client_message_id"`
	ServerMessageID int                  `json:"server_message_id"`
}

Message is the structure of communication between a client and the server. It describes both the operation that occurred, as well as the indexes for both the client and server, which is necessary to understand if and how the operation should be transformed.

type Model

type Model interface {
	ID() int
	Create(utils.DB) error
	Update(utils.DB) error
	Delete(utils.DB) error
}

Model is an interface that provides the basic structure for interacting with database tables. One can safely assume that a struct conforming to this interface has a corresponding database table.

type Session

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

Session represents a connection between a server and client.

func NewSession

func NewSession(doc *Document) (*Session, error)

NewSession initializes a new Session for an existing document.

func (*Session) Receive

func (s *Session) Receive(msg *Message) error

Receive handles a new message from the client and updates the document.

type User

type User struct {
	Email     string
	FirstName string
	LastName  string
	CreatedAt time.Time
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

User represents an entity in the system that can interact with files, either by modifying or reading.

func (*User) Create

func (u *User) Create(db utils.DB) error

Create inserts the user into the database.

func (*User) Delete

func (u *User) Delete(db utils.DB) error

func (*User) ID

func (u *User) ID() int

ID is the primary key of the model.

func (*User) Update

func (u *User) Update(db utils.DB) error

func (*User) Validate

func (u *User) Validate() error

Validate ensures that the model can be created or updated.

Jump to

Keyboard shortcuts

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