core

package
v0.0.0-...-b68b127 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2020 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BtsEqualFold

func BtsEqualFold(s, p []byte) bool

btsEqualFold checks s to be case insensitive equal to p. Note that p must be only ascii letters. That is, every byte in p belongs to range ['a','z'] or ['A','Z'].

func BtsHasToken

func BtsHasToken(header, token []byte) (has bool)

func GetObjectTypeName

func GetObjectTypeName(obj interface{}) string

func GetPk

func GetPk(obj interface{}) string

func GraphQLSmartErrorMessageBytes

func GraphQLSmartErrorMessageBytes(msg interface{}) []byte

func IsHMACAlg

func IsHMACAlg(token []byte) bool

func IsObjectStructType

func IsObjectStructType(obj interface{}) bool

func Iterator

func Iterator(o *OMap) *iterator

func JWTTokenAuth

func JWTTokenAuth(ctx *HContext) *graphql.Field

func JWTTokenVerify

func JWTTokenVerify(ctx *HContext) *graphql.Field

func LoadPrivateKey

func LoadPrivateKey(data []byte) (interface{}, error)

func ParseGraphQLData

func ParseGraphQLData(gqlData []byte) (string, map[string]interface{}, error)

func StrEqualFold

func StrEqualFold(s, p string) bool

StrEqualFold checks s to be case insensitive equal to p. Note that p must be only ascii letters. That is, every byte in p belongs to range ['a','z'] or ['A','Z'].

func StrHasToken

func StrHasToken(header, token string) (has bool)

func StrToBytes

func StrToBytes(str string) (bts []byte)

func VerifyJWT

func VerifyJWT(token []byte,
	authPublicKey []byte,
	authSecretKey []byte,
	authBearer string,
	plainToken bool,
	logToGlog bool) (map[string]interface{}, bool)

func WebsocketFileDescriptor

func WebsocketFileDescriptor(conn net.Conn) int

Types

type AuthVerify

type AuthVerify struct {
}

func (*AuthVerify) Verify

func (av *AuthVerify) Verify(token []byte, authPublicKey []byte, authSecretKey []byte, authBearer string) (map[string]interface{}, bool)

type AuthVerifyInterface

type AuthVerifyInterface interface {
	// Get Unique ID from authorization data and also validity of auth data
	Verify(token []byte, authPublicKey []byte, authSecretKey []byte, authBearer string) (map[string]interface{}, bool)
}

type EventPool

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

func MakeCustomEventPool

func MakeCustomEventPool(epollEventQueueSize int, epollWaitingTime int) (*EventPool, error)

func MakeEventPool

func MakeEventPool() (*EventPool, error)

func (*EventPool) AddConnection

func (e *EventPool) AddConnection(conn net.Conn) error

func (*EventPool) GetConnection

func (e *EventPool) GetConnection(cid int) (net.Conn, bool)

func (*EventPool) GetWebSocketConnectionIdSlice

func (e *EventPool) GetWebSocketConnectionIdSlice() []int

func (*EventPool) GetWebSocketConnectionMap

func (e *EventPool) GetWebSocketConnectionMap() map[int]net.Conn

func (*EventPool) GetWebSocketConnectionSlice

func (e *EventPool) GetWebSocketConnectionSlice() []net.Conn

func (*EventPool) RemoveConnection

func (e *EventPool) RemoveConnection(conn net.Conn) error

func (*EventPool) TotalActiveWebSocketConnections

func (e *EventPool) TotalActiveWebSocketConnections() int

func (*EventPool) Wait

func (e *EventPool) Wait() ([]net.Conn, error)

type HContext

type HContext struct {
	Host string // read only
	Port string // read only

	EPollEventQueueSize int //read only
	EPollWaitingTime    int //read only

	EnableTLS bool   //read only
	CertFile  string //read only
	KeyFile   string //read only

	ServerMux *http.ServeMux

	ConnectionEventPool *EventPool

	IsLive bool          // read write
	Lock   *sync.RWMutex // mutex for modifiable params

	AuthVerify AuthVerifyInterface // read only
	ServeWS    ServeWSInterface    // read only

	AuthBearer     string   // read only
	AuthPublicKey  string   // read only
	AuthPrivateKey string   // read only
	AuthSecretKey  string   // read only
	AuthAlgorithm  string   // read only
	AuthIssuer     string   // read only
	AuthAudiences  []string // read only

	AuthTokenDefaultTimeout      int64 // seconds
	AuthTokenSuperGroupTimeout   int64 // seconds
	AuthTokenServiceGroupTimeout int64 // seconds
	AuthTokenNormalGroupTimeout  int64 // seconds

	OnlineUserDataStore OnlineUserDataStoreInterface // read only

	LivePath             []byte // read only
	AuthPath             []byte // read only
	GraphQLPath          []byte // read only
	WebSocketUpgradePath []byte // read only

	MiddlewareList []MiddlewareInterface // read only while running the server
	RouteList      []*Route              // read only while running the server

	KeyValueStore map[string]string
	StorageEngine StorageInterface
	DbPath        string

	//GraphQL related Objects
	//GraphQLQuery *graphql.Object
	//GraphQLMutation *graphql.Object
	GraphQLQueryFields    graphql.Fields
	GraphQLMutationFields graphql.Fields
	GraphQLSchema         *graphql.Schema

	AuthQueryFields    graphql.Fields
	AuthMutationFields graphql.Fields
	AuthSchema         *graphql.Schema

	EnableLivePath      bool
	EnableAuthPath      bool
	EnableGraphQLPath   bool
	EnableWebSocketPath bool

	CORSOptions *cors.Options
}

