Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateID ¶ added in v0.0.57
ValidateID validates and parses a Unix timestamp ID string. It handles IDs in both server format (just timestamp) and client format (timestamp.userNumber). This function extracts the timestamp portion from the ID and returns it as an int64.
Parameters:
- new_id_in: The ID string to validate (e.g., "1624397134562544800" or "1624397134562544800.42")
Returns:
- id: The timestamp portion of the ID as an int64 value
- err: An error if the ID format is invalid
Validation rules:
- The ID must contain only digits and at most one decimal point
- The timestamp portion (before the decimal point) must be a valid int64
Types ¶
type Config ¶ added in v0.0.54
type Config struct {
// Session provides user session numbers in WebAssembly environments
Session userSessionNumber // e.g., userSessionNumber() string = "1","4","4000" etc.
// contains filtered or unexported fields
}
Config holds the configuration and dependencies for a UnixID instance
type UnixID ¶
type UnixID struct {
// Config holds the external dependencies for the UnixID
*Config
// contains filtered or unexported fields
}
UnixID is the main struct for ID generation and handling It contains all configuration and state needed for ID generation
func (*UnixID) FieldType ¶ added in v0.0.55
FieldType determines if a field is an ID field and/or a primary key field. This function analyzes field names to identify ID fields and primary keys based on naming conventions.
Parameters:
- tableName: The name of the table or entity that the field belongs to
- fieldName: The name of the field to analyze
Returns:
- ID: true if the field is an ID field (starts with "id")
- PK: true if the field is a primary key (is named "id" or matches the pattern "id{tableName}" or "id_{tableName}")
Examples:
- FieldType("user", "id") returns (true, true)
- FieldType("user", "iduser") returns (true, true)
- FieldType("user", "id_user") returns (true, true)
- FieldType("user", "idaddress") returns (true, false)
func (*UnixID) GetNewID ¶
GetNewID generates a new unique ID based on Unix nanosecond timestamp. In client-side WebAssembly environments, this appends a user session number to the timestamp, separated by a dot (e.g., "1624397134562544800.42"). This helps ensure that IDs are unique even across different client sessions. Returns a string representation of the unique ID or an error if the user session number can't be obtained.
func (*UnixID) SetValue ¶ added in v0.0.55
SetValue sets a unique ID value to a struct field using reflection. For WASM environments, the ID includes the user session number as a suffix. Parameters:
- rv: A reflect.Value pointer to the struct field that will receive the ID
- valueOut: A pointer to a string that will store the generated ID
- sizeOut: A byte slice that will track the size of the generated value
Returns nil on success or an error if the operation fails.
func (*UnixID) UnixNanoToStringDate ¶ added in v0.0.54
UnixNanoToStringDate converts a Unix nanosecond timestamp ID to a human-readable date string. This function accepts a string representation of a Unix nanosecond timestamp (with or without a user number suffix) and returns a formatted date string in the format "2006-01-02 15:04" (year-month-day hour:minute).
Parameters:
- unixNanoStr: String representation of a Unix timestamp in nanoseconds (e.g. "1624397134562544800" or "1624397134562544800.42")
Returns:
- A formatted date string (e.g. "2021-06-22 15:32")
- An error if the input is invalid or the conversion fails
Example:
dateStr, err := handler.UnixNanoToStringDate("1624397134562544800")
if err != nil {
// handle error
}
fmt.Println(dateStr) // e.g. "2021-06-22 15:32"