lrs

package module
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: BSD-3-Clause Imports: 14 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

LiveRecord Server

Go Report Card License Build Status Github All Releases

This is socket server for LiveRecord communication platform.

Configure

Add to .env

MYSQL_DSN=root:123@tcp(127.0.0.1:3306)/liveRecord?charset=utf8&parseTime=True
DOCUMENT_ROOT=/Users/zoonman/Projects/www/liverecord/client/dist
LISTEN_ADDR=:8000
DEBUG=true

Assemble and run

Install make and execute:

make it work

Running inside Docker container




Documentation

Index

Constants

View Source
const (
	PingFrame           = "Ping"
	AuthFrame           = "Auth"
	AuthErrorFrame      = "AuthError"
	JWTFrame            = "JWT"
	UserListFrame       = "UserList"
	UserInfoFrame       = "UserInfo"
	UserUpdateFrame     = "UserUpdate"
	UserDeleteFrame     = "UserDelete"
	CategoryFrame       = "Category"
	CategoryListFrame   = "CategoryList"
	CategorySaveFrame   = "CategorySave"
	CategoryUpdateFrame = "CategoryUpdate"
	CategoryDeleteFrame = "CategoryDelete"
	CategoryErrorFrame  = "CategoryError"
	TopicFrame          = "Topic"
	TopicSaveFrame      = "TopicSave"
	TopicListFrame      = "TopicList"
	CommentFrame        = "Comment"
	CommentListFrame    = "CommentList"
	CommentSaveFrame    = "CommentSave"
	UserFrame           = "User"
	ResetPasswordFrame  = "ResetPassword"
	FileUploadFrame     = "Upload"
	CancelUploadFrame   = "CancelUpload"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Model
	Type        string `json:"type"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Link        string `json:"link"`
	Thumbnail   string `json:"thumbnail"`
	HTML        string `json:"html"`
}

Attachment for comment

type Category

type Category struct {
	Model
	Name        string `json:"name"`
	Slug        string `sql:"index" json:"slug"`
	Description string `json:"description" sql:"type:text"`
	Order       int    `json:"order"`
	Active      bool   `json:"active"`
	Updates     int    `json:"updates"`
}

Category of topics

type Comment

type Comment struct {
	Model
	TopicID     uint         `json:"topicId" sql:"index"`
	Topic       Topic        `json:"topic,omitempty" gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID      uint         `json:"userId" sql:"index"`
	User        User         `json:"user" gorm:"association_autoupdate:false;association_autocreate:false"`
	Body        string       `json:"body" sql:"type:text"`
	Attachments []Attachment `json:"attachments,omitempty" gorm:"association_autoupdate:false;association_autocreate:false"`
	Rank        uint         `json:"rank"`
	Solution    bool         `json:"solution"`
	Spam        bool         `json:"spam"`
	Moderated   bool         `json:"moderated"`
}

Comment on the topic

type CommentStatus

type CommentStatus struct {
	Model
	CommentID  uint       `json:"commentId"`
	Comment    Topic      `json:"comment" gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID     uint       `json:"userId" sql:"index"`
	User       User       `json:"user" gorm:"association_autoupdate:false;association_autocreate:false"`
	ReadAt     *time.Time `json:"readAt"`
	NotifiedAt *time.Time `json:"notifiedAt"`
	Vote       int        `json:"vote"`
}

CommentStatus used to track read statuses of comments

type Config

type Config struct {
	ID           uint   `gorm:"primary_key" json:"id"`
	JwtSignature []byte `gorm:"type:varbinary(256)"`
	Protocol     string
	Port         uint
	Name         string
	Domain       string
	LogoPath     string
	UploadDir    string
	DocumentRoot string
	SMTP         SMTP `gorm:"embedded;embedded_prefix:smtp_"`
	Debug        bool
}

Config defines app configuration

func (*Config) LogoURL

func (cfg *Config) LogoURL() string

LogoURL returns link to the logo

func (*Config) SiteURL

func (cfg *Config) SiteURL() string

SiteURL Returns site URL

type ConnectionPool

type ConnectionPool struct {
	Sockets SocketConnectionsMap
	Users   UserConnectionsMap
	// contains filtered or unexported fields
}

ConnectionPool is intended to keep track of all connections

func NewConnectionPool

func NewConnectionPool() *ConnectionPool

NewConnectionPool is factory to create new pool of connections

func (*ConnectionPool) AddConnection

func (pool *ConnectionPool) AddConnection(conn *websocket.Conn)

AddConnection adds connection to the pool

func (*ConnectionPool) Authenticate

func (pool *ConnectionPool) Authenticate(conn *websocket.Conn, user *User)

Authenticate binds user identifier to a connection

func (*ConnectionPool) Broadcast

func (pool *ConnectionPool) Broadcast(frame Frame)

Broadcast sends a frame to all connections

func (*ConnectionPool) DropConnection

func (pool *ConnectionPool) DropConnection(conn *websocket.Conn)

DropConnection closes connection

func (*ConnectionPool) Logout

func (pool *ConnectionPool) Logout(user *User)

Logout disaccosiates users and connections

func (*ConnectionPool) Send

func (pool *ConnectionPool) Send(to *User, frame Frame)

Send delivers a frame to all user's connections

func (*ConnectionPool) Write

func (pool *ConnectionPool) Write(conn *websocket.Conn, frame Frame)

Write sends a frame to a specific connection

type Device

type Device struct {
	UserID       uint
	DeviceID     string
	Type         string // browser, phone
	UserAgent    string
	LastIP       net.Addr
	AccessAt     time.Time
	Subscribed   bool
	PushEndpoint string
	PushKeyP256  string
	PushAuth     string
}

Device describes the device used by the user

type Frame

type Frame struct {
	Type      string `json:"type"`
	Data      string `json:"data"`
	RequestID string `json:"requestId"`
}

func NewFrame

func NewFrame(t string, obj interface{}, requestId string) Frame

func (Frame) BindJSON

func (frame Frame) BindJSON(obj interface{}) error

type Model

type Model struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"createdAt,omitempty"`
	UpdatedAt time.Time  `json:"updatedAt,omitempty"`
	DeletedAt *time.Time `sql:"index" json:"deletedAt,omitempty"`
}

