utils/utils.go
package utils
import (
"crypto/rand"
"encoding/hex"
"os"
)
func GetAppName() string {
appName := os.Getenv("OTEL_SERVICE_NAME")
if appName == "" {
appName = os.Getenv("APP_NAME")
if appName == "" {
appName = "go-hello-world"
}
}
return appName
}
func GenerateKey() (string, error) {
bytes := make([]byte, 32) //generate a random 32 byte key for AES-256
if _, err := rand.Read(bytes); err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil //encode key in bytes to string for saving
}