package user

import "github.com/Diarkis/diarkis/user"

Index

Constants

const TCPClient = 1

TCPClient Client transport type used with userData.GetClientTransport()

const UDPClient = 2

UDPClient Client transport type used with userData.GetClientTransport()

const UnknownClient = 4

UnknownClient invalid network transport type that should never show up...

Functions

func CopyUser

func CopyUser(user *User) map[string]interface{}

CopyUser Copies a user struct for transferring user client data to another server.

Parameters

user - User to be copied as a map.

func DecodeUserCopy

func DecodeUserCopy(b []byte) map[string]interface{}

DecodeUserCopy decodes encoded user by EncodeUserCopy

func DecodeUserData

func DecodeUserData(encoded string) (map[string]interface{}, error)

DecodeUserData decodes encoded user property data to a map

func DiscardUser

func DiscardUser(reliableClientAddr string, sid string)

DiscardUser Deletes a user data. Either reliableClientAddr or SID to be used.

Note

Uses mutex lock internally.

Note

Newer version of the clients use SID instead of the client address.

Parameters

reliableClientAddr - Client address of the user to be discarded.
sid                - User SID of the user to be discarded.

func EmitOnReconnect

func EmitOnReconnect(newAddr string, userData *User) error

EmitOnReconnect emits the onReconnectCallbacks.

func EncodeUserCopy

func EncodeUserCopy(user *User) []byte

EncodeUserCopy encodes the user into a byte array to be decoded by DecodeUserCopy.

func EncodeUserData

func EncodeUserData(user *User) (string, error)

EncodeUserData encodes the user property data to base64 string.

func ExistsByID

func ExistsByID(sid string) bool

ExistsByID returns true if the user by the given SID exists.

Note

This does NOT update user TTL.

Note

Uses mutex lock internally.

func GetAllUserIDs

func GetAllUserIDs() []string

GetAllUserIDs returns all user SIDs that are connected to the server process.

Important

This maybe extremely expensive to use as it loops all existing users on the server.

Important

Limiting the usage of this function for tests and debugging is recommended.

func GetCCU

func GetCCU() int

GetCCU returns the number of concurrent users of the server.

Note

Uses mutex lock internally..

func IsBlankUser

func IsBlankUser(u *User) bool

IsBlankUser returns true if the given *User is created by CreateBlankUser(sid string, uid string).

func OnClientAddressChange

func OnClientAddressChange(callback func(userData *User))

OnClientAddressChange assigns a callback on change client global address.

Public IP address is checked every time we receive TCP/UDP packets and if the address is changed, this callback will be triggered.

Important

All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a global IP address is changed on client side.
           func(userData *User)
           userData - User data of the user that made the new connection with the server.

func OnDiscard

func OnDiscard(callback func(sid string, userData *User))

OnDiscard Registers a callback on user data deletion.

Important

This function is not goroutine safe and it must not be used in runtime.
assign callbacks on the start of your process only.

Important

The callbacks are invoked while a mutex lock is held,
which means using mutex lock in the callbacks may result in unexpected blocking.

Parameters

callback - Callback to be invoked when the target user is deleted.
           func(sid string, userData *User)
           sid      - SID of the discarded user.
           userData - User data of the discarded user.

func OnNew

func OnNew(callback func(userData *User))

OnNew Registers a callback on user creation.

Important

All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a new user is created.
           func(userData *User)
           userData - User data of new user.

func OnNewConnection

func OnNewConnection(callback func(userData *User))

OnNewConnection assigns a callback on new user connection.

New connection is made and the user client actually establishes a valid connection with the server.

Important

All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a new user is created.
           func(userData *User)
           userData - User data of the user that made the new connection with the server.

func OnReconnect

func OnReconnect(callback func(newAddr string, userData *User) error)

OnReconnect assigns a callback before the user reconnects to the server.

func OnSIDUpdate

func OnSIDUpdate(callback func(previousSID string, newSID string, previousUserData *User, newUserData *User))

OnSIDUpdate assigns a callback to be invoked when the user changes its SID.

Important

