wasilak/go-hello-world

View on GitHub
utils/utils.go

Summary

Maintainability
A
0 mins
Test Coverage
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

}