-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
67 lines (57 loc) · 1.47 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
"github.com/joho/godotenv"
)
var (
port int
local bool
)
func init() {
flag.IntVar(&port, "port", 9003, "web service port")
flag.BoolVar(&local, "local", true, "run web service locally")
flag.Parse()
}
func main() {
if local {
err := godotenv.Load()
if err != nil {
log.Panicln(err)
}
}
// Initialize standard Go html template engine
engine := html.New("./views", ".html")
app := fiber.New(fiber.Config{
Views: engine,
})
// Create a data structure to store project-related information
projectInfo := struct {
ProjectName string
ProjectNameExplanation string
Description string
GithubLink string
ImageURL string
// You can add other project-related information here
}{
ProjectName: os.Getenv("PROJECT_NAME"),
ProjectNameExplanation: os.Getenv("PROJECT_NAME_EXPLANATION"),
Description: os.Getenv("DESCRIPTION"),
GithubLink: os.Getenv("GITHUB_LINK"),
ImageURL: os.Getenv("IMAGE_URL"),
}
app.Get("/", func(c *fiber.Ctx) error {
// Render index template
return c.Render("index", projectInfo)
})
// Serve a PDF file at /pdf
app.Get("/api-doc", func(c *fiber.Ctx) error {
return c.SendFile("./pdf/api-documentation.pdf")
})
log.Printf("Web service running on [::]:%d\n", port)
log.Fatal(app.Listen(fmt.Sprintf(":%d", port)))
}