-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (43 loc) · 1.12 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
package main
import (
"embed"
"log"
"net/http"
"os"
"time"
"github.com/xmdhs/searchqanda/get"
"github.com/xmdhs/searchqanda/web"
)
func main() {
if len(os.Args) != 1 {
upsql()
} else {
r := http.NewServeMux()
r.HandleFunc("/search", web.Index)
r.HandleFunc("/search/static/", func(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("cache-control", "max-age=2592000")
http.StripPrefix("/search/", http.FileServer(http.FS(staticfile))).ServeHTTP(rw, r)
})
r.HandleFunc("/search/s", func(rw http.ResponseWriter, r *http.Request) {
rw.Write(htmlfile)
})
r.HandleFunc("/search/api/s", web.SerchApi)
r.HandleFunc("/search/hide", web.Auth(web.Hidethead, key))
r.HandleFunc("/search/snapshot", web.Auth(web.Snapshot, key))
s := http.Server{
Addr: ":8081",
ReadTimeout: 5 * time.Second,
WriteTimeout: 20 * time.Second,
Handler: r,
}
log.Println(s.ListenAndServe())
}
}
//go:embed static
var staticfile embed.FS
//go:embed static/index.html
var htmlfile []byte
func upsql() {
get.Start()
}
const key = "53e6b64604b8ed484bb6c67b93c0987bec828db8d4a725d080dd7092b9fb15b2"