-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (40 loc) · 1.19 KB
/
main.go
File metadata and controls
50 lines (40 loc) · 1.19 KB
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/915604903T/ModelController/handlers"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/gorilla/mux"
)
const NameExpression = "-a-zA-Z_0-9."
func main() {
router := mux.NewRouter()
router.HandleFunc("/render/scene/{name}", handlers.MakeReceiveFileHandler())
router.HandleFunc("/relocalise/info", handlers.MakeReceiveRelocInfoHandler())
router.HandleFunc("/relocalise/scene/{name}", handlers.MakeSendSceneModelHandler())
// start server but not block
go handlers.DealSignal()
// start send resource info to center server
go handlers.SendResourceInfo()
// close nvml and two channel
defer func() {
ret := nvml.Shutdown()
if ret != nvml.SUCCESS {
log.Fatalf("Unable to shutdown NVML: %v", nvml.ErrorString(ret))
}
}()
defer close(handlers.RenderFinish)
defer close(handlers.RelocaliseFinish)
// regard tcp port as env viarable
tcpPort := os.Getenv("PORT")
// tcpPort, _ := strconv.Atoi(os.Getenv("PORT"))
handlers.HostAddr = "http://127.0.0.1" + ":" + tcpPort
s := &http.Server{
Addr: fmt.Sprintf(":%s", tcpPort),
Handler: router,
}
log.Println("listen on port: ", tcpPort)
log.Fatal(s.ListenAndServe())
}