/
request.go
107 lines (95 loc) · 3.95 KB
/
request.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
package restful
import (
"gioui.org/layout"
"gioui.org/unit"
"github.com/mirzakhany/chapar/internal/domain"
"github.com/mirzakhany/chapar/ui/chapartheme"
"github.com/mirzakhany/chapar/ui/pages/requests/component"
"github.com/mirzakhany/chapar/ui/widgets"
)
type Request struct {
Tabs *widgets.Tabs
PreRequest *component.PrePostRequest
PostRequest *component.PrePostRequest
Body *Body
Params *Params
Headers *Headers
Auth *Auth
}
func NewRequest(req *domain.Request, theme *chapartheme.Theme) *Request {
r := &Request{
Tabs: widgets.NewTabs([]*widgets.Tab{
{Title: "Params"},
{Title: "Body"},
{Title: "Auth"},
{Title: "Headers"},
// {Title: "Pre Request"},
{Title: "Post Request"},
}, nil),
//PreRequest: component.NewPrePostRequest([]component.Option{
// {Title: "None", Value: domain.PostRequestTypeNone},
// {Title: "Python", Value: domain.PostRequestTypePythonScript, Type: component.TypeScript, Hint: "Write your pre request python script here"},
// {Title: "Shell Script", Value: domain.PostRequestTypeSSHTunnel, Type: component.TypeScript, Hint: "Write your pre request shell script here"},
// {Title: "Kubectl tunnel", Value: domain.PostRequestTypeK8sTunnel, Type: component.TypeScript, Hint: "Run kubectl port-forward command"},
// {Title: "SSH tunnel", Value: domain.PostRequestTypeSSHTunnel, Type: component.TypeScript, Hint: "Run ssh command"},
//}, theme),
PostRequest: component.NewPrePostRequest([]component.Option{
{Title: "None", Value: domain.PostRequestTypeNone},
{Title: "Set Environment Variable", Value: domain.PostRequestTypeSetEnv, Type: component.TypeSetEnv, Hint: "Set environment variable"},
// {Title: "Python", Value: domain.PostRequestTypePythonScript, Type: component.TypeScript, Hint: "Write your post request python script here"},
// {Title: "Shell Script", Value: domain.PostRequestTypeShellScript, Type: component.TypeScript, Hint: "Write your post request shell script here"},
}, theme),
Body: NewBody(req.Spec.HTTP.Request.Body, theme),
Params: NewParams(nil, nil),
Headers: NewHeaders(nil),
Auth: NewAuth(req.Spec.HTTP.Request.Auth, theme),
}
if req != nil && req.Spec != (domain.RequestSpec{}) && req.Spec.HTTP != nil && req.Spec.HTTP.Request != nil {
r.Params.SetQueryParams(req.Spec.HTTP.Request.QueryParams)
r.Params.SetPathParams(req.Spec.HTTP.Request.PathParams)
r.Headers.SetHeaders(req.Spec.HTTP.Request.Headers)
//if req.Spec.HTTP.Request.PreRequest != (domain.PreRequest{}) {
// r.PreRequest.SetSelectedDropDown(req.Spec.HTTP.Request.PreRequest.Type)
// r.PreRequest.SetCode(req.Spec.HTTP.Request.PreRequest.Script)
//}
if req.Spec.HTTP.Request.PostRequest != (domain.PostRequest{}) {
r.PostRequest.SetSelectedDropDown(req.Spec.HTTP.Request.PostRequest.Type)
// r.PostRequest.SetCode(req.Spec.HTTP.Request.PostRequest.Script)
}
if req.Spec.HTTP.Request.PostRequest.PostRequestSet != (domain.PostRequestSet{}) {
r.PostRequest.SetPostRequestSetValues(req.Spec.HTTP.Request.PostRequest.PostRequestSet)
}
}
return r
}
func (r *Request) Layout(gtx layout.Context, theme *chapartheme.Theme) layout.Dimensions {
inset := layout.Inset{Top: unit.Dp(10)}
return inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{
Axis: layout.Vertical,
Alignment: layout.Start,
}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return r.Tabs.Layout(gtx, theme)
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
switch r.Tabs.SelectedTab().Title {
//case "Pre Request":
// return r.PreRequest.Layout(gtx, theme)
case "Post Request":
return r.PostRequest.Layout(gtx, theme)
case "Params":
return r.Params.Layout(gtx, theme)
case "Headers":
return r.Headers.Layout(gtx, theme)
case "Auth":
return r.Auth.Layout(gtx, theme)
case "Body":
return r.Body.Layout(gtx, theme)
default:
return layout.Dimensions{}
}
}),
)
})
}