-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (32 loc) · 762 Bytes
/
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
package main
import (
"io/fs"
"net/http"
"os"
"go-file-cache-server.example.com/controllers"
"go-file-cache-server.example.com/db"
)
func main() {
db.InitializeDB()
os.Mkdir(controllers.DOWNLOADS_FILE_DIR, fs.ModeDevice)
os.Chmod(controllers.DOWNLOADS_FILE_DIR, os.ModePerm)
s := NewServer()
http.ListenAndServe(s.addr, s)
}
func (s server) ServeHTTP(w http.ResponseWriter, request *http.Request) {
requestURI := request.URL.Path
for _, route := range routes {
matches := route.regex.FindStringSubmatch(requestURI)
if len(matches) > 0 && route.method == request.Method {
route.handler(w, request)
return
}
}
http.NotFound(w, request)
}
type server struct {
addr string
}
func NewServer() server {
return server{addr: ":8080"}
}