func (*HContext) AddAuthMutationField

func (c *HContext) AddAuthMutationField(name string, field *graphql.Field)

func (*HContext) AddAuthQueryField

func (c *HContext) AddAuthQueryField(name string, field *graphql.Field)

func (*HContext) AddConnection

func (c *HContext) AddConnection(conn net.Conn) error

func (*HContext) AddGraphQLMutationField

func (c *HContext) AddGraphQLMutationField(name string, field *graphql.Field)

func (*HContext) AddGraphQLQueryField

func (c *HContext) AddGraphQLQueryField(name string, field *graphql.Field)

func (*HContext) AddMiddleware

func (c *HContext) AddMiddleware(mi MiddlewareInterface)

func (*HContext) AddObject

func (c *HContext) AddObject(obj interface{}) bool

func (*HContext) AddRoute

func (c *HContext) AddRoute(pattern string, httpHandlerObject ServeHTTPInterface)

func (*HContext) AddUser

func (c *HContext) AddUser(uid string, group string, sid int)

func (*HContext) ClearKeyValueStore

func (c *HContext) ClearKeyValueStore()

func (*HContext) DeleteFromStorage

func (c *HContext) DeleteFromStorage(key []byte) bool

func (*HContext) DeleteObject

func (c *HContext) DeleteObject(obj interface{}) bool

func (*HContext) GetConnection

func (c *HContext) GetConnection(cid int) (net.Conn, bool)

func (*HContext) GetFromStorage

func (c *HContext) GetFromStorage(key []byte) ([]byte, bool)

func (*HContext) GetGroupFromSID

func (c *HContext) GetGroupFromSID(sid int) string

func (*HContext) GetIdList

func (c *HContext) GetIdList(uid string) []int

func (*HContext) GetIsLive

func (c *HContext) GetIsLive() bool

func (*HContext) GetObject

func (c *HContext) GetObject(obj interface{}) bool

func (*HContext) GetTotalUID

func (c *HContext) GetTotalUID() int

func (*HContext) GetUIDFromSID

func (c *HContext) GetUIDFromSID(sid int) string

func (*HContext) GetUIDList

func (c *HContext) GetUIDList() []string

func (*HContext) GetValue

func (c *HContext) GetValue(key string) string

func (*HContext) GetWebSocketConnectionIdSlice

func (c *HContext) GetWebSocketConnectionIdSlice() []int

func (*HContext) GetWebSocketConnectionMap

func (c *HContext) GetWebSocketConnectionMap() map[int]net.Conn

func (*HContext) GetWebSocketConnectionSlice

func (c *HContext) GetWebSocketConnectionSlice() []net.Conn

func (*HContext) HasAuthVerify

func (c *HContext) HasAuthVerify() bool

func (*HContext) HasWSServer

func (c *HContext) HasWSServer() bool

func (*HContext) IsExistsInStorage

func (c *HContext) IsExistsInStorage(key []byte) bool

func (*HContext) IsObjectExists

func (c *HContext) IsObjectExists(obj interface{}) bool

func (*HContext) IsStorageEngineReady

func (c *HContext) IsStorageEngineReady() bool

func (*HContext) RemoveConnection

func (c *HContext) RemoveConnection(conn net.Conn) error

func (*HContext) RemoveUser

func (c *HContext) RemoveUser(sid int)

func (*HContext) RemoveValue

func (c *HContext) RemoveValue(key string)

func (*HContext) SaveToStorage

func (c *HContext) SaveToStorage(key []byte, value []byte) bool

func (*HContext) SetIsLive

func (c *HContext) SetIsLive(live bool)

func (*HContext) SetKeyValueStore

func (c *HContext) SetKeyValueStore(dataMap map[string]string)

func (*HContext) SetValue

func (c *HContext) SetValue(key string, value string)

func (*HContext) TotalActiveWebSocketConnections

func (c *HContext) TotalActiveWebSocketConnections() int

func (*HContext) WriteLowLevelMessage

func (c *HContext) WriteLowLevelMessage(connectionId int, opCode ws.OpCode, message []byte)

func (*HContext) WriteMessage

func (c *HContext) WriteMessage(connectionId int, message []byte)

type MiddlewareInterface

