-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (48 loc) · 937 Bytes
/
main.go
File metadata and controls
61 lines (48 loc) · 937 Bytes
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
package main
import (
"fmt"
"github.com/leeeboo/wechat/wx"
"log"
"net/http"
"time"
)
const (
logLevel = "dev"
port = 8081
token = "kosfe9rtue9r1"
)
func get(w http.ResponseWriter, r *http.Request) {
client, err := wx.NewClient(r, w, token)
if err != nil {
log.Println(err)
w.WriteHeader(403)
return
}
if len(client.Query.Echostr) > 0 {
w.Write([]byte(client.Query.Echostr))
return
}
w.WriteHeader(403)
return
}
func post(w http.ResponseWriter, r *http.Request) {
client, err := wx.NewClient(r, w, token)
if err != nil {
log.Println(err)
w.WriteHeader(403)
return
}
client.Run()
return
}
func main() {
server := http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: &httpHandler{},
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
MaxHeaderBytes: 0,
}
log.Println(fmt.Sprintf("Listen: %d", port))
log.Fatal(server.ListenAndServe())
}