-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (29 loc) · 689 Bytes
/
main.go
File metadata and controls
38 lines (29 loc) · 689 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
package main
import (
"io/fs"
"log"
"net/http"
"time"
"embed"
"github.com/ikeohachidi/view-github-static/cmd"
)
//go:embed "web"
var web embed.FS
func main() {
router := http.NewServeMux()
fSys, err := fs.Sub(web, "web")
if err != nil {
log.Fatalf("unable to read embed files: %v", err)
}
router.Handle("GET /", http.FileServer(http.FS(fSys)))
router.HandleFunc("POST /open", cmd.Open)
router.HandleFunc("GET /{username}/{repo}/*", cmd.Navigate)
server := http.Server{
Addr: ":8000",
Handler: router,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
}
log.Print("Listening on port 8000")
log.Fatal(server.ListenAndServe())
}