type MiddlewareInterface interface {
	// ServeHTTP and instruct to proceed next or not
	ServeHTTP(context *HContext, request *http.Request, response http.ResponseWriter) bool
}

type OMap

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

Thread safe One One Map

func (*OMap) Append

func (o *OMap) Append(key, value interface{})

func (*OMap) DeleteByFirst

func (o *OMap) DeleteByFirst(value interface{}) bool

func (*OMap) DeleteByIndex

func (o *OMap) DeleteByIndex(index int) bool

func (*OMap) DeleteBySecond

func (o *OMap) DeleteBySecond(value interface{}) bool

func (*OMap) Get

func (o *OMap) Get(index int) (interface{}, interface{})

func (*OMap) GetByFirst

func (o *OMap) GetByFirst(value interface{}) interface{}

func (*OMap) GetBySecond

func (o *OMap) GetBySecond(value interface{}) interface{}

func (*OMap) GetFirstByIndex

func (o *OMap) GetFirstByIndex(index int) interface{}

func (*OMap) GetSecondByIndex

func (o *OMap) GetSecondByIndex(index int) interface{}

func (*OMap) IsCompatible

func (o *OMap) IsCompatible() bool

func (*OMap) Length

func (o *OMap) Length() int

func (*OMap) New

func (o *OMap) New(first []interface{}, second []interface{}) *OMap

type OnlineUserDataStoreInterface

type OnlineUserDataStoreInterface interface {
	AddUser(uid string, group string, sid int)
	RemoveUser(sid int)
	GetIdList(uid string) []int
	GetUIDFromSID(sid int) string
	GetGroupFromSID(sid int) string

	GetUIDList() []string
	GetTotalUID() int
}

type OnlineUserMemoryMap

type OnlineUserMemoryMap struct {
	UserMap                map[string][]int
	SocketIDToUserMap      map[int]string
	SocketIDToUserGroupMap map[int]string

	UserMapLock *sync.RWMutex
}

func NewOnlineUserMemoryMap

func NewOnlineUserMemoryMap() *OnlineUserMemoryMap

func (*OnlineUserMemoryMap) AddUser

func (o *OnlineUserMemoryMap) AddUser(uid string, group string, sid int)

func (*OnlineUserMemoryMap) GetGroupFromSID

func (o *OnlineUserMemoryMap) GetGroupFromSID(sid int) string

func (*OnlineUserMemoryMap) GetIdList

func (o *OnlineUserMemoryMap) GetIdList(uid string) []int

func (*OnlineUserMemoryMap) GetTotalUID

func (o *OnlineUserMemoryMap) GetTotalUID() int

func (*OnlineUserMemoryMap) GetUIDFromSID

func (o *OnlineUserMemoryMap) GetUIDFromSID(sid int) string

func (*OnlineUserMemoryMap) GetUIDList

func (o *OnlineUserMemoryMap) GetUIDList() []string

func (*OnlineUserMemoryMap) RemoveUser

func (o *OnlineUserMemoryMap) RemoveUser(sid int)

type Route

type Route struct {
	Pattern           string
	HttpHandlerObject ServeHTTPInterface
}

type ServeHTTPInterface

type ServeHTTPInterface interface {
	ServeHTTP(ctx *HContext, request *http.Request, response http.ResponseWriter)
}

type ServeWSGraphQL

type ServeWSGraphQL struct {
}

func (*ServeWSGraphQL) ServeWS

func (serveWSGraphQL *ServeWSGraphQL) ServeWS(ctx *HContext, connectionId int, message []byte, opCode byte)

type ServeWSInterface

type ServeWSInterface interface {
	ServeWS(ctx *HContext, connectionId int, message []byte, opCode byte)
}

type ServiceInterface

type ServiceInterface interface {
	ServiceName() string
	ServiceGroup() string

	//Set Service Settings
	SetServiceSettings(data []byte)

	// Serve based on data and return boolean flag with proper message
	Serve(data []byte) (bool, []byte)
}

type ServiceRegistry

type ServiceRegistry struct {
	ServiceMap map[string]ServiceInterface
}

func NewServiceRegistry

func NewServiceRegistry() *ServiceRegistry

func (*ServiceRegistry) Get

func (sr *ServiceRegistry) Get(name string) (ServiceInterface, bool)

func (*ServiceRegistry) RegisterService

func (sr *ServiceRegistry) RegisterService(si ServiceInterface)

func (*ServiceRegistry) SetServiceSettings

func (sr *ServiceRegistry) SetServiceSettings(name string, data []byte) bool

type SettingsInterface

type SettingsInterface interface {
	GetSettings(key string) []byte
	SetSettings(key string, value []byte) bool
}

type StorageInterface

type StorageInterface interface {
	Open(dbPath string) bool
	Close()

	Set(key []byte, value []byte) bool
	Get(key []byte) ([]byte, bool)
	Delete(key []byte) bool

	IsExists(key []byte) bool
}

Jump to

Keyboard shortcuts

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