Embed env into binary

This commit is contained in:
2024-07-20 18:58:11 +02:00
parent 9255ff6790
commit 291994cb7a

23
main.go
View File

@@ -1,11 +1,13 @@
package main
import (
_ "embed"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
"code.gitea.io/sdk/gitea"
"github.com/joho/godotenv"
@@ -28,10 +30,25 @@ func init() {
log.Lmicroseconds|log.Lshortfile)
}
//go:embed .env
var env string
func main() {
godotenv.Load()
username := os.Getenv("GITEA_USER")
password := os.Getenv("GITEA_PASSWORD")
envvar, err := godotenv.Parse(strings.NewReader(env))
if err != nil {
Error.Fatalf("Error parsing .env file: %v", err)
os.Exit(1)
}
username, ok := envvar["GITEA_USER"]
if !ok {
Error.Fatalf("GITEA_USER environment variable is required")
os.Exit(1)
}
password, ok := envvar["GITEA_PASSWORD"]
if !ok {
Error.Fatalf("GITEA_PASSWORD environment variable is required")
os.Exit(1)
}
if username == "" || password == "" {
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")