func (*Model) ToJSON

func (m *Model) ToJSON() string

type Role

type Role struct {
	Role string `json:"role"`
}

Role of the user

type SMTP

type SMTP struct {
	From        string
	Host        string
	Port        int
	Username    string
	Password    string
	InsecureTLS bool
	SSL         bool
}

SMTP used to define SMTP configuration

type Settings

type Settings struct {
	// Offline Notifications:
	// 0. No
	// 1. Push only
	// 2. Immediate to email
	// 3. Daily email digests
	// 4. Weekly email digests
	UserID        uint
	Notifications uint
	Timezone      time.Location
}

Settings keep user settings under control

type Slugged

type Slugged struct {
	Slug string `sql:"index" json:"slug"`
}

type SocialProfile

type SocialProfile struct {
	Model
	NetworkID string    `json:"networkId"`
	Network   string    `json:"name"`
	Token     string    `json:"-"`
	ExpiresAt time.Time `json:"-"`
	UserID    uint
}

SocialProfile represents user profile in social networks

type SocketConnectionsMap

type SocketConnectionsMap map[*websocket.Conn]*User

SocketConnectionsMap type

type SocketStateMap

type SocketStateMap map[*websocket.Conn]bool

SocketStateMap type

type Topic

type Topic struct {
	Model
	Slugged
	CategoryID    uint     `json:"categoryId"`
	Category      Category `json:"category,omitempty" gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID        uint     `json:"userId"`
	User          User     `json:"user,omitempty" gorm:"association_autoupdate:false;association_autocreate:false"`
	Title         string   `json:"title"`
	Body          string   `json:"body,omitempty" sql:"type:longtext"`
	Order         int      `json:"order"`
	ACL           []User   `json:"acl" gorm:"many2many:topic_acl;association_autoupdate:false;association_autocreate:false"`
	TotalViews    uint32   `json:"total_views,omitempty"`
	TotalComments uint32   `json:"total_comments,omitempty"`
	Rank          uint32   `json:"rank,omitempty"`
	Private       bool     `json:"private"`
	Pinned        bool     `json:"pinned"`
}

Topic defines the main forum topic structure

func (*Topic) BeforeCreate

func (t *Topic) BeforeCreate(scope *gorm.Scope) (err error)

BeforeCreate hook

func (*Topic) BeforeSave

func (t *Topic) BeforeSave() (err error)

BeforeSave hook

func (*Topic) SafeTopic

func (t *Topic) SafeTopic() *Topic

SafeTopic returns sanitized version of the topic

type User

type User struct {
	Model
	Email         string          `validator:"email" gorm:"unique_index" json:"email,omitempty"`
	EmailVerified bool            `gorm:"default:false" json:"email_verified,omitempty"`
	Password      string          `json:"-"`
	Hash          string          `json:"-"`
	Name          string          `json:"name"`
	Slug          string          `json:"slug" gorm:"unique_index"`
	Picture       string          `json:"picture"`
	About         string          `json:"about,omitempty"`
	Gender        string          `json:"gender,omitempty"`
	Rank          float32         `json:"rank"`
	Online        bool            `json:"online"`
	Roles         []Role          `json:"roles,omitempty"`
	Profiles      []SocialProfile `json:"profiles,omitempty" gorm:"[]"`
	Devices       []Device        `json:"devices,omitempty"`
	Settings      *Settings       `json:"settings,omitempty"`
}

User represents user entity

func (*User) MakeGravatarPicture

func (u *User) MakeGravatarPicture() string

MakeGravatarPicture method

func (*User) MakeNameFromEmail

func (u *User) MakeNameFromEmail() string

MakeNameFromEmail method

func (*User) MakeSlug

func (u *User) MakeSlug()

MakeSlug method

func (*User) SafePluck

func (u *User) SafePluck() User

SafePluck returns sanitized version of User object

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword for the User

type UserAuthData

type UserAuthData struct {
	Email      string `json:"email"`
	Password   string `json:"password"`
	RememberMe bool   `json:"rememberMe"`
}

UserAuthData packet

type UserConnectionsMap

type UserConnectionsMap map[uint]SocketStateMap

UserConnectionsMap type

type UserList

type UserList []User

UserList for list of the users

func (UserList) Map

func (ul UserList) Map(f func(User) User) UserList

Directories

Path Synopsis
cmd
lrs command

Jump to

Keyboard shortcuts

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