Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Commit 49c2f4d

Browse files
committed
set env from dotenv before run the server
1 parent aadc4d3 commit 49c2f4d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

cmd/typical-rest-server/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
"time"
57

68
"github.com/sirupsen/logrus"
9+
"github.com/typical-go/typical-go/pkg/envkit"
710
"github.com/typical-go/typical-go/pkg/typapp"
811
"github.com/typical-go/typical-go/pkg/typgo"
912
"github.com/typical-go/typical-rest-server/internal/app"
1013

14+
// Important to enable dependency injectino
1115
_ "github.com/typical-go/typical-rest-server/internal/generated/ctor"
1216
_ "github.com/typical-go/typical-rest-server/internal/generated/envcfg"
1317
)
1418

1519
func main() {
16-
fmt.Printf("%s %s\n", typgo.ProjectName, typgo.ProjectVersion)
20+
// Print application header
21+
fmt.Printf("Start %s (%s) at %s\n",
22+
typgo.ProjectName, typgo.ProjectVersion, time.Now().Format(time.RFC3339))
23+
24+
// Read dotenv file
25+
if dotenv := os.Getenv("CONFIG"); dotenv != "" {
26+
fmt.Printf("Set ENV from '%s'", dotenv)
27+
m, _ := envkit.ReadFile(dotenv)
28+
envkit.Setenv(m)
29+
}
30+
1731
if err := typapp.StartApp(app.Start, app.Shutdown); err != nil {
1832
logrus.Fatal(err.Error())
1933
}

0 commit comments

Comments
 (0)