teousers

package
v0.0.0-...-2e4d9bc Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package teousers (teo-users) is the Teonet users service package.

Install this go package:

go get github.com/kirill-scherba/teonet-go/services/teocdb

Data base organisation

This service uses ScyllaDB. If you install this service manually you need install ScyllaDB. Run Scylla in Docker:

https://www.scylladb.com/download/open-source/#docker

You may check version of your existing running scylla docker container with command:

docker exec -it scylla scylla --version

Before you execute application which used this package you need install database schemas. Launch `cqlsh`:

docker exec -it scylla cqlsh

and execute next commands:

CREATE KEYSPACE IF NOT EXISTS teousers with replication = { 'class' : 'SimpleStrategy',
'replication_factor' : 3 };
USE teousers;
CREATE TABLE IF NOT EXISTS  users (
  id uuid,
  access_token uuid,
  prefix text,
  name text,
  avatar_id uuid,
  gravatar_id text,
  online boolean,
  last_online timestamp,
  state int,
  PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS ON users (prefix);
CREATE INDEX IF NOT EXISTS ON users (name);
CREATE INDEX IF NOT EXISTS ON users (online);

To run db tests repeat the same with teousers_test in first string:

CREATE KEYSPACE IF NOT EXISTS teousers_test with replication = { 'class' : 'SimpleStrategy',  'replication_factor' : 3 };
USE teousers;

and execute abowe code, from the CREATE TABLE ...

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserAlreadyExists happends if user already exist during creating
	ErrUserAlreadyExists = errors.New("user with selected id already exists")
)
View Source
var MODULE = teokeys.Color(teokeys.ANSIBrown, "(teousers)")

MODULE is this package module name

Functions

This section is empty.

Types

type Process

type Process struct{ *Users }

Process receiver to process teousers commands

func (*Process) ComCheckAccess

func (p *Process) ComCheckAccess(pac TeoPacket) (res *cli.UserResponce, err error)

ComCheckAccess process check users access token request, return user_id and access_tocken (the same as create user return)

Input data: {req_id uint32, prefix_with_or_without_id string}

Output data: UserNew{user_id gocql.UUID,access_tocken gocql.UUID,prefix string}

Use UserNew.UnmarshalBinary to decode binary buffer into UserNew

func (*Process) ComCheckUser

func (p *Process) ComCheckUser(pac TeoPacket) (exists bool, err error)

ComCheckUser process check user request, return true if user valid.

Input data (binary): user_id []byte[16] or user_prefix + user_id string.

Output data (byte): user_exists []byte[1]; 0 - not exists, 1 - exists.

func (*Process) ComCreateUser

func (p *Process) ComCreateUser(pac TeoPacket) (res *cli.UserResponce, err error)

ComCreateUser process create new user request, return new user_id and access_tocken.

Input data: {req_id uint32, prefix_with_or_without_id string}

Output data: UserNew{user_id gocql.UUID,access_tocken gocql.UUID,prefix string}

Use UserNew.UnmarshalBinary to decode binary buffer into UserNew.

type TeoConnector

type TeoConnector interface {
	SendTo(peer string, cmd byte, data []byte) (int, error)
	//SendAnswer(pac *teonet.Packet, cmd byte, data []byte) (int, error)
	SendAnswer(pac interface{}, cmd byte, data []byte) (int, error)
}

TeoConnector is teonet connector interface. It may be servers (*Teonet) or clients (*TeoLNull) connector and must conain SendTo method.

type TeoPacket

type TeoPacket interface {
	Cmd() byte
	Data() []byte
}

TeoPacket is teonet packet interface

type User

type User struct {
	ID          gocql.UUID // User ID
	AccessToken gocql.UUID // Access tocken is tocken to use when login
	Prefix      string     // Application(game) prefix (name or code)
	Name        string     // User name
	AvatarID    gocql.UUID // Avatar ID
	GravatarID  string     // Gravatar ID
	Online      bool       // Online or offline
	LastOnline  time.Time  // Last time was online
	State       int        // Current state
}

User data structure

type Users

type Users struct {
	*Process
	TeoConnector
	// contains filtered or unexported fields
}

Users is the teousers data structure and methods receiver

func Connect

func Connect(con TeoConnector, hosts ...string) (u *Users, err error)

Connect to the cql cluster and create teousers receiver. First parameter is keyspace, next parameters is hosts name (usualy it should be 3 hosts - 3 ScyllaDB nodes)

func (*Users) Close

func (u *Users) Close()

Close closes cql connection and destroy teoregistry receiver

Jump to

Keyboard shortcuts

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