-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
executable file
·200 lines (174 loc) · 4.59 KB
/
Copy pathtypes.go
File metadata and controls
executable file
·200 lines (174 loc) · 4.59 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package rubik
import (
"fmt"
"net/http"
"os"
)
type IpcRxEntity struct {
Entity
Message string `rubik:"|param"`
Body interface{} `rubik:"|body"`
}
// ByteType let's rubik know what type of bytes to send as response
type ByteType int
// Type is a rubik type literal used for indication of response/template types
var Type = struct {
HTML ByteType
JSON ByteType
Text ByteType
Bytes ByteType
templateHTML ByteType
templateText ByteType
Gob ByteType
}{1, 2, 3, 4, 5, 6, 7}
// Content is a struct that holds default values of Content-Type headers
// it can be used throughout your rubik application for avoiding basic
// spell mistakes
var Content = struct {
Header string
JSON string
Text string
HTML string
URLEncoded string
Multipart string
}{
"Content-Type",
"application/json",
"text/plain",
"text/html",
"application/x-www-form-urlencoded",
"multipart/form-data",
}
var StringByteTypeMap = map[string]ByteType{
"json": Type.JSON,
"html": Type.HTML,
"text": Type.Text,
}
// Message that is to be sent in communicator channel
type Message struct {
Communicator string
Topic string
Body interface{}
}
// MessagePasser holds the channels for communication with rubik server
type MessagePasser struct {
Message chan Message
Error chan error
}
// ByteResponse is the response of rubik server
type ByteResponse struct {
Status int
Data interface{}
OfType ByteType
Error error
redirectURL string
safeWrite bool
handler http.Handler
handlerFunc http.HandlerFunc
}
// Validation is validation operations to be performed
// on the request entity
type Validation map[string][]Assertion
// SessionManager is an interface contract that rubik.Session uses
// Anything abiding by this contract can
type SessionManager interface {
Get(string) string
Set(string, string) error
Delete(string) bool
}
// Communicator interface is used to handle the service/driver that
// rubik's inherent communication depends upon
type Communicator interface {
Send(string, interface{}) error
}
// Entity holds the data for a single API call
// It lets you write consolidated clean Go code
type Entity struct {
entityType string
PointTo string
Params []string
request *http.Request
FormData bool
URLEncoded bool
JSON bool
Infer interface{}
Cookies Values
RawBody []byte
}
// GobEntity extends Entity and let's rubik know that this date is
// present inside body of the request and you need to decode it using
// GobDecoder
// type GobEntity struct {
// Entity
// }
// GetCtx ...
// func (re RequestEntity) GetCtx() *Payload {
// return re.request
// }
// BlankRequestEntity ...
type BlankRequestEntity struct {
Entity
}
// DownloadRequestEntity ...
type DownloadRequestEntity struct {
Entity
TargetFilePath string
}
// Values that transcends url.Values allowing any type as value
type Values map[string]interface{}
// Encode converts the values into urlencoded strings
func (val Values) Encode() string {
var qs = ""
var cnt = 0
if len(val) > 0 {
for k, v := range val {
qs += fmt.Sprintf("%s=%v", k, v)
if cnt+1 != len(val) {
qs += "&"
}
cnt++
}
}
return qs
}
// Set assigns a value for key `key` inside the rubik.Values
func (val Values) Set(key string, value interface{}) {
val[key] = value
}
// File used by ink to embed file
type File struct {
Path string
OSFile *os.File
Raw []byte
}
// RResponseWriter is Rubik's response writer that implements http.ResponseWriter
// and it's methods to provide additional functionalities related to Rubik.
type RResponseWriter struct {
http.ResponseWriter
written bool
status int
data []byte
}
// WriteHeader writes the http.Request's Header values to the wire and
// sets the status given as the parameter
func (w *RResponseWriter) WriteHeader(status int) {
w.status = status
w.written = true
w.ResponseWriter.WriteHeader(status)
}
// Write writes the response bytes b to the wire
func (w *RResponseWriter) Write(b []byte) (int, error) {
w.data = b
w.written = true
return w.ResponseWriter.Write(b)
}
// Assertion is the assert functions for rubik's validation cycle
// it should return a message stating why validation failed and
// bool indicating if assertion has passed or not
type Assertion func(interface{}) error
// Modifier lets you modify the parameters passed through the request.
// The input of the modifier is the value from the wire and the output
// is the modified value.
// Note: Modified value type must match the type declared in the
// entity.
// type Modifier func(interface{}) interface{}