-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c37f1ab
commit 3a90441
Showing
7 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cryptox | ||
|
||
func SHA256Str(s string) string { | ||
return SHA256([]byte(s)) | ||
} | ||
|
||
func SHA512Str(s string) string { | ||
return SHA512([]byte(s)) | ||
} | ||
|
||
func SHA384Str(s string) string { | ||
return SHA384([]byte(s)) | ||
} | ||
|
||
func SHA512_224Str(s string) string { | ||
return SHA512_224([]byte(s)) | ||
} | ||
|
||
func SHA512_256Str(s string) string { | ||
return SHA512_256([]byte(s)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package mapx | ||
|
||
import "strconv" | ||
|
||
func GetString(m map[string]any, key string, ifFailed string) string { | ||
if v, ok := m[key]; ok { | ||
if str, ok := v.(string); ok { | ||
return str | ||
} | ||
return ifFailed | ||
} | ||
return ifFailed | ||
} | ||
|
||
func GetBool(m map[string]any, key string, ifFailed bool) bool { | ||
if v, ok := m[key]; ok { | ||
switch v.(type) { | ||
case bool: | ||
return v.(bool) | ||
case string: | ||
if v.(string) == "true" { | ||
return true | ||
} | ||
return false | ||
default: | ||
return ifFailed | ||
} | ||
} | ||
return ifFailed | ||
} | ||
|
||
func GetInt(m map[string]any, key string, ifFailed int) int { | ||
if v, ok := m[key]; ok { | ||
switch v.(type) { | ||
case int: | ||
return v.(int) | ||
case string: | ||
if i, err := strconv.Atoi(v.(string)); err == nil { | ||
return i | ||
} | ||
return ifFailed | ||
default: | ||
return ifFailed | ||
} | ||
} | ||
return ifFailed | ||
} | ||
|
||
func GetInt64(m map[string]any, key string, ifFailed int64) int64 { | ||
if v, ok := m[key]; ok { | ||
switch v.(type) { | ||
case int64: | ||
return v.(int64) | ||
case string: | ||
if i, err := strconv.ParseInt(v.(string), 10, 64); err == nil { | ||
return i | ||
} | ||
return ifFailed | ||
default: | ||
return ifFailed | ||
} | ||
} | ||
return ifFailed | ||
} | ||
|
||
func GetFloat64(m map[string]any, key string, ifFailed float64) float64 { | ||
if v, ok := m[key]; ok { | ||
switch v.(type) { | ||
case float64: | ||
return v.(float64) | ||
case string: | ||
if i, err := strconv.ParseFloat(v.(string), 64); err == nil { | ||
return i | ||
} | ||
return ifFailed | ||
default: | ||
return ifFailed | ||
} | ||
} | ||
return ifFailed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package x | ||
|
||
func Assert[T any](in any, ifFailed T) T { | ||
v, ok := in.(T) | ||
if !ok { | ||
return ifFailed | ||
} | ||
return v | ||
} | ||
|
||
func AssertPanic[T any](in any) T { | ||
v, ok := in.(T) | ||
if !ok { | ||
panic("assertion failed") | ||
} | ||
return v | ||
} | ||
|
||
func AssertAsInt(in any, ifFailed int) int { | ||
switch in.(type) { | ||
case int: | ||
return in.(int) | ||
case int8: | ||
return int(in.(int8)) | ||
case int16: | ||
return int(in.(int16)) | ||
case int32: | ||
return int(in.(int32)) | ||
case int64: | ||
return int(in.(int64)) | ||
case uint: | ||
return int(in.(uint)) | ||
case uint8: | ||
return int(in.(uint8)) | ||
case uint16: | ||
return int(in.(uint16)) | ||
case uint32: | ||
return int(in.(uint32)) | ||
case uint64: | ||
return int(in.(uint64)) | ||
case float32: | ||
return int(in.(float32)) | ||
case float64: | ||
return int(in.(float64)) | ||
} | ||
return ifFailed | ||
} | ||
|
||
func AssertAsFloat(in any, ifFailed float64) float64 { | ||
switch in.(type) { | ||
case int: | ||
return float64(in.(int)) | ||
case int8: | ||
return float64(in.(int8)) | ||
case int16: | ||
return float64(in.(int16)) | ||
case int32: | ||
return float64(in.(int32)) | ||
case int64: | ||
return float64(in.(int64)) | ||
case uint: | ||
return float64(in.(uint)) | ||
case uint8: | ||
return float64(in.(uint8)) | ||
case uint16: | ||
return float64(in.(uint16)) | ||
case uint32: | ||
return float64(in.(uint32)) | ||
case uint64: | ||
return float64(in.(uint64)) | ||
case float32: | ||
return float64(in.(float32)) | ||
case float64: | ||
return in.(float64) | ||
} | ||
return ifFailed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package x | ||
|
||
func NotNil(a ...any) bool { | ||
for _, v := range a { | ||
if v == nil { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func PanicIfNil(a ...any) { | ||
for _, v := range a { | ||
if v == nil { | ||
panic("nil") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package x | ||
|
||
func Ite[T any](conExpr bool, ifTrue, ifFalse T) T { | ||
if conExpr { | ||
return ifTrue | ||
} | ||
return ifFalse | ||
} | ||
|
||
func IteFunc[T any](conExpr bool, ifTrue, ifFalse func() T) T { | ||
if conExpr { | ||
return ifTrue() | ||
} | ||
return ifFalse() | ||
} | ||
|
||
func IteFuncTrue[T any](conExpr bool, ifTrue func() T, ifFalse T) T { | ||
if conExpr { | ||
return ifTrue() | ||
} | ||
return ifFalse | ||
} | ||
|
||
func IteFuncElse[T any](conExpr bool, ifTrue T, ifFalse func() T) T { | ||
if conExpr { | ||
return ifTrue | ||
} | ||
return ifFalse() | ||
} |