core

package
v0.0.0-...-379397d Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 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 Arg

type Arg struct {
	Name  []byte
	Value []byte
}

type Channel

type Channel struct {
	ID string
	// display name
	Name string
	// contains filtered or unexported fields
}

func (*Channel) Join

func (channel *Channel) Join(user *Conn)

func (*Channel) Leave

func (channel *Channel) Leave(user *Conn)

func (*Channel) Send

func (channel *Channel) Send(data []byte)

type CompactTweetParser

type CompactTweetParser struct {
}

CompactTweetParser parses tweets encoded using compact tweet format a compact tweet format is [code;arg1=arg1v,arg2=arg2v,argN=argNv;content] arguments and content are optional code, args, content must end with ;

func (*CompactTweetParser) Compile

func (parser *CompactTweetParser) Compile(code, arguments string, content []byte) []byte

Compile creates a raw tweet out of twwet parts example: char *args[]{tweet.code, tweet.argument, tweet.content}

func (*CompactTweetParser) Parse

func (parser *CompactTweetParser) Parse(message []byte) *Tweet

Parse parses a tweet text and returns a Tweet type

func (*CompactTweetParser) Serialize

func (parser *CompactTweetParser) Serialize(tweet *Tweet) []byte

Serialize serializes a tweet into a string different than raw, as the tweet may have been changed so, this function re-constructs the tweet's string

type Conn

type Conn struct {
	evio.Conn
	// contains filtered or unexported fields
}

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) Ping

func (c *Conn) Ping()

func (*Conn) Write

func (c *Conn) Write(message []byte)

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(message []byte)

type Flock

type Flock struct {
	OnConnectionMiddlewares    []OnConnectionHandler
	OnDisconnectionMiddlewares []OnDisconnectionHandler
	// contains filtered or unexported fields
}

func NewFlock

func NewFlock() Flock

func (*Flock) Add

func (flock *Flock) Add(twitter TweetHandler, options TwitterOptions)

tiwtter callbacks. These are the actual callbacks that will process tweets they're not middlewares

func (*Flock) AddMany

func (flock *Flock) AddMany(twitters []TweetHandler, options TwitterOptions)

func (*Flock) AddMiddleware

func (flock *Flock) AddMiddleware(twitter TweetHandler, options MiddlewareOptions)

middlewares

func (*Flock) AddOnConnection

func (flock *Flock) AddOnConnection(middleware OnConnectionHandler)

install a single middleware to be run when a new ws is connected

func (*Flock) AddOnDisconnection

func (flock *Flock) AddOnDisconnection(middleware OnDisconnectionHandler)

install a single middleware to be run when a ws is disconnected

func (*Flock) GePosttMiddlewares

func (flock *Flock) GePosttMiddlewares(scope Scope) []TweetHandler

middlewares with Scope.Any should be returned here, even if scope was diffferent

func (*Flock) Get

func (flock *Flock) Get(code string, scope Scope) (TweetHandler, bool)

retrieve a twitter

func (*Flock) GetMiddlewares

func (flock *Flock) GetMiddlewares(scope Scope) []TweetHandler

middlewares with Scope.Any should be returned here, even if scope was diffferent

type Middleware

type Middleware interface {
	// register middleware
	Congregate(flock *Flock, options MiddlewareOptions)
}

Middleware sparrow middlewares should implement this interface

type MiddlewareOptions

type MiddlewareOptions struct {
	Scope Scope
	Post  bool
	Async bool
}

MiddlewareOptions can be used to change a middleware's scope or run it before/after twitter

type NanoWebsocket

type NanoWebsocket struct {
	OnOpen    func(c *Conn, handshake *ws.Handshake)
	OnClose   func(c *Conn, err error) (action evio.Action)
	OnMessage func(c *Conn, mesaage wsutil.Message) (out []byte, action evio.Action)
	OnPing    func(c *Conn)
	OnPong    func(c *Conn)
}

func (*NanoWebsocket) Serve

func (nano *NanoWebsocket) Serve(addr ...string) error

type OnConnectionHandler

type OnConnectionHandler func(*Conn, *ws.Handshake)

type OnDisconnectionHandler

type OnDisconnectionHandler func(*Conn, User)

type ReadWriteBuffer

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

func (ReadWriteBuffer) Read

func (rw ReadWriteBuffer) Read(p []byte) (n int, err error)

func (ReadWriteBuffer) Write

func (rw ReadWriteBuffer) Write(p []byte) (n int, err error)

type Scope

type Scope int32
const (
	NONE  Scope = 0 // before loging in
	ANY   Scope = 1 // all scopes
	USER  Scope = 2 // a user
	ADMIN Scope = 3 // an admin
)

type Sparrow

type Sparrow struct {
	// contains twitters, followers, leaders, middlewares, and postwares
	Flock       Flock
	TweetParser TweetParser
	Users       *trie.PathTrie
	Channels    *trie.PathTrie
}

Sparrow server

func NewSparrow

func NewSparrow() *Sparrow

New creates a new Sparrow instance

func (*Sparrow) Install

func (sparrow *Sparrow) Install(twitter Twitter)

func (*Sparrow) InstallMiddleware

func (sparrow *Sparrow) InstallMiddleware(middleware Middleware, options MiddlewareOptions)

middleware run order: 1- middlewares 2- twitter-specific middlewares 3- twitter 4- post middlewares 5- twitter-specific post middlewares

func (*Sparrow) LogUserIn

func (sparrow *Sparrow) LogUserIn(id []byte, scope Scope, ws *Conn) bool

func (*Sparrow) LogUserOut

func (sparrow *Sparrow) LogUserOut(id []byte, ws Conn) bool

func (*Sparrow) OnConnection

func (sparrow *Sparrow) OnConnection(middleware OnConnectionHandler)

install a single middleware to be run when a new ws is connected

func (*Sparrow) OnDisconnection

func (sparrow *Sparrow) OnDisconnection(middleware OnDisconnectionHandler)

install a single middleware to be run when a ws is disconnected

func (*Sparrow) Run

func (sparrow *Sparrow) Run()

Run starts listening for incoming messages

func (*Sparrow) Use

func (sparrow *Sparrow) Use(twitter TweetHandler, options TwitterOptions)

func (*Sparrow) UseMiddleware

func (sparrow *Sparrow) UseMiddleware(middleware TweetHandler, options MiddlewareOptions)

callback middlewares (lambda instead of classes)

type Tweet

type Tweet struct {
	Code    string            //target twitter callback
	Args    map[string]string // key-value pairs argments
	Content []byte            // tweet's content
	Raw     []byte            // message as received by ws
}

func (Tweet) Valid

func (tweet Tweet) Valid() bool

type TweetHandler

type TweetHandler func(*Conn, User, *Tweet) bool

Conn, user, tweet, twitter, success: the result of the ran twitter, for post middlewares

type TweetParser

type TweetParser interface {
	Parse(message []byte) *Tweet
}

TweetParser an interface for twwet parsers

type Twitter

type Twitter interface {
	// this twitter's name
	Name() string
	// a function to register the twitter's handler functions
	Congregate(flock *Flock)
}

type TwitterOptions

type TwitterOptions struct {
	Code  string
	Scope Scope
	Post  bool
	Async bool
}

type User

type User interface {
	ID() string
	Scope() Scope
}

Jump to

Keyboard shortcuts

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