feat: use package.json to show project infos

Signed-off-by: martin <martin.labat92@gmail.com>
This commit is contained in:
martin 2023-02-13 18:18:09 +01:00
parent bf3ea6ad35
commit 4022be77ae
No known key found for this signature in database
GPG key ID: 4544CC55835A3B9E
2 changed files with 25 additions and 1 deletions

View file

@ -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"]

View file

@ -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")