only load .env file when not in prod
This commit is contained in:
parent
48e6a851fa
commit
0f95094014
1 changed files with 23 additions and 21 deletions
44
cmd/main.go
44
cmd/main.go
|
|
@ -10,39 +10,41 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
||||
"github.com/juancwu/potoforio/pkg/pages"
|
||||
"github.com/juancwu/potoforio/pkg/pages"
|
||||
)
|
||||
|
||||
type TemplateRenderer struct {
|
||||
templates *template.Template
|
||||
templates *template.Template
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Load connection string from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("failed to load env", err)
|
||||
}
|
||||
// Load connection string from .env file
|
||||
if os.Getenv("GO_ENV") != "production" {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("failed to load env", err)
|
||||
}
|
||||
}
|
||||
|
||||
templates, err := template.New("").ParseGlob("public/views/*.html")
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing templates: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
templates, err := template.New("").ParseGlob("public/views/*.html")
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing templates: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
e.Renderer = &TemplateRenderer{
|
||||
templates: templates,
|
||||
}
|
||||
e := echo.New()
|
||||
e.Renderer = &TemplateRenderer{
|
||||
templates: templates,
|
||||
}
|
||||
|
||||
e.Use(middleware.Logger())
|
||||
e.Static("/static", "static")
|
||||
e.Use(middleware.Logger())
|
||||
e.Static("/static", "static")
|
||||
|
||||
e.GET("/", pages.Index)
|
||||
e.GET("/", pages.Index)
|
||||
|
||||
e.Logger.Fatal(e.Start(":5173"))
|
||||
e.Logger.Fatal(e.Start(":5173"))
|
||||
}
|
||||
|
||||
func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
return t.templates.ExecuteTemplate(w, name, data)
|
||||
return t.templates.ExecuteTemplate(w, name, data)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue