-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (42 loc) · 1.16 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Zaradb lite faset document database
package main
import (
"embed"
"fmt"
"net/http"
"zaradb/engine"
)
//go:embed static
var content embed.FS
func main() {
// TODO close programe greatfully.
db := engine.NewDB("test.db")
db.CreateCollection("test")
defer db.Close()
fmt.Printf("zaradb run on %s:%s\n", Host, Port)
http.Handle("/static/", http.FileServer(http.FS(content)))
http.HandleFunc("/shell", shell)
http.HandleFunc("/", index)
// standard endpoint
http.HandleFunc("/ws", engine.Ws)
// endpoints for speed network
http.HandleFunc("/query", engine.Resever)
http.HandleFunc("/result", engine.Sender)
http.ListenAndServe(":1111", nil)
}
// redirect to shell page temporary
func index(w http.ResponseWriter, r *http.Request) {
// TODO create index page
http.Redirect(w, r, "http://localhost:1111/shell", http.StatusSeeOther)
}
// render static shell.html file
func shell(w http.ResponseWriter, r *http.Request) {
// Open the index.html file
f, err := content.ReadFile("static/shell.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Copy the index.html file to the response
fmt.Fprint(w, string(f))
}