generated from AOrps/readme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.go
39 lines (29 loc) · 795 Bytes
/
serve.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
package main
import (
"fmt"
"net/http"
"strconv"
lib "github.com/AOrps/neurod-task-spin/lib"
)
const (
templatePath = lib.TEMPLATEPATH
)
// (Global) port: initial port to serve content on
// - should this fail, it will increment value
var port = 7100
func main() {
// Assets at assets/
fs := http.FileServer(http.Dir("assets/"))
http.Handle("/assets/", http.StripPrefix("/assets/", fs))
// Is the area where the routes are setup
lib.SetupRoutes()
// checks if port is available and valid
for (lib.CheckPort(port) == false) && (port < 65536) {
port++
}
// converts port number to string (so ListenAndServe)
// can use it post conversion
servePort := strconv.Itoa(port)
fmt.Printf("server: http://127.0.0.1:%s\n", servePort)
http.ListenAndServe(":"+servePort,nil)
}