-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
40 lines (34 loc) · 1.07 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
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"v2ray-heal/config"
"v2ray-heal/handler"
)
var confer = config.GetConfig()
func main() {
var router = httprouter.New()
router.GlobalOPTIONS = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Access-Control-Request-Method") != "" {
header := w.Header()
header.Set("Access-Control-Allow-Methods", header.Get("Allow"))
header.Set("Access-Control-Allow-Origin", "*")
header.Set("Access-Control-Allow-Headers", "*")
}
w.WriteHeader(http.StatusNoContent)
})
router.PanicHandler = func(w http.ResponseWriter, r *http.Request, v interface{}) {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(fmt.Sprintf("err: %+v", v)))
}
router.GET("/sub", handler.Sub)
router.POST("/pub", handler.Pub)
log.Printf("%s start...", confer.ProjectName)
if confer.Https.Enable {
log.Fatal(http.ListenAndServeTLS(confer.Port, confer.Https.CrtFile, confer.Https.KeyFile, router))
} else {
log.Fatal(http.ListenAndServe(confer.Port, router))
}
}