From 46b4090629683f34e8aa98a112ace6f4605711ba Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 2 Nov 2024 03:36:55 +0800 Subject: [PATCH] moved env to .env.example, update setup method --- .env.example | 22 ++++++++++++++++++++++ compose.example.yml | 16 ++-------------- internal/common/constants.go | 3 ++- internal/setup.go | 7 ++++--- 4 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..107435e5 --- /dev/null +++ b/.env.example @@ -0,0 +1,22 @@ +# set timezone to get correct log timestamp +TZ=ETC/UTC + +# generate secret with `openssl rand -base64 32` +GOPROXY_API_JWT_SECRET= + +# the JWT token time-to-live +GOPROXY_API_JWT_TOKEN_TTL=1h + +# API/WebUI login credentials +GOPROXY_API_USER=admin +GOPROXY_API_PASSWORD=password + +# Proxy listening address +GOPROXY_HTTP_ADDR=:80 +GOPROXY_HTTPS_ADDR=:443 + +# API listening address +GOPROXY_API_ADDR=127.0.0.1:8888 + +# Debug mode +GOPROXY_DEBUG=false diff --git a/compose.example.yml b/compose.example.yml index ebb865d3..82b79f35 100755 --- a/compose.example.yml +++ b/compose.example.yml @@ -4,31 +4,19 @@ services: container_name: go-proxy-frontend restart: unless-stopped network_mode: host + env_file: .env depends_on: - app # if you also want to proxy the WebUI and access it via gp.y.z # labels: # - proxy.aliases=gp # - proxy.gp.port=3000 - - # Make sure the value is same as `GOPROXY_API_ADDR` below (if you have changed it) - # - # environment: - # GOPROXY_API_ADDR: 127.0.0.1:8888 app: image: ghcr.io/yusing/go-proxy:latest container_name: go-proxy restart: always network_mode: host - environment: - # (Optional) change this to your timezone to get correct log timestamp - TZ: ETC/UTC - - # Change these if you need - # - # GOPROXY_HTTP_ADDR: :80 - # GOPROXY_HTTPS_ADDR: :443 - # GOPROXY_API_ADDR: 127.0.0.1:8888 + env_file: .env volumes: - /var/run/docker.sock:/var/run/docker.sock - ./config:/app/config diff --git a/internal/common/constants.go b/internal/common/constants.go index 0a2c2bb8..c637a177 100644 --- a/internal/common/constants.go +++ b/internal/common/constants.go @@ -13,7 +13,8 @@ const ( // file, folder structure const ( - DotEnvPath = ".env" + DotEnvPath = ".env" + DotEnvExamplePath = ".env.example" ConfigBasePath = "config" ConfigFileName = "config.yml" diff --git a/internal/setup.go b/internal/setup.go index 6b5fb824..708323b5 100644 --- a/internal/setup.go +++ b/internal/setup.go @@ -16,6 +16,7 @@ var ( baseURL = "https://github.com/yusing/go-proxy/raw/" + branch requiredConfigs = []Config{ {common.ConfigBasePath, true, false, ""}, + {common.DotEnvPath, false, true, common.DotEnvExamplePath}, {common.ComposeFileName, false, true, common.ComposeExampleFileName}, {path.Join(common.ConfigBasePath, common.ConfigFileName), false, true, common.ConfigExampleFileName}, } @@ -40,7 +41,7 @@ func Setup() { config.setup() } - log.Println("done") + log.Println("setup finished") } func (c *Config) setup() { @@ -96,7 +97,7 @@ func fetch(remoteFilename string, outFileName string) { log.Printf("%q already exists, downloading to %q\n", outFileName, remoteFilename) outFileName = remoteFilename } - log.Printf("downloading %q\n", remoteFilename) + log.Printf("downloading %q to %q\n", remoteFilename, outFileName) url, err := url.JoinPath(baseURL, remoteFilename) if err != nil { @@ -120,7 +121,7 @@ func fetch(remoteFilename string, outFileName string) { log.Fatalf("failed to write to file: %s\n", err) } - log.Printf("downloaded to %q\n", outFileName) + log.Print("done") resp.Body.Close() }