This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
134 lines (113 loc) · 3.45 KB
/
structs.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package resttunnel
import (
"time"
"github.com/google/uuid"
"github.com/valyala/fasthttp"
"golang.org/x/xerrors"
)
// ResponseType represents the type of response the client wants
type ResponseType int8
const (
// RespondWithResponse defines the client wants the response.
RespondWithResponse ResponseType = iota
// RespondWithUUIDCallback defines the client will want the response at a later time.
RespondWithUUIDCallback
// NoResponse defines the client does not want the response.
NoResponse
)
func (rt ResponseType) String() string {
switch rt {
case RespondWithResponse:
return "RespondWithResponse"
case RespondWithUUIDCallback:
return "RespondWithUUIDCallback"
case NoResponse:
return "NoResponse"
}
return ""
}
// ParseResponse converts a response string into a ResponseType value.
// returns an error if the input string does not match known values.
func ParseResponse(responseStr string) (ResponseType, error) {
switch responseStr {
case RespondWithResponse.String():
return RespondWithResponse, nil
case RespondWithUUIDCallback.String():
return RespondWithUUIDCallback, nil
case NoResponse.String():
return NoResponse, nil
}
return RespondWithResponse, xerrors.Errorf("Unknown ResponseType String: '%s', defaulting to RespondWithResponse", responseStr)
}
// AliveResponse represents the response to /alive
type AliveResponse struct {
Name string `json:"name"`
Version string `json:"version"`
Reverse bool `json:"reverse"`
}
// TunnelRequest represents a RestTunnel request
type TunnelRequest struct {
ID uuid.UUID
Req *fasthttp.RequestCtx
URI []byte
Body []byte
Method string
QueryString []byte
Headers *fasthttp.RequestHeader
ResponseType ResponseType
Priority bool
Bucket string
Callback chan bool
}
// TunnelResponse represents a RestTunnel response
type TunnelResponse struct {
Expiration time.Time
CompleteC chan bool
Complete bool
ID uuid.UUID
RatelimitHit bool
Response *fasthttp.Response
Error error
}
// RateLimitResponse represents the structure of a ratelimit
// message from discord
type RateLimitResponse struct {
Message string `json:"message"`
RetryAfter time.Duration `json:"retry_after"`
Global bool `json:"global"`
}
// DataStamp is a struct to store a time and a corresponding value
type DataStamp struct {
Time interface{} `json:"x"`
Value interface{} `json:"y"`
}
// LineChart is a struct to store LineChart data easier
type LineChart struct {
Labels []string `json:"labels,omitempty"`
Datasets []Dataset `json:"datasets"`
}
// Dataset is a struct to store data for a Chart
type Dataset struct {
Label string `json:"label"`
BackgroundColour string `json:"backgroundColor,omitempty"`
BorderColour string `json:"borderColor,omitempty"`
Data []interface{} `json:"data"`
}
// AnalyticResponse returns the response to an api/analytics request
type AnalyticResponse struct {
Uptime string `json:"uptime"`
Charts struct {
Hits LineChart `json:"hits"`
Misses LineChart `json:"misses"`
Waiting LineChart `json:"waiting"`
Requests LineChart `json:"requests"`
Callbacks LineChart `json:"callbacks"`
AverageResponse LineChart `json:"average_response"`
} `json:"charts"`
Numbers struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Requests int64 `json:"requests"`
Waiting int64 `json:"waiting"`
} `json:"numbers"`
}