From 4022be77ae3f20fc2fa7639d93435b9674d3db36 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 13 Feb 2023 18:18:09 +0100 Subject: [PATCH] feat: use package.json to show project infos Signed-off-by: martin --- Dockerfile | 2 ++ src/init.go | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 87c63fb..96dd709 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,7 @@ RUN go get -d -v ./src/ && \ FROM alpine:3.17 COPY --from=builder /go/bin/immich-exporter /go/bin/immich-exporter +COPY package.json /go/bin/ +WORKDIR /go/bin CMD ["/go/bin/immich-exporter"] diff --git a/src/init.go b/src/init.go index 7b38288..876f682 100644 --- a/src/init.go +++ b/src/init.go @@ -1,9 +1,11 @@ package main import ( + "encoding/json" "flag" "immich-exporter/src/immich" "immich-exporter/src/models" + "io/ioutil" "log" "os" @@ -12,11 +14,11 @@ import ( ) func startup() { + projectinfo() var envfile bool flag.BoolVar(&envfile, "e", false, "Use .env file") flag.Parse() - log.Println("Loading all parameters") if envfile { useenvfile() } else { @@ -27,8 +29,27 @@ func startup() { } +func projectinfo() { + fileContent, err := os.Open("./package.json") + + if err != nil { + log.Fatal(err) + return + } + + defer fileContent.Close() + + byteResult, _ := ioutil.ReadAll(fileContent) + + var res map[string]interface{} + json.Unmarshal([]byte(byteResult), &res) + log.Println("Author :", res["author"]) + log.Println(res["name"], "version", res["version"]) +} + func useenvfile() { myEnv, err := godotenv.Read() + username := myEnv["IMMICH_USERNAME"] password := myEnv["IMMICH_PASSWORD"] immich_url := myEnv["IMMICH_BASE_URL"] @@ -50,6 +71,7 @@ func useenvfile() { } func initenv() { + username := os.Getenv("IMMICH_USERNAME") password := os.Getenv("IMMICH_PASSWORD") immich_url := os.Getenv("IMMICH_BASE_URL")