feat(config): load .env file for default cli values
This commit is contained in:
parent
32c9c22b14
commit
977c818328
3 changed files with 11 additions and 1 deletions
1
go.mod
1
go.mod
|
@ -20,6 +20,7 @@ require (
|
|||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.9.0 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -34,6 +34,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
|
|||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
|
9
main.go
9
main.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"flag"
|
||||
"github.com/anhgelus/gokord"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
|
@ -9,6 +10,8 @@ import (
|
|||
"github.com/anhgelus/les-copaings-bot/config"
|
||||
"github.com/anhgelus/les-copaings-bot/user"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/joho/godotenv"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -26,7 +29,11 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&token, "token", "", "token of the bot")
|
||||
err := godotenv.Load()
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
utils.SendWarn("Error while loading .env file", "error", err.Error())
|
||||
}
|
||||
flag.StringVar(&token, "token", os.Getenv("TOKEN"), "token of the bot")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue