init
This commit is contained in:
9
internal/core/utils/convert.go
Normal file
9
internal/core/utils/convert.go
Normal file
@ -0,0 +1,9 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Str2StrSlice(value string) []string {
|
||||
return strings.Split(strings.ReplaceAll(value, " ", ""), ",")
|
||||
}
|
15
internal/core/utils/os.go
Normal file
15
internal/core/utils/os.go
Normal file
@ -0,0 +1,15 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
func ExitErr() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func GetEnvOrDefault(key, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
26
internal/core/utils/password.go
Normal file
26
internal/core/utils/password.go
Normal file
@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// HashPassword hashes password and returns hashed password or error
|
||||
func HashPassword(password string) (string, error) {
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword(
|
||||
[]byte(password),
|
||||
bcrypt.DefaultCost,
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(hashedPassword), nil
|
||||
}
|
||||
|
||||
// ComparePassword compares password with hashed password and returns error if they don't match or nil if they do
|
||||
func ComparePassword(password, hashedPassword string) error {
|
||||
return bcrypt.CompareHashAndPassword(
|
||||
[]byte(hashedPassword),
|
||||
[]byte(password),
|
||||
)
|
||||
}
|
7
internal/core/utils/time.go
Normal file
7
internal/core/utils/time.go
Normal file
@ -0,0 +1,7 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
func GetNow() time.Time {
|
||||
return time.Now()
|
||||
}
|
Reference in New Issue
Block a user