Skip to content

Commit

Permalink
added ParseUInt64 and renamed ParseSnowflake to ParseInt64
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jan 24, 2022
1 parent ad7f328 commit 164417b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ id.Int64()
id = NewSnowflake(time.Now())

// returns the int64 as a Snowflake
id = ParseSnowflake(123456789012345678)
id = ParseInt64(123456789012345678)

// returns the uint64 as a Snowflake
id = ParseUInt64(123456789012345678)

// returns a snowflake from an environment variable
id = GetSnowflakeEnv("guild_id")
Expand Down
13 changes: 8 additions & 5 deletions snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ func NewSnowflake(timestamp time.Time) Snowflake {
return Snowflake(strconv.FormatInt(((timestamp.UnixNano()/1_000_000)-Epoch)<<22, 10))
}

// ParseSnowflake parses a Snowflake int64 into a Snowflake
// ParseInt64 parses an int64 into a Snowflake
//goland:noinspection GoUnusedExportedFunction
func ParseSnowflake(i int64) Snowflake {
if i == 0 {
return ""
}
func ParseInt64(i int64) Snowflake {
return Snowflake(strconv.FormatInt(i, 10))
}

// ParseUInt64 parses an uint64 into a Snowflake
//goland:noinspection GoUnusedExportedFunction
func ParseUInt64(i uint64) Snowflake {
return Snowflake(strconv.FormatUint(i, 10))
}

// GetSnowflakeEnv returns a new Snowflake from an environment variable
//goland:noinspection GoUnusedExportedFunction
func GetSnowflakeEnv(key string) Snowflake {
Expand Down

0 comments on commit 164417b

Please sign in to comment.