init
This commit is contained in:
44
internal/adapter/config/helper.go
Normal file
44
internal/adapter/config/helper.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/aykhans/oh-my-chat/internal/adapter/logger"
|
||||
"github.com/aykhans/oh-my-chat/internal/core/utils"
|
||||
)
|
||||
|
||||
var log = logger.NewStdLogger()
|
||||
|
||||
func GetEnvOrDie(key string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
log.Error(
|
||||
"Error get environment variable",
|
||||
"error",
|
||||
fmt.Errorf("Environment variable "+key+" is not set"),
|
||||
)
|
||||
utils.ExitErr()
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func Str2IntOrDie(value string) int {
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
log.Error("Error convert string to int", "error", err)
|
||||
utils.ExitErr()
|
||||
}
|
||||
return intValue
|
||||
}
|
||||
|
||||
func Str2DurationOrDie(value string) *time.Duration {
|
||||
duration, err := time.ParseDuration(value)
|
||||
if err != nil {
|
||||
log.Error("Error convert string to duration", "error", err)
|
||||
utils.ExitErr()
|
||||
}
|
||||
return &duration
|
||||
}
|
||||
Reference in New Issue
Block a user