feat: added wallet service
This commit is contained in:
48
server/utils/general.go
Normal file
48
server/utils/general.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Generates a random integer in the range (min, max)
|
||||
func RandInt(min, max int) int {
|
||||
n, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min)))
|
||||
return int(n.Int64()) + min
|
||||
}
|
||||
|
||||
// Get the current time in milliseconds
|
||||
func GetCurrentTimeMillis() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond) // Convert nanoseconds to milliseconds
|
||||
}
|
||||
|
||||
// IsAlpha checks if the string contains only alphabetic characters
|
||||
func IsAlpha(s string) bool {
|
||||
for _, r := range s {
|
||||
if !('a' <= r && r <= 'z') && !('A' <= r && r <= 'Z') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsDigit checks if the string contains only digits
|
||||
func IsDigit(s string) bool {
|
||||
for _, r := range s {
|
||||
if !(r >= '0' && r <= '9') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsHex checks if the string is a valid hexadecimal representation
|
||||
func IsHex(s string) bool {
|
||||
for _, r := range s {
|
||||
if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user