fix env
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6a7a1bf3d2
commit
ab57c7fa41
|
@ -7,16 +7,16 @@ steps:
|
|||
pull: if-not-exists
|
||||
image: golang:1.23
|
||||
environment:
|
||||
TELEGRAM_TOKEN:
|
||||
BOT_TOKEN:
|
||||
from_secret: bot_token
|
||||
POSTGRES_URL_CONNECT:
|
||||
from_secret: postgres_url_connect
|
||||
settings:
|
||||
envs: [ TELEGRAM_TOKEN,POSTGRES_URL_CONNECT ]
|
||||
envs: [ BOT_TOKEN,POSTGRES_URL_CONNECT ]
|
||||
commands:
|
||||
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o smm_tg cmd/smm_tg/main.go
|
||||
- touch .env
|
||||
- echo TELEGRAM_TOKEN=$${TELEGRAM_TOKEN} >> .env
|
||||
- echo BOT_TOKEN=$${TELEGRAM_TOKEN} >> .env
|
||||
- echo POSTGRES_URL_CONNECT=$${POSTGRES_URL_CONNECT} >> .env
|
||||
|
||||
- name: test
|
||||
|
|
|
@ -2,7 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.3crabs.ru/save_my_money/smm_tg/internal/modules/messenger/telegram"
|
||||
"git.3crabs.ru/save_my_money/smm_tg/internal/services/bot"
|
||||
|
@ -15,7 +17,7 @@ func main() {
|
|||
// try get sysenv
|
||||
telegarmToken := os.Getenv("BOT_TOKEN")
|
||||
if len(telegarmToken) == 0 {
|
||||
if err := godotenv.Load("../../.env"); err != nil {
|
||||
if err := godotenv.Load(dir(".env")); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
telegarmToken = os.Getenv("BOT_TOKEN")
|
||||
|
@ -38,3 +40,25 @@ func main() {
|
|||
ctx := context.Background()
|
||||
listenerService.Run(ctx)
|
||||
}
|
||||
|
||||
func dir(envFile string) string {
|
||||
currentDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for {
|
||||
goModPath := filepath.Join(currentDir, "go.mod")
|
||||
if _, err := os.Stat(goModPath); err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
parent := filepath.Dir(currentDir)
|
||||
if parent == currentDir {
|
||||
panic(fmt.Errorf("go.mod not found"))
|
||||
}
|
||||
currentDir = parent
|
||||
}
|
||||
|
||||
return filepath.Join(currentDir, envFile)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue