-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (46 loc) · 1.23 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/justyntemme/gobolt/dom"
"github.com/justyntemme/gobolt/server"
"github.com/sirupsen/logrus"
)
func main() {
logger := &logrus.Logger{
Out: os.Stdout,
Formatter: &logrus.TextFormatter{FullTimestamp: true},
Level: logrus.DebugLevel,
}
domInstance := dom.NewDOM()
srv, err := server.NewServer(domInstance)
if err != nil {
log.Fatal(err.Error())
}
// Load the Markdown content into the DOM (pass in the base directory)
err = domInstance.LoadMarkdown(srv.BaseDir)
if err != nil {
log.Fatalf("Error loading markdown content: %v", err)
}
err = dom.LoadCSS(srv.BaseDir + "/styles.css")
if err != nil {
logger.Fatalf("Unable to load css: error: %s", err)
}
go func() {
if err := srv.Start(); err != nil && err != http.ErrServerClosed {
fmt.Printf("Error starting server: %v\n", err)
}
}()
// Wait for interrupt signal to gracefully shut down the server
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit // Block until a signal is received
logger.Info("\nShutting down server...")
if err := srv.Shutdown(); err != nil {
logger.Infof("Error during shutdown: %v\n", err)
}
}