-
Notifications
You must be signed in to change notification settings - Fork 17
/
request-response.go
92 lines (80 loc) · 2.03 KB
/
request-response.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
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* SPDX-License-Identifier: MIT
*/
package v1alpha2
import (
"context"
"fmt"
)
type COARequest struct {
Context context.Context `json:"-"`
Method string `json:"method"`
Route string `json:"route"`
ContentType string `json:"contentType"`
Body []byte `json:"body"`
Metadata map[string]string `json:"metadata,omitempty"`
Parameters map[string]string `json:"parameters,omitempty"`
}
func (in *COARequest) DeepCopyInto(out *COARequest) {
*out = *in
out.Context = in.Context //TODO: Is this okay?
out.Method = in.Method
out.Route = in.Route
out.ContentType = in.ContentType
if in.Body != nil {
out.Body = make([]byte, len(in.Body))
copy(out.Body, in.Body)
}
if in.Metadata != nil {
in, out := &in.Metadata, &out.Metadata
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Parameters != nil {
in, out := &in.Parameters, &out.Parameters
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}
func (in *COARequest) DeepCopy() *COARequest {
if in == nil {
return nil
}
out := new(COARequest)
in.DeepCopyInto(out)
return out
}
type COAResponse struct {
ContentType string `json:"contentType"`
Body []byte `json:"body"`
State State `json:"state"`
Metadata map[string]string `json:"metadata,omitempty"`
RedirectUri string `json:"redirectUri,omitempty"`
}
func (c COAResponse) String() string {
return string(c.Body)
}
func (c COAResponse) Println() {
fmt.Println(string(c.Body))
}
type COAHandler func(COARequest) COAResponse
type Endpoint struct {
Methods []string
Version string
Route string
Handler COAHandler
Parameters []string
}
func (e Endpoint) GetPath() string {
path := fmt.Sprintf("/%s/%s", e.Version, e.Route)
for _, p := range e.Parameters {
path += "/{" + p + "}"
}
return path
}