-
Notifications
You must be signed in to change notification settings - Fork 16
/
wiretap_broadcast.go
80 lines (69 loc) · 2.5 KB
/
wiretap_broadcast.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
77
78
79
80
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package daemon
import (
"github.com/google/uuid"
"github.com/pb33f/libopenapi-validator/errors"
"github.com/pb33f/ranch/model"
"net/http"
)
func (ws *WiretapService) broadcastRequestValidationErrors(request *model.Request, errors []*errors.ValidationError) {
id, _ := uuid.NewUUID()
ht := buildRequest(request)
ht.RequestValidation = errors
ws.broadcastChan.Send(&model.Message{
Id: &id,
DestinationId: request.Id,
Channel: WiretapBroadcastChan,
Destination: WiretapBroadcastChan,
Payload: ht,
Direction: model.ResponseDir,
})
}
func (ws *WiretapService) broadcastRequest(request *model.Request) {
id, _ := uuid.NewUUID()
ws.broadcastChan.Send(&model.Message{
Id: &id,
DestinationId: request.Id,
Channel: WiretapBroadcastChan,
Destination: WiretapBroadcastChan,
Payload: buildRequest(request),
Direction: model.ResponseDir,
})
}
func (ws *WiretapService) broadcastResponse(request *model.Request, response *http.Response) {
id, _ := uuid.NewUUID()
ws.broadcastChan.Send(&model.Message{
Id: &id,
DestinationId: request.Id,
Channel: WiretapBroadcastChan,
Destination: WiretapBroadcastChan,
Payload: buildResponse(request, response),
Direction: model.ResponseDir,
})
}
func (ws *WiretapService) broadcastResponseError(request *model.Request, response *http.Response, err error) {
id, _ := uuid.NewUUID()
ws.broadcastChan.Send(&model.Message{
Id: &id,
DestinationId: request.Id,
Error: err,
Channel: WiretapBroadcastChan,
Destination: WiretapBroadcastChan,
Payload: buildResponse(request, response),
Direction: model.ResponseDir,
})
}
func (ws *WiretapService) broadcastResponseValidationErrors(request *model.Request, response *http.Response, errors []*errors.ValidationError) {
id, _ := uuid.NewUUID()
ht := buildResponse(request, response)
ht.ResponseValidation = errors
ws.broadcastChan.Send(&model.Message{
Id: &id,
DestinationId: request.Id,
Channel: WiretapBroadcastChan,
Destination: WiretapBroadcastChan,
Payload: ht,
Direction: model.ResponseDir,
})
}