File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -35,5 +35,6 @@ func NewHelperCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
35
35
helperCmd .AddCommand (NewFleetServerCmd (globalFlags ))
36
36
helperCmd .AddCommand (NewDockerCredentialsHelperCmd (globalFlags ))
37
37
helperCmd .AddCommand (NewGetImageCmd (globalFlags ))
38
+ helperCmd .AddCommand (requestCmd )
38
39
return helperCmd
39
40
}
Original file line number Diff line number Diff line change
1
+ package helper
2
+
3
+ import (
4
+ "fmt"
5
+ "io"
6
+ "log"
7
+
8
+ "github.com/loft-sh/devpod/pkg/daemon/workspace/network"
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var requestCmd = & cobra.Command {
13
+ Use : "request [path]" ,
14
+ Short : "Send an HTTP request to the specified path via the DevPod network" ,
15
+ Args : cobra .ExactArgs (1 ),
16
+ Run : func (cmd * cobra.Command , args []string ) {
17
+ path := args [0 ]
18
+
19
+ client := network .GetHTTPClient ()
20
+
21
+ url := fmt .Sprintf ("http://%s" , path )
22
+ log .Printf ("Sending request to %s via DevPod network" , url )
23
+
24
+ resp , err := client .Get (url )
25
+ if err != nil {
26
+ log .Fatalf ("HTTP request error: %v" , err )
27
+ }
28
+ defer resp .Body .Close ()
29
+
30
+ body , err := io .ReadAll (resp .Body )
31
+ if err != nil {
32
+ log .Fatalf ("Error reading response: %v" , err )
33
+ }
34
+ fmt .Printf ("Response:\n %s\n " , body )
35
+ },
36
+ }
You can’t perform that action at this time.
0 commit comments