package user
import "github.com/Diarkis/diarkis/user"
Index
- Constants
- func CopyUser(user *User) map[string]interface{}
- func DecodeUserCopy(b []byte) map[string]interface{}
- func DecodeUserData(encoded string) (map[string]interface{}, error)
- func DiscardUser(reliableClientAddr string, sid string)
- func EmitOnReconnect(newAddr string, userData *User) error
- func EncodeUserCopy(user *User) []byte
- func EncodeUserData(user *User) (string, error)
- func ExistsByID(sid string) bool
- func GetAllUserIDs() []string
- func GetCCU() int
- func IsBlankUser(u *User) bool
- func New(data map[string]interface{}, initTTL int64) (map[string]interface{}, error)
- func OnClientAddressChange(callback func(userData *User))
- func OnDiscard(callback func(sid string, userData *User))
- func OnNew(callback func(userData *User))
- func OnNewConnection(callback func(userData *User))
- func OnReconnect(callback func(newAddr string, userData *User) error)
- func OnSIDUpdate(...)
- func RemoveOnNewConnection(callback func(userData *User))
- func SetUserByID(sid string, user *User, ttl int64) bool
- func Setup(ttl int64)
- func SetupAsTCPServer()
- func SetupAsUDPServer()
- func UpdateUserByID(sid string) bool
-
type User
- func CreateBlankUser(sid, uid string) *User
- func CreateNewUser(data map[string]interface{}, initTTL int64) (*User, int64, error)
- func GetUserByID(sid string) *User deprecated
- func GetUserBySID(sid string) *User
- func GetUserByUID(uid string) *User
- func (user *User) Delete(key string) bool
- func (user *User) Disconnect()
- func (user *User) Get(key string) interface{}
- func (u *User) GetAsBool(k string) (bool, bool)
- func (u *User) GetAsBoolArray(k string) ([]bool, bool)
- func (u *User) GetAsBytes(k string) ([]byte, bool)
- func (u *User) GetAsBytesArray(k string) ([][]byte, bool)
- func (u *User) GetAsFloat32(k string) (float32, bool)
- func (u *User) GetAsFloat32Array(k string) ([]float32, bool)
- func (u *User) GetAsFloat64(k string) (float64, bool)
- func (u *User) GetAsFloat64Array(k string) ([]float64, bool)
- func (u *User) GetAsInt(k string) (int, bool)
- func (u *User) GetAsInt16(k string) (int16, bool)
- func (u *User) GetAsInt16Array(k string) ([]int16, bool)
- func (u *User) GetAsInt32(k string) (int32, bool)
- func (u *User) GetAsInt32Array(k string) ([]int32, bool)
- func (u *User) GetAsInt64(k string) (int64, bool)
- func (u *User) GetAsInt64Array(k string) ([]int64, bool)
- func (u *User) GetAsInt8(k string) (int8, bool)
- func (u *User) GetAsInt8Array(k string) ([]int8, bool)
- func (u *User) GetAsIntArray(k string) ([]int, bool)
- func (u *User) GetAsString(k string) (string, bool)
- func (u *User) GetAsStringArray(k string) ([]string, bool)
- func (u *User) GetAsUint(k string) (uint, bool)
- func (u *User) GetAsUint16(k string) (uint16, bool)
- func (u *User) GetAsUint16Array(k string) ([]uint16, bool)
- func (u *User) GetAsUint32(k string) (uint32, bool)
- func (u *User) GetAsUint32Array(k string) ([]uint32, bool)
- func (u *User) GetAsUint64(k string) (uint64, bool)
- func (u *User) GetAsUint64Array(k string) ([]uint64, bool)
- func (u *User) GetAsUint8(k string) (uint8, bool)
- func (u *User) GetAsUint8Array(k string) ([]uint8, bool)
- func (u *User) GetAsUintArray(k string) ([]uint, bool)
- func (user *User) GetClientAddr() string
- func (user *User) GetClientKey() string
- func (user *User) GetClientTransport() int
- func (user *User) GetLatency() int64
- func (user *User) ImportUserData(ud map[string]interface{})
- func (user *User) IsReconnecting() bool
- func (user *User) IsTCP() bool
- func (user *User) IsUDP() bool
- func (user *User) OnClientAddressChange(callback func())
- func (user *User) OnNewConnection(callback func())
- func (user *User) Push(message []byte, reliable bool)
- func (user *User) RemoveOnNewConnection()
- func (user *User) Respond(message []byte, status uint8, reliable bool)
- func (user *User) Send(ver uint8, cmd uint16, message []byte, status uint8, reliable bool)
- func (user *User) ServerPush(ver uint8, cmd uint16, message []byte, reliable bool)
- func (user *User) ServerRespond(message []byte, ver uint8, cmd uint16, status uint8, reliable bool)
- func (user *User) Set(key string, value interface{}) deprecated
- func (u *User) SetAsBool(k string, v bool) bool
- func (u *User) SetAsBoolArray(k string, v []bool) bool
- func (u *User) SetAsBytes(k string, v []byte) bool
- func (u *User) SetAsBytesArray(k string, v [][]byte) bool
- func (u *User) SetAsFloat32(k string, v float32) bool
- func (u *User) SetAsFloat32Array(k string, v []float32) bool
- func (u *User) SetAsFloat64(k string, v float64) bool
- func (u *User) SetAsFloat64Array(k string, v []float64) bool
- func (u *User) SetAsInt(k string, v int) bool
- func (u *User) SetAsInt16(k string, v int16) bool
- func (u *User) SetAsInt16Array(k string, v []int16) bool
- func (u *User) SetAsInt32(k string, v int32) bool
- func (u *User) SetAsInt32Array(k string, v []int32) bool
- func (u *User) SetAsInt64(k string, v int64) bool
- func (u *User) SetAsInt64Array(k string, v []int64) bool
- func (u *User) SetAsInt8(k string, v int8) bool
- func (u *User) SetAsInt8Array(k string, v []int8) bool
- func (u *User) SetAsIntArray(k string, v []int) bool
- func (u *User) SetAsString(k string, v string) bool
- func (u *User) SetAsStringArray(k string, v []string) bool
- func (u *User) SetAsUint(k string, v uint) bool
- func (u *User) SetAsUint16(k string, v uint16) bool
- func (u *User) SetAsUint16Array(k string, v []uint16) bool
- func (u *User) SetAsUint32(k string, v uint32) bool
- func (u *User) SetAsUint32Array(k string, v []uint32) bool
- func (u *User) SetAsUint64(k string, v uint64) bool
- func (u *User) SetAsUint64Array(k string, v []uint64) bool
- func (u *User) SetAsUint8(k string, v uint8) bool
- func (u *User) SetAsUint8Array(k string, v []uint8) bool
- func (u *User) SetAsUintArray(k string, v []uint) bool
- func (user *User) SetLatency(clientTime int64)
- func (user *User) Update(key string, op func(data interface{}) interface{}) deprecated
- func (u *User) UpdateAsBool(k string, cb func(v bool, found bool) (bool, bool)) (bool, bool)
- func (u *User) UpdateAsBoolArray(k string, cb func(v []bool, found bool) ([]bool, bool)) ([]bool, bool)
- func (u *User) UpdateAsBytes(k string, cb func(v []byte, found bool) ([]byte, bool)) ([]byte, bool)
- func (u *User) UpdateAsBytesArray(k string, cb func(v [][]byte, found bool) ([][]byte, bool)) ([][]byte, bool)
- func (u *User) UpdateAsFloat32(k string, cb func(v float32, found bool) (float32, bool)) (float32, bool)
- func (u *User) UpdateAsFloat32Array(k string, cb func(v []float32, found bool) ([]float32, bool)) ([]float32, bool)
- func (u *User) UpdateAsFloat64(k string, cb func(v float64, found bool) (float64, bool)) (float64, bool)
- func (u *User) UpdateAsFloat64Array(k string, cb func(v []float64, found bool) ([]float64, bool)) ([]float64, bool)
- func (u *User) UpdateAsInt(k string, cb func(v int, found bool) (int, bool)) (int, bool)
- func (u *User) UpdateAsInt16(k string, cb func(v int16, found bool) (int16, bool)) (int16, bool)
- func (u *User) UpdateAsInt16Array(k string, cb func(v []int16, found bool) ([]int16, bool)) ([]int16, bool)
- func (u *User) UpdateAsInt32(k string, cb func(v int32, found bool) (int32, bool)) (int32, bool)
- func (u *User) UpdateAsInt32Array(k string, cb func(v []int32, found bool) ([]int32, bool)) ([]int32, bool)
- func (u *User) UpdateAsInt64(k string, cb func(v int64, found bool) (int64, bool)) (int64, bool)
- func (u *User) UpdateAsInt64Array(k string, cb func(v []int64, found bool) ([]int64, bool)) ([]int64, bool)
- func (u *User) UpdateAsInt8(k string, cb func(v int8, found bool) (int8, bool)) (int8, bool)
- func (u *User) UpdateAsInt8Array(k string, cb func(v []int8, found bool) ([]int8, bool)) ([]int8, bool)
- func (u *User) UpdateAsIntArray(k string, cb func(v []int, found bool) ([]int, bool)) ([]int, bool)
- func (u *User) UpdateAsString(k string, cb func(v string, found bool) (string, bool)) (string, bool)
- func (u *User) UpdateAsStringArray(k string, cb func(v []string, found bool) ([]string, bool)) ([]string, bool)
- func (u *User) UpdateAsUint(k string, cb func(v uint, found bool) (uint, bool)) (uint, bool)
- func (u *User) UpdateAsUint16(k string, cb func(v uint16, found bool) (uint16, bool)) (uint16, bool)
- func (u *User) UpdateAsUint16Array(k string, cb func(v []uint16, found bool) ([]uint16, bool)) ([]uint16, bool)
- func (u *User) UpdateAsUint32(k string, cb func(v uint32, found bool) (uint32, bool)) (uint32, bool)
- func (u *User) UpdateAsUint32Array(k string, cb func(v []uint32, found bool) ([]uint32, bool)) ([]uint32, bool)
- func (u *User) UpdateAsUint64(k string, cb func(v uint64, found bool) (uint64, bool)) (uint64, bool)
- func (u *User) UpdateAsUint64Array(k string, cb func(v []uint64, found bool) ([]uint64, bool)) ([]uint64, bool)
- func (u *User) UpdateAsUint8(k string, cb func(v uint8, found bool) (uint8, bool)) (uint8, bool)
- func (u *User) UpdateAsUint8Array(k string, cb func(v []uint8, found bool) ([]uint8, bool)) ([]uint8, bool)
- func (u *User) UpdateAsUintArray(k string, cb func(v []uint, found bool) ([]uint, bool)) ([]uint, bool)
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
userData - 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 New
func New(data map[string]interface{}, initTTL int64) (map[string]interface{}, error)
New [INTERNAL USE ONLY] handle mesh network command sent from HTTP
[NOTE] Uses mutex lock internally. [IMPORTANT] The return value of map[string]interface{} is always nil with or without error returned.
If initTTL is greater than 0, it will be used as the initial TTL (in seconds)
If initTTL is 0 or less, config TTL will be used as the initial TTL (in seconds)
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.New()
[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. userData - 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 IsMoving bool // Key value storage: Do NOT use this map directly. // Use Get, Set, Update, and "GetAs..." instead. Data map[string]interface{} // Deprecated and no longer used Payload []byte TCPState *tcp.State UDPState *udp.State RUDPConn *udp.Connection UDPClientLocalAddrList []string // UDPState is always a new one.. UDPClientKey string // encryption keys EncryptionKey []byte EncryptionIV []byte EncryptionMacKey []byte sync.RWMutex // contains filtered or unexported fields }
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 UUID v4 | 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
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 string - 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) 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) IsReconnecting
func (user *User) IsReconnecting() bool
IsReconnecting returns true if the user client is in the process of reconnection to the other server.
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) OnClientAddressChange
func (user *User) OnClientAddressChange(callback func())
OnClientAddressChange [INTERNAL USE ONLY]
callback - Callback to be invoked when a public IP address for the client is changed
func (*User) OnNewConnection
func (user *User) OnNewConnection(callback func())
OnNewConnection [INTERNAL USE ONLY]
[NOTE] Uses mutex lock internally. callback - Callback to be invoked when a new user connection is established with the client.
func (*User) Push
func (user *User) Push(message []byte, reliable bool)
Push use ServerPush instead
Deprecated
func (*User) RemoveOnNewConnection
func (user *User) RemoveOnNewConnection()
RemoveOnNewConnection [INTERNAL USE ONLY]
func (*User) Respond
func (user *User) Respond(message []byte, status uint8, reliable bool)
Respond use ServerRespond instead
Deprecated
func (*User) Send
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.
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{}. key string - Key of the user property to be set. value interface{} - Value of the user property to be set.
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) SetLatency
func (user *User) SetLatency(clientTime int64)
SetLatency [INTERNAL USE ONLY]
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.
Parameters
func (*User) Update deprecated
func (user *User) Update(key string, op func(data interface{}) interface{})
[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{}.
key string - Key of the user property to be updated.
op func(targetPropertyValue interface{}) - 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.