utils

package module
v0.0.0-...-a867e63 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

README

GEEKROS UTILS COMPONENT

⚡ Utils Component For GEEKROS ⚡

License

Basic Requirements

Your device should meet the following basic requirements.

Distributor ID: Ubuntu
Description:    Ubuntu 24.04.4 LTS
Release:        24.04
Codename:       noble

Development Team

GEEKROS https://www.geekros.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmountConvert

func AmountConvert(amount int) string

AmountConvert converts an amount in cents to a string representation in yuan with two decimal places.

func AmountToYuan

func AmountToYuan(amount int) float64

AmountToYuan converts an amount in cents to a float64 representation in yuan.

func CalcDiscountAmount

func CalcDiscountAmount(amount int, discount float64) int

CalcDiscountAmount calculates the discounted amount based on the original amount in cents and a discount rate.

func CalculateRequestDuration

func CalculateRequestDuration(clientTime int64) (float64, error)

CalculateRequestDuration calculates the duration between the client time and the current server time.

func ConvertChineseToKeyword

func ConvertChineseToKeyword(chinese string) string

ConvertChineseToKeyword converts Chinese characters to a keyword format suitable for wakeup detection.

func Downsample2to1Average

func Downsample2to1Average(in []int16) []int16

func EmailFormat

func EmailFormat(email string) string

EmailFormat masks part of the email address for privacy.

func EncryptMD5

func EncryptMD5(input string) string

EncryptMD5 generates an MD5 hash of the input string.

func Error

func Error(c *gin.Context, code int, data interface{})

Error sends an error response with a specific code and data.

func FormatPrompt

func FormatPrompt(prompt string, parameter map[string]string) string

FormatPrompt reads the system prompt file and replaces placeholders with provided parameters.

func GenerateID

func GenerateID(uid int) int

GenerateID generates an obfuscated ID using the Optimus algorithm.

func GenerateLoginToken

func GenerateLoginToken(uid int) (string, error)

GenerateToken creates a JWT token for a given user ID with a 15-day expiration.

func GenerateRealtimeToken

func GenerateRealtimeToken(uid int, project int, device int) (string, error)

GenerateRealtimeToken creates a JWT token for real-time communication with a 30-day expiration.

func GenerateToken

func GenerateToken(len int, id ...int) string

GenerateToken creates an obfuscated API key using the Hashids algorithm.

func GetCurrentUnix

func GetCurrentUnix() int

GetCurrentUnix returns the current Unix timestamp.

func GetCurrentUnixMilli

func GetCurrentUnixMilli() int

GetCurrentUnixMilli returns the current Unix timestamp in milliseconds.

func GetDate

func GetDate() string

GetDate returns the current date in YYYY-MM-DD format.

func GetLunarDate

func GetLunarDate() string

GetLunarDate returns a placeholder for the current lunar date.

func GetTencentCloudLocalIP

func GetTencentCloudLocalIP() (string, error)

func GetTencentCloudPublicIP

func GetTencentCloudPublicIP() (string, error)

func GetTime

func GetTime() string

GetTime returns the current time in HH:MM:SS format.

func GetUUID

func GetUUID() string

UUID is a utility function to generate a new UUID.

func GetWeekday

func GetWeekday() string

GetWeekday returns the current weekday as a string.

func IsLocalhost

func IsLocalhost(ipStr string) bool

IsLocalhost checks if the given IP address is a loopback address (localhost).

func MobileFormat

func MobileFormat(str string) string

MobileFormat format phone number

func PCMToWAV

func PCMToWAV(pcmData []byte, sampleRate, numChannels, bitsPerSample int) []byte

PCMToWAV converts raw PCM data to WAV format.

func ParseID

func ParseID(uid int) int

ParseID decodes an obfuscated ID back to the original user ID.

func ParseToken

func ParseToken(len int, key string) ([]int, error)

ParseToken decodes an obfuscated API key back to the original ID(s).

func RequestLog

func RequestLog(c *gin.Context, status string, response string)

RequestLog logs the details of the HTTP request and response.

func Sample48to16

func Sample48to16(in []int16) []int16

Sample48to16 converts 48kHz audio samples to 16kHz by downsampling.

func SendMail

func SendMail(to string, subject string, content string) bool

SendMail sends an email to the specified recipient with the given subject and content.

func Success

func Success(c *gin.Context, code int, data interface{})

Success sends a successful response with a specific code and data.

func TimeFormat

func TimeFormat(unix int) string

TimeFormat formats a Unix timestamp into a human-readable string.

func TimeMinFormat

func TimeMinFormat(unix int) string

TimeMinFormat formats a Unix timestamp into a date string (YYYY-MM-DD).

func UpsampleAndStereo

func UpsampleAndStereo(in []int16) []int16

upsampleAndStereo converts 24kHz mono PCM to 48kHz stereo PCM

func ValidateAuthorization

func ValidateAuthorization(c *gin.Context) (bool, int)

func ValidateDevice

func ValidateDevice(c *gin.Context) string

func ValidateHeader

func ValidateHeader(c *gin.Context) (bool, int)

Va

func ValidateSource

func ValidateSource(c *gin.Context) string

func Warning

func Warning(c *gin.Context, code int, data interface{})

Warning sends a warning response with a specific code and data.

Types

type EmptyData

type EmptyData struct{}

EmptyData is an empty struct used as a placeholder or for responses with no data.

type IPInfo

type IPInfo struct {
	Query      string  `json:"query"`
	Country    string  `json:"country"`
	RegionName string  `json:"regionName"`
	City       string  `json:"city"`
	Lat        float64 `json:"lat"`
	Lon        float64 `json:"lon"`
	ISP        string  `json:"isp"`
}

func GetIPLocation

func GetIPLocation(ip string) (*IPInfo, error)

type LoginClaims

type LoginClaims struct {
	UID int `json:"user_id"`
	jwt.RegisteredClaims
}

LoginClaims struct defines the structure for JWT claims used in authentication.

func ParseLoginToken

func ParseLoginToken(tokenStr string) (*LoginClaims, error)

ParseToken validates a JWT token string and returns the claims if valid.

type RealtimeClaims

type RealtimeClaims struct {
	UID       int `json:"user_id"`
	ProjectID int `json:"project_id"`
	DeviceID  int `json:"device_id"`
	jwt.RegisteredClaims
}

RealtimeClaims struct defines the structure for JWT claims used in real-time communication.

func ParseRealtimeToken

func ParseRealtimeToken(tokenStr string) (*RealtimeClaims, error)

ParseRealtimeToken validates a JWT token string for real-time communication and returns the claims if valid.

type RequestLogData

type RequestLogData struct {
	Scheme   string `json:"scheme"`
	Domain   string `json:"domain"`
	Path     string `json:"path"`
	HostName string `json:"host_name"`
	Length   string `json:"length"`
}

RequestLogData struct defines the structure for logging request details.

Source Files

  • amount.go
  • audio.go
  • client.go
  • cryption.go
  • device.go
  • email.go
  • empty.go
  • header.go
  • phone.go
  • pinyin.go
  • prompt.go
  • return.go
  • sample.go
  • time.go
  • uuid.go

Jump to

Keyboard shortcuts

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