mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add environment variable support
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
# Use Alpine as the base image
|
||||
FROM golang:alpine
|
||||
|
||||
# Install isotope
|
||||
FROM ugric/isotope:latest
|
||||
|
||||
# Set the Current Working Directory inside the container
|
||||
WORKDIR /app
|
||||
WORKDIR /argon
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
@@ -11,7 +14,7 @@ COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source from the current directory to the Working Directory inside the container
|
||||
COPY . .
|
||||
COPY ./src ./src
|
||||
|
||||
# Build the Go app
|
||||
RUN go build -trimpath -ldflags="-s -w" -o bin/argon ./src
|
||||
@@ -20,4 +23,4 @@ RUN go build -trimpath -ldflags="-s -w" -o bin/argon ./src
|
||||
RUN chmod +x bin/argon
|
||||
|
||||
# add the binary to the path
|
||||
ENV PATH="/app/bin:${PATH}"
|
||||
ENV PATH="/argon/bin:${PATH}"
|
||||
2
go.mod
2
go.mod
@@ -7,6 +7,8 @@ require (
|
||||
github.com/wadey/go-rounding v1.1.0
|
||||
)
|
||||
|
||||
require github.com/joho/godotenv v1.5.1 // indirect
|
||||
|
||||
require (
|
||||
github.com/gabriel-vasile/mimetype v1.4.2
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -2,6 +2,8 @@ github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
||||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
|
||||
github.com/jwalton/go-supportscolor v1.1.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
func makeGlobal() ArObject {
|
||||
var vars = anymap{}
|
||||
vars["global"] = vars
|
||||
vars["env"] = env
|
||||
vars["term"] = ArTerm
|
||||
vars["ArgonVersion"] = ArString(VERSION)
|
||||
vars["number"] = builtinFunc{"number", ArgonNumber}
|
||||
|
||||
34
src/env.go
Normal file
34
src/env.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// get the environment variables
|
||||
func getEnv() ArObject {
|
||||
env := make(anymap)
|
||||
for _, e := range os.Environ() {
|
||||
pair := strings.Split(e, "=")
|
||||
env[pair[0]] = ArString(pair[1])
|
||||
}
|
||||
cwd, err := os.Getwd()
|
||||
if err == nil {
|
||||
envfile := filepath.Join(cwd, ".env")
|
||||
err := godotenv.Load(envfile)
|
||||
if err == nil {
|
||||
values, err := godotenv.Read()
|
||||
if err == nil {
|
||||
for k, v := range values {
|
||||
env[k] = ArString(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Map(env)
|
||||
}
|
||||
|
||||
var env = getEnv()
|
||||
Reference in New Issue
Block a user