-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (43 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"net/http"
"os"
"github.com/fahimanzamdip/go-invoice-api/router"
"github.com/joho/godotenv"
)
func init() {
log.Println("<========= Go-Invoice-Api Starting =========>")
if err := godotenv.Load(); err != nil {
log.Println("File .env not found, reading configuration from ENV")
return
}
log.Println("Reading .env file successful || Alhamdulillaah")
directoryPaths := []string{"./public/uploads", "./public/pdfs"}
for _, directoryPath := range directoryPaths {
_, err := os.Stat(directoryPath)
if os.IsNotExist(err) {
err = os.MkdirAll(directoryPath, os.ModePerm)
if err != nil {
log.Println("Error creating directory:", err)
return
}
log.Println("Directory created:", directoryPath)
} else if err != nil {
log.Println("Error checking directory:", err)
return
} else {
log.Println("Directory exists:", directoryPath)
}
}
}
func main() {
r := router.Configure()
port := os.Getenv("server_port")
if port == "" {
port = "8000"
}
log.Println("API URL: http://localhost/" + os.Getenv("api_uri"))
log.Println("<===========================================>")
log.Fatal(http.ListenAndServe(":"+port, r))
}