diff --git a/.env_copy b/.env_copy new file mode 100644 index 0000000..8ef3a90 --- /dev/null +++ b/.env_copy @@ -0,0 +1 @@ +ARTICLE_PATH=./article \ No newline at end of file diff --git a/.gitignore b/.gitignore index e69de29..2eea525 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/go.mod b/go.mod index 3265054..9472d2c 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.11.2 // indirect github.com/goccy/go-json v0.10.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect diff --git a/go.sum b/go.sum index 93decc6..e47e9d0 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= diff --git a/handler/article.go b/handler/article.go index f117e4b..6b529f8 100644 --- a/handler/article.go +++ b/handler/article.go @@ -16,7 +16,7 @@ func Article(c *gin.Context) { id = strings.Replace(id, "-", "/", -1) - articleBasePath := "./article" + articleBasePath := os.Getenv("ARTICLE_PATH") articlePath := articleBasePath + "/" + id + ".md" diff --git a/handler/index.go b/handler/index.go index 765db39..d4e208d 100644 --- a/handler/index.go +++ b/handler/index.go @@ -10,7 +10,7 @@ import ( func Index(c *gin.Context) { - articleBasePath := "./article" + articleBasePath := os.Getenv("ARTICLE_PATH") list := make([]string, 0) diff --git a/main.go b/main.go index c694aa3..5d187fc 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,21 @@ package main import ( "flag" + "log" + "os" "strconv" + + "github.com/joho/godotenv" ) func main() { + + err := godotenv.Load(".env") + if err != nil { + log.Fatal("Error loading .env file") + os.Exit(1) + } + r := Router() r.LoadHTMLGlob("tmpl/*") r.Static("/statics", "./statics")