The callbacks are invoked while a mutex lock is held,
which means using mutex lock in the callbacks may result in unexpected blocking.

Note

The callbacks are invoked when the user attempts to create a new user data with the existing user ID with different SID.
If the user attempts to create a new user data without calling Disconnect and the user data is not expired yet,
User module replaces the user data and SID.

func RemoveOnNewConnection

func RemoveOnNewConnection(callback func(userData *User))

RemoveOnNewConnection removes an assigned callback on new user connection.

func SetUserByID

func SetUserByID(sid string, user *User, ttl int64) bool

SetUserByID Sets a user data by SID.

It returns false if it fails to set the user.

Note

Uses mutex lock internally.

Parameters

sid  - User SID to store in the server memory.
user - User to be stored.
ttl  - TTL of the stored user in seconds. This will be extended by using Extend etc.

func Setup

func Setup(ttl int64)

Setup sets up user package without network protocol association.

ttl int64 - TTL of the user data in seconds.

func SetupAsTCPServer

func SetupAsTCPServer()

SetupAsTCPServer Sets up as TCP server.

Important

You must invoke this function before invoking diarkis.Start() to setup as TCP server.

Important

You may not setup both TCP and UDP.

func SetupAsUDPServer

func SetupAsUDPServer()

SetupAsUDPServer Sets up as UDP server

Important

You must invoke this function before invoking diarkis.Start() to setup as UDP server.

Important

You may not setup both TCP and UDP.

func UpdateUserByID

func UpdateUserByID(sid string) bool

UpdateUserByID Updates TTL of user data in the vault.

It returns false if the update fails.

Note

Uses mutex lock internally.

Parameters

sid - User SID of the target user to updated.

Types

type User

type User struct {
	// unique ID to identify the user by
	ID       string
	SID      string
	SIDBytes []byte
	// Key value storage: Do NOT use this map directly.
	// Use Get, Set, Update, and "GetAs..." instead.
	Data map[string]interface{}
	// Deprecated: no longer used.
	Payload  []byte
	TCPState *tcp.State
	// UDPState is always a new one.
	UDPState               *udp.State
	RUDPConn               *udp.Connection
	UDPClientLocalAddrList []string
	UDPClientKey           string
	// encryption keys
	EncryptionKey    []byte
	EncryptionIV     []byte
	EncryptionMacKey []byte

	sync.RWMutex
}

User represents user client and its property data, network connection.

func CreateBlankUser

func CreateBlankUser(sid, uid string) *User

CreateBlankUser creates an incomplete user to be used as a dummy.

Usage Example: Create a dummy user to create an empty room and/or group without actual client.

sid - Blank user SID.
uid - Blank user ID.

func CreateNewUser

func CreateNewUser(data map[string]interface{}, initTTL int64) (*User, int64, error)

CreateNewUser creates a new user data.

This function does NOT store the new user in the vault memory.

Input parameter data map[string]interface{} must contain the following properties:

Error Cases:

┌───────────────────────────┬──────────────────────────────────────────────────────────────────┐
│ Error                     │ Reason                                                           │
╞═══════════════════════════╪══════════════════════════════════════════════════════════════════╡
│ Failed to generate UUIDv4 │ crypto/rand.Ready failed.                                        │
├───────────────────────────┼──────────────────────────────────────────────────────────────────┤
│ User already exists       │ User with the same SID or UID already exists on the same server. │
└───────────────────────────┴──────────────────────────────────────────────────────────────────┘

> [!IMPORTANT] Uniqueness of the user by its SID and UID is guaranteed only on the same server.

Parameters

sid    - SID of the new user to be created. The format is UUID v4.
key    - Encryption key of the user.
iv     - Encryption IV of the user.
macKey - Encryption mac key of the user.
uid    - User ID.
data   - Optional property: Encoded user property data.

func GetUserByID deprecated

func GetUserByID(sid string) *User

GetUserByID has been deprecated and will be removed in the future. Please use GetUserBySID instead.

Deprecated: GetUserByID returns a user by its SID.

Important

It returns nil if the user is not found by the given SID.

Note

This does NOT update user TTL.

Note

Uses mutex lock internally.

Parameters

sid - User SID of the target user.

func GetUserBySID

func GetUserBySID(sid string) *User

GetUserBySID returns a user by its SID.

Important

It returns nil if the user is not found by the given SID.

Note

This does NOT update user TTL.

Note

Uses mutex lock internally.

Parameters

sid - User SID of the target user.

func GetUserByUID

func GetUserByUID(uid string) *User

GetUserByUID returns a user by its user ID (UID).

Important

It returns nil if the user is not found by the given UID.

Note

This does NOT update user TTL.

Note

Uses mutex lock internally.

Parameters

uid - User ID of the target user.

func (*User) Delete

func (user *User) Delete(key string) bool

Delete removes the key and its value and returns true if the deletion was successful.

Note

Uses mutex lock internally.

Note

If the key does not exist, it will simple do nothing and returns false.

func (*User) Disconnect

func (user *User) Disconnect()

Disconnect disconnects the client from the server

func (*User) Get

func (user *User) Get(key string) interface{}

Get returns a value associated with the key (SID) given

Note

Uses mutex lock internally.

User data must be handled by the user and nobody else, so no race condition...

Important

If you need to store a structured data, please use json label or convert to map instead.

Important

If the value is a map, the data type will become map[string]interface{} when the user moves to the other server.

Important

If the value is a slice, the data type will become []interface{} when the user moves to the other server.

Important

If the value is numeric, the data type will become float64 when the user moves to the other server.

Example:

numInterface := userData.GetAsInt("num") // this maybe float64, but we want to make sure it is read as an int

Parameters

key - User property key of the value to retrieve.

func (*User) GetAsBool

func (u *User) GetAsBool(k string) (bool, bool)

GetAsBool returns user data by its key as a bool.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Note

Uses mutex lock internally.

func (*User) GetAsBoolArray

func (u *User) GetAsBoolArray(k string) ([]bool, bool)

GetAsBoolArray returns user data by its key as an array of bool.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsBytes

func (u *User) GetAsBytes(k string) ([]byte, bool)

GetAsBytes returns user data by its key as a string.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the value held is a base64 encoded string, it will be returned as a byte array as a valid value.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsBytesArray

func (u *User) GetAsBytesArray(k string) ([][]byte, bool)

GetAsBytesArray returns user data by its key as an array of []byte.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsFloat32

func (u *User) GetAsFloat32(k string) (float32, bool)

GetAsFloat32 returns user data by its key as a float32.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsFloat32Array

func (u *User) GetAsFloat32Array(k string) ([]float32, bool)

GetAsFloat32Array returns user data by its key as an array of float32.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsFloat64

func (u *User) GetAsFloat64(k string) (float64, bool)

GetAsFloat64 returns user data by its key as a float64.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsFloat64Array

func (u *User) GetAsFloat64Array(k string) ([]float64, bool)

GetAsFloat64Array returns user data by its key as an array of float64.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsInt

func (u *User) GetAsInt(k string) (int, bool)

GetAsInt returns user data by its key as a int.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsInt16

func (u *User) GetAsInt16(k string) (int16, bool)

GetAsInt16 returns user data by its key as a int16.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsInt16Array

func (u *User) GetAsInt16Array(k string) ([]int16, bool)

GetAsInt16Array returns user data by its key as an array of int16.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

func (*User) GetAsInt32

func (u *User) GetAsInt32(k string) (int32, bool)

GetAsInt32 returns user data by its key as a int32.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsInt32Array

func (u *User) GetAsInt32Array(k string) ([]int32, bool)

GetAsInt32Array returns user data by its key as an array of int32.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsInt64

func (u *User) GetAsInt64(k string) (int64, bool)

GetAsInt64 returns user data by its key as a int64.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsInt64Array

func (u *User) GetAsInt64Array(k string) ([]int64, bool)

GetAsInt64Array returns user data by its key as an array of int64.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsInt8

func (u *User) GetAsInt8(k string) (int8, bool)

GetAsInt8 returns user data by its key as a int8.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsInt8Array

func (u *User) GetAsInt8Array(k string) ([]int8, bool)

GetAsInt8Array returns user data by its key as an array of int8.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsIntArray

func (u *User) GetAsIntArray(k string) ([]int, bool)

GetAsIntArray returns user data by its key as an array of int.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsString

func (u *User) GetAsString(k string) (string, bool)

GetAsString returns user data by its key as a string.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Note

Uses mutex lock internally.

func (*User) GetAsStringArray

func (u *User) GetAsStringArray(k string) ([]string, bool)

GetAsStringArray returns user data by its key as an array of string.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsUint

func (u *User) GetAsUint(k string) (uint, bool)

GetAsUint returns user data by its key as a uint.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsUint16

func (u *User) GetAsUint16(k string) (uint16, bool)

GetAsUint16 returns user data by its key as a uint16.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsUint16Array

func (u *User) GetAsUint16Array(k string) ([]uint16, bool)

GetAsUint16Array returns user data by its key as an array of uint16.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsUint32

func (u *User) GetAsUint32(k string) (uint32, bool)

GetAsUint32 returns user data by its key as a uint32.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsUint32Array

func (u *User) GetAsUint32Array(k string) ([]uint32, bool)

GetAsUint32Array returns user data by its key as an array of uint32.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

func (*User) GetAsUint64

func (u *User) GetAsUint64(k string) (uint64, bool)

GetAsUint64 returns user data by its key as a uint32.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsUint64Array

func (u *User) GetAsUint64Array(k string) ([]uint64, bool)

GetAsUint64Array returns user data by its key as an array of uint64.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsUint8

func (u *User) GetAsUint8(k string) (uint8, bool)

GetAsUint8 returns user data by its key as a uint8.

Important

The second returned value indicates if the value exists or not.
The second value will be true, if the value is invalid or missing.

Important

If the held value is float64, it will be converted to the correct type and returned as a valid value.

Note

Uses mutex lock internally.

func (*User) GetAsUint8Array

func (u *User) GetAsUint8Array(k string) ([]uint8, bool)

GetAsUint8Array returns user data by its key as an array of uint8.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetAsUintArray

func (u *User) GetAsUintArray(k string) ([]uint, bool)

GetAsUintArray returns user data by its key as an array of uint.

Important

The second returned value indicates if the value exists or not.
The second value will be false, if the value data type is not invalid or missing.
Valid means that the value is of the correct data type.

Important

If one or more elements in the array are not the specified data type,
the second return value will be false.

Important

If one or more elements in the array are to be float64,
it is an exception that will be auto-converted to the specified numerical data type
and the second return value will be true.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) GetClientAddr

func (user *User) GetClientAddr() string

GetClientAddr returns the user client address.

Important

If the UDP server has a configuration enableP2P: false,
The returned value will be "0.0.0.0:0".

func (*User) GetClientKey

func (user *User) GetClientKey() string

GetClientKey returns clientKey.

Returns an empty string if client key is not set by environment variable DIARKIS_CLIENT_KEY.

func (*User) GetClientTransport

func (user *User) GetClientTransport() int

GetClientTransport returns enum to indicate which network transport the user client is using:

Possible values:

TCPClient int = 1
UDPClient int = 2
WSClient  int = 3
UnknownClient int = 4 // this should never happen...

func (*User) GetLatency

func (user *User) GetLatency() int64

GetLatency returns server-to-client latency in milliseconds of the user client.

func (*User) GetReconnectAddr

func (user *User) GetReconnectAddr() string

GetReconnectAddr returns the new address for the user to reconnect to. Value is only returned if IsReconnecting() returns true.

func (*User) ImportUserData

func (user *User) ImportUserData(ud map[string]interface{})

ImportUserData imports the given map as user data.

Important

If the map contains invalid data type value,
the value will NOT be imported.

func (*User) IsConnected

func (user *User) IsConnected() bool

IsConnected returns true if the user client is connected to the server. This function is used on the new server after a user reconnect. This can return false when following conditions are met:

  1. The user authenticated but not connected to the server.
  2. The user is reconnecting from the other server.

func (*User) IsReconnecting

func (user *User) IsReconnecting() bool

IsReconnecting returns true if the user client is in the process of reconnection to the other server. This function is used on the old server during the user reconnect process.

func (*User) IsTCP

func (user *User) IsTCP() bool

IsTCP returns true if the user client is TCP

func (*User) IsUDP

func (user *User) IsUDP() bool

IsUDP returns true if the user client is UDP

func (*User) Push deprecated

func (user *User) Push(message []byte, reliable bool)

Push use ServerPush instead

Deprecated: Use [PushToClient] instead.

func (*User) PushToClient

func (user *User) PushToClient(ver uint8, cmd uint16, message []byte, reliable packet.ReliableFlag)

PushToClient Sends a push packet from the server to the target user client.

ver       - Server push message command version.
cmd       - Server push message command ID.
message   - Message byte array to be sent as a push.
reliable  - If true, UDP will become RUDP.

func (*User) Respond deprecated

func (user *User) Respond(message []byte, status uint8, reliable bool)

Respond use ServerRespond instead

Deprecated: Use [ServerRespond] instead.

func (*User) Send deprecated

func (user *User) Send(ver uint8, cmd uint16, message []byte, status uint8, reliable bool)

Send Sends a packet from the server to the target user client with a response status

Deprecated:

func (*User) ServerPush

func (user *User) ServerPush(ver uint8, cmd uint16, message []byte, reliable bool)

ServerPush Sends a push packet from the server to the target user client.

ver       - Server push message command version.
cmd       - Server push message command ID.
message   - Message byte array to be sent as a push.
reliable  - If true, UDP will become RUDP.

TODO: Deprecated: Use [PushToClient] instead.

func (*User) ServerRespond

func (user *User) ServerRespond(message []byte, ver uint8, cmd uint16, status uint8, reliable bool)

ServerRespond sends a packet as a response w/ ver and cmd of your choice

message  - Message byte array to be sent as a response.
ver      - Server response command version.
cmd      - Server response command ID.
status   - Server response status. Status consts are available in server package.
           server.Ok (success), server.Bad (error caused by the user), server.Err (error caused by the server).
reliable - If true, UDP will become RUDP.

func (*User) Set deprecated

func (user *User) Set(key string, value interface{})

Set stores a value along with the key (SID): the value will remain stored until user object is discarded

Deprecated: This function will be removed at v2.0.0. Use SetAs* instead.

Note

Uses mutex lock internally.

User data must be handled by the user and nobody else, so no race condition....

Important

value does NOT support struct. If you need to store a structured data, please use map instead.

Important

If you store complex data types such as maps etc all value type will be stored as interface{}.

func (*User) SetAsBool

func (u *User) SetAsBool(k string, v bool) bool

SetAsBool sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsBoolArray

func (u *User) SetAsBoolArray(k string, v []bool) bool

SetAsBoolArray sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsBytes

func (u *User) SetAsBytes(k string, v []byte) bool

SetAsBytes sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsBytesArray

func (u *User) SetAsBytesArray(k string, v [][]byte) bool

SetAsBytesArray sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsFloat32

func (u *User) SetAsFloat32(k string, v float32) bool

SetAsFloat32 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsFloat32Array

func (u *User) SetAsFloat32Array(k string, v []float32) bool

SetAsFloat32Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsFloat64

func (u *User) SetAsFloat64(k string, v float64) bool

SetAsFloat64 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsFloat64Array

func (u *User) SetAsFloat64Array(k string, v []float64) bool

SetAsFloat64Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsInt

func (u *User) SetAsInt(k string, v int) bool

SetAsInt sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsInt16

func (u *User) SetAsInt16(k string, v int16) bool

SetAsInt16 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsInt16Array

func (u *User) SetAsInt16Array(k string, v []int16) bool

SetAsInt16Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsInt32

func (u *User) SetAsInt32(k string, v int32) bool

SetAsInt32 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsInt32Array

func (u *User) SetAsInt32Array(k string, v []int32) bool

SetAsInt32Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsInt64

func (u *User) SetAsInt64(k string, v int64) bool

SetAsInt64 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsInt64Array

func (u *User) SetAsInt64Array(k string, v []int64) bool

SetAsInt64Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsInt8

func (u *User) SetAsInt8(k string, v int8) bool

SetAsInt8 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsInt8Array

func (u *User) SetAsInt8Array(k string, v []int8) bool

SetAsInt8Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsIntArray

func (u *User) SetAsIntArray(k string, v []int) bool

SetAsIntArray sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsString

func (u *User) SetAsString(k string, v string) bool

SetAsString sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsStringArray

func (u *User) SetAsStringArray(k string, v []string) bool

SetAsStringArray sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsUint

func (u *User) SetAsUint(k string, v uint) bool

SetAsUint sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsUint16

func (u *User) SetAsUint16(k string, v uint16) bool

SetAsUint16 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsUint16Array

func (u *User) SetAsUint16Array(k string, v []uint16) bool

SetAsUint16Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsUint32

func (u *User) SetAsUint32(k string, v uint32) bool

SetAsUint32 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsUint32Array

func (u *User) SetAsUint32Array(k string, v []uint32) bool

SetAsUint32Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsUint64

func (u *User) SetAsUint64(k string, v uint64) bool

SetAsUint64 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsUint64Array

func (u *User) SetAsUint64Array(k string, v []uint64) bool

SetAsUint64Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsUint8

func (u *User) SetAsUint8(k string, v uint8) bool

SetAsUint8 sets the key and value.

Note

Uses mutex lock internally.

func (*User) SetAsUint8Array

func (u *User) SetAsUint8Array(k string, v []uint8) bool

SetAsUint8Array sets the key and its value.

Note

Uses mutex lock internally.

func (*User) SetAsUintArray

func (u *User) SetAsUintArray(k string, v []uint) bool

SetAsUintArray sets the key and its value.

Note

Uses mutex lock internally.

func (*User) Update deprecated

func (user *User) Update(key string, op func(data interface{}) interface{})

Update allows a custom operation function to "update" user data by its key

Deprecated: This function will be removed at v2.0.0. Use UpdateAs* instead.

Note

Uses mutex lock internally.

Important

value does NOT support struct. If you need to store a structured data, please use map instead.

Important

If you store complex data types such as maps etc all value type will be stored as interface{}.

Parameters

key - Key of the user property to be updated.
op  - Operation function to handle the property update.

func (*User) UpdateAsBool

func (u *User) UpdateAsBool(k string, cb func(v bool, found bool) (bool, bool)) (bool, bool)

UpdateAsBool sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsBoolArray

func (u *User) UpdateAsBoolArray(k string, cb func(v []bool, found bool) ([]bool, bool)) ([]bool, bool)

UpdateAsBoolArray sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsBytes

func (u *User) UpdateAsBytes(k string, cb func(v []byte, found bool) ([]byte, bool)) ([]byte, bool)

UpdateAsBytes sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsBytesArray

func (u *User) UpdateAsBytesArray(k string, cb func(v [][]byte, found bool) ([][]byte, bool)) ([][]byte, bool)

UpdateAsBytesArray sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsFloat32

func (u *User) UpdateAsFloat32(k string, cb func(v float32, found bool) (float32, bool)) (float32, bool)

UpdateAsFloat32 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsFloat32Array

func (u *User) UpdateAsFloat32Array(k string, cb func(v []float32, found bool) ([]float32, bool)) ([]float32, bool)

UpdateAsFloat32Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsFloat64

func (u *User) UpdateAsFloat64(k string, cb func(v float64, found bool) (float64, bool)) (float64, bool)

UpdateAsFloat64 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsFloat64Array

func (u *User) UpdateAsFloat64Array(k string, cb func(v []float64, found bool) ([]float64, bool)) ([]float64, bool)

UpdateAsFloat64Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsInt

func (u *User) UpdateAsInt(k string, cb func(v int, found bool) (int, bool)) (int, bool)

UpdateAsInt sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsInt16

func (u *User) UpdateAsInt16(k string, cb func(v int16, found bool) (int16, bool)) (int16, bool)

UpdateAsInt16 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsInt16Array

func (u *User) UpdateAsInt16Array(k string, cb func(v []int16, found bool) ([]int16, bool)) ([]int16, bool)

UpdateAsInt16Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsInt32

func (u *User) UpdateAsInt32(k string, cb func(v int32, found bool) (int32, bool)) (int32, bool)

UpdateAsInt32 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsInt32Array

func (u *User) UpdateAsInt32Array(k string, cb func(v []int32, found bool) ([]int32, bool)) ([]int32, bool)

UpdateAsInt32Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsInt64

func (u *User) UpdateAsInt64(k string, cb func(v int64, found bool) (int64, bool)) (int64, bool)

UpdateAsInt64 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsInt64Array

func (u *User) UpdateAsInt64Array(k string, cb func(v []int64, found bool) ([]int64, bool)) ([]int64, bool)

UpdateAsInt64Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsInt8

func (u *User) UpdateAsInt8(k string, cb func(v int8, found bool) (int8, bool)) (int8, bool)

UpdateAsInt8 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsInt8Array

func (u *User) UpdateAsInt8Array(k string, cb func(v []int8, found bool) ([]int8, bool)) ([]int8, bool)

UpdateAsInt8Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsIntArray

func (u *User) UpdateAsIntArray(k string, cb func(v []int, found bool) ([]int, bool)) ([]int, bool)

UpdateAsIntArray sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsString

func (u *User) UpdateAsString(k string, cb func(v string, found bool) (string, bool)) (string, bool)

UpdateAsString sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsStringArray

func (u *User) UpdateAsStringArray(k string, cb func(v []string, found bool) ([]string, bool)) ([]string, bool)

UpdateAsStringArray sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsUint

func (u *User) UpdateAsUint(k string, cb func(v uint, found bool) (uint, bool)) (uint, bool)

UpdateAsUint sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsUint16

func (u *User) UpdateAsUint16(k string, cb func(v uint16, found bool) (uint16, bool)) (uint16, bool)

UpdateAsUint16 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsUint16Array

func (u *User) UpdateAsUint16Array(k string, cb func(v []uint16, found bool) ([]uint16, bool)) ([]uint16, bool)

UpdateAsUint16Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsUint32

func (u *User) UpdateAsUint32(k string, cb func(v uint32, found bool) (uint32, bool)) (uint32, bool)

UpdateAsUint32 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsUint32Array

func (u *User) UpdateAsUint32Array(k string, cb func(v []uint32, found bool) ([]uint32, bool)) ([]uint32, bool)

UpdateAsUint32Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsUint64

func (u *User) UpdateAsUint64(k string, cb func(v uint64, found bool) (uint64, bool)) (uint64, bool)

UpdateAsUint64 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsUint64Array

func (u *User) UpdateAsUint64Array(k string, cb func(v []uint64, found bool) ([]uint64, bool)) ([]uint64, bool)

UpdateAsUint64Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsUint8

func (u *User) UpdateAsUint8(k string, cb func(v uint8, found bool) (uint8, bool)) (uint8, bool)

UpdateAsUint8 sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

func (*User) UpdateAsUint8Array

func (u *User) UpdateAsUint8Array(k string, cb func(v []uint8, found bool) ([]uint8, bool)) ([]uint8, bool)

UpdateAsUint8Array sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.

func (*User) UpdateAsUintArray

func (u *User) UpdateAsUintArray(k string, cb func(v []uint, found bool) ([]uint, bool)) ([]uint, bool)

UpdateAsUintArray sets or updates the value to the given key if the callback's second return value is true. The first returned value of the callback will be the value to be stored for the given key.

Important

The callback receives two arguments:
First argument: The value of the key as the data type indicated by the name of the function.
Use the same data type as the GetAs...() function to retrieve the value.
Second argument: True, if the value exists. If the given key has no value, this argument is false.

Important

While in the callback no other get/set/update function should be called.

Note

Uses mutex lock internally.

Note

The first value returns a copy of the original value.