-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
49 lines (39 loc) · 880 Bytes
/
server.go
File metadata and controls
49 lines (39 loc) · 880 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"github.com/go-chi/chi"
_ "github.com/mattn/go-sqlite3"
)
type Server struct {
port uint
fileMap FileMap
httpHandler HTTPHandler
router *chi.Mux
database DatabaseHandler
srcDir string
websiteDir string
}
func (p *Server) init() {
p.port = 3000
p.srcDir = "src"
p.websiteDir = "e-journal-frontend"
p.database.init(p)
p.fileMap.init(p.getWebsiteDir(), []string{".scss", ".git"})
p.router = chi.NewRouter()
p.httpHandler.init(p)
p.loadFiles()
p.run(3000)
}
func (p Server) getWebsiteDir() string {
return p.srcDir + "/" + p.websiteDir + "/"
}
func (p *Server) loadFiles() {
p.fileMap.loadFilesRecursively(p.getWebsiteDir())
}
func (p *Server) run(port int) {
fmt.Println("Started server at: ", port)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), p.router))
}