common

package module
v0.0.0-...-76e6372 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PrefixLength = 4
)

Variables

This section is empty.

Functions

func GeneratePasswordFromUserId

func GeneratePasswordFromUserId(userId, secret string, nBytes int) string

GeneratePasswordFromUserId generates a deterministic shorter password from user ID using HMAC-SHA256. This is used for third-party system integration where users are auto-created.

Parameters:

  • userId: The IM system user ID (e.g., "u___42" or "ag__7")
  • secret: A secret key from configuration (should be kept secure)
  • nBytes: number of bytes to keep from HMAC (e.g. 12 or 16)

Returns:

  • A shorter deterministic string that can be used as password

Example:

password := GeneratePasswordFromUserId("u___42", "my-secret-key", 12)
// password will always be the same for "u___42" with the same secret

Types

type Actor

type Actor struct {
	Id   int64
	Role RoleType
}

Actor represents an external identity that maps to an IM user id.

func (*Actor) FromIMUserId

func (a *Actor) FromIMUserId(userId string) error

FromIMUserId parses an IM user id string back into an Actor. Returns an error if the format is unrecognised.

func (*Actor) ToIMUserId

func (a *Actor) ToIMUserId() (string, error)

ToIMUserId converts an Actor to the IM system's string user id.

Actor{ID: 42, Role: RoleUser}.ToIMUserId()  => "u___42"
Actor{ID: 7, Role: RoleAgent}.ToIMUserId()  => "ag__7"

type RoleType

type RoleType string

RoleType defines the actor role in the IM system.

const (
	RoleUser  RoleType = "user"
	RoleAgent RoleType = "agent"
)

Jump to

Keyboard shortcuts

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