Embed env into binary
This commit is contained in:
23
main.go
23
main.go
@@ -1,11 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
@@ -28,10 +30,25 @@ func init() {
|
|||||||
log.Lmicroseconds|log.Lshortfile)
|
log.Lmicroseconds|log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed .env
|
||||||
|
var env string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
godotenv.Load()
|
envvar, err := godotenv.Parse(strings.NewReader(env))
|
||||||
username := os.Getenv("GITEA_USER")
|
if err != nil {
|
||||||
password := os.Getenv("GITEA_PASSWORD")
|
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 == "" {
|
if username == "" || password == "" {
|
||||||
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
|
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
|
||||||
|
Reference in New Issue
Block a user