-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
76 lines (53 loc) · 1.35 KB
/
http.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/xen0n/go-workwx"
)
type jsonAPI struct{}
var jsonhttp = &jsonAPI{}
func (j *jsonAPI) init() {
j.msghttp()
select {}
}
func (j *jsonAPI) msghttp() {
hh, err := workwx.NewHTTPHandler(conf.WeiXin.Token, conf.WeiXin.AESKey, dummyRxMessageHandler{})
if err != nil {
fmt.Println("parm error:", err)
os.Exit(1)
}
mux := http.NewServeMux()
mux.Handle("/", hh)
log.Println("Server started !")
err = http.ListenAndServe(conf.Web.Port, mux)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func (j *jsonAPI) msghttp2() {
router := mux.NewRouter()
router.HandleFunc("/message", j.httpMessage)
router.Handle("/", http.FileServer(http.Dir(conf.Web.RootPath)))
if conf.Web.SSLcrt == "" || conf.Web.SSLkey == "" {
err := http.ListenAndServe(":"+conf.Web.Port, router)
if err != nil {
fmt.Println("start http err:", err)
}
} else {
//http.ListenAndServe(":9999", nil)
err := http.ListenAndServeTLS(":"+conf.Web.Port, conf.Web.SSLcrt, conf.Web.SSLkey, router)
if err != nil {
fmt.Println("start http ssl err:", err)
}
}
}
func (j *jsonAPI) httpMessage(w http.ResponseWriter, req *http.Request) {
// hh, err := workwx.NewHTTPHandler(conf.WeiXin.Token, conf.WeiXin.AESKey, dummyRxMessageHandler{})
// if err != nil {
// panic(err)
// }
}