Add config dir env variable
This commit is contained in:
parent
3b9d08ebbd
commit
96bffc8fb0
|
@ -14,6 +14,7 @@ EXPOSE 8080
|
|||
|
||||
ENV YTDL_HTTP_PORT=8080 \
|
||||
YTDL_HTTP_LISTEN=0.0.0.0 \
|
||||
YTDL_BINARYPATH=/usr/bin/yt-dlp
|
||||
YTDL_BINARYPATH=/usr/bin/yt-dlp \
|
||||
YTDL_CONFIGDIR=/config
|
||||
|
||||
ENTRYPOINT [ "./ytdl-web" ]
|
|
@ -23,6 +23,7 @@ You can configure the application using environment variables
|
|||
|
||||
| Variable Name | Description | Default Value | Accepted Values |
|
||||
| ---------------------------------- | ----------------------------------------------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------ |
|
||||
| YTDL_CONFIGDIR | Add a custom config directory to search for the config file | ` ` | |
|
||||
| YTDL_ENV | The application environment | `Production` | `Development`, `Staging`, `Production` |
|
||||
| YTDL_BINARYPATH | The path to the yt-dlp binary | `yt-dlp` | |
|
||||
| YTDL_HTTP_PORT | The tcp port for the web server to listen on | `8080` | |
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -88,10 +90,22 @@ func LoadConfig(paths ...string) (*Config, error) {
|
|||
v.AddConfigPath(path)
|
||||
}
|
||||
} else {
|
||||
envDir := os.Getenv("YTDL_CONFIGDIR")
|
||||
if envDir != "" {
|
||||
v.AddConfigPath(envDir)
|
||||
}
|
||||
|
||||
v.AddConfigPath(".")
|
||||
v.AddConfigPath("/etc/ytdl-web")
|
||||
v.AddConfigPath("$HOME/.config/ytdl-web")
|
||||
v.AddConfigPath("$XDG_CONFIG_HOME/ytdl-web")
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
v.AddConfigPath(homeDir + "/.config/ytdl-web")
|
||||
}
|
||||
|
||||
v.AddConfigPath(xdg.ConfigHome + "/ytdl-web")
|
||||
for _, dir := range xdg.ConfigDirs {
|
||||
v.AddConfigPath(dir + "/ytdl-web")
|
||||
}
|
||||
}
|
||||
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module go.fifitido.net/ytdl-web
|
|||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/adrg/xdg v0.4.0
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4
|
||||
github.com/gofiber/fiber/v2 v2.44.0
|
||||
github.com/gofiber/template v1.8.0
|
||||
|
|
3
go.sum
3
go.sum
|
@ -55,6 +55,8 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
|
|||
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
|
||||
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
|
||||
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
|
@ -657,6 +659,7 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
Loading…
Reference in New Issue