-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
executable file
·53 lines (42 loc) · 1.1 KB
/
server.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
/*
#cgo LDFLAGS: -lassimp -L/usr/local/lib/libassimp.so
#include <stdio.h>
#include <stdlib.h>
#include <assimp/cimport.h> // Plain-C interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
*/
import "C"
import "net/http"
import "os"
import "fmt"
import "encoding/json"
import "./libs/assimp-go/conv"
func handler(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
gScene, err := conv.LoadAsset("assets/models/" + values.Get("name"))
if err != nil {
fmt.Println("error:", err)
}
b, err := json.Marshal(gScene)
if err != nil {
fmt.Println("error:", err)
}
w.Write(b)
}
var hFile http.Handler
func fileHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache")
hFile.ServeHTTP(w, r)
}
func main() {
path, err := os.Getwd()
if err != nil {
fmt.Println(err)
}
hFile = http.FileServer(http.Dir(path))
http.HandleFunc("/", fileHandler)
http.HandleFunc("/engine/model", handler)
panic(http.ListenAndServe(":8080", nil))
}