-
Notifications
You must be signed in to change notification settings - Fork 165
/
guard.go
55 lines (42 loc) · 1.16 KB
/
guard.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
package server
import (
"bytes"
logger2 "github.com/ArtisanCloud/PowerLibs/v3/logger"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"io/ioutil"
"net/http"
)
type Guard struct {
*kernel.ServerGuard
}
func NewGuard(app *kernel.ApplicationInterface) *Guard {
//config := (*app).GetContainer().GetConfig()
guard := &Guard{
kernel.NewServerGuard(app),
}
guard.OverrideShouldReturnRawResponse()
return guard
}
func (guard *Guard) VerifyURL(request *http.Request) (httpRS *http.Response, err error) {
logger := (*guard.App).GetComponent("Logger").(*logger2.Logger)
_, err = guard.Validate(request)
if err != nil {
return nil, err
}
bodyData := ioutil.NopCloser(bytes.NewBufferString(request.URL.Query().Get("echostr")))
rs := &http.Response{
Body: bodyData,
StatusCode: http.StatusOK,
}
logger.Info("Server response created:", "content", request.URL.Query().Get("echostr"))
return rs, err
}
// Override Validate
func (guard *Guard) OverrideShouldReturnRawResponse() {
guard.ShouldReturnRawResponse = func(request *http.Request) bool {
if request == nil || request.URL.Query().Get("echostr") == "" {
return false
}
return true
}
}