Skip to content

Commit 5382163

Browse files
committed
Implement basic functionality
1 parent df6a718 commit 5382163

File tree

214 files changed

+58237
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+58237
-1
lines changed

Diff for: README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# pipe-curl
1+
# pipe-curl
2+
Window CLU util to make HTTP requests through Windows named pipe
3+
4+
# Usage
5+
6+
To use this, just call `pipe-curl.exe -p <path_to_pipe> http://localhost/<your_api_path>`
7+
8+
# Build
9+
10+
To build run:
11+
```shell
12+
go build -mod vendor
13+
```
14+
> Note: This is Windows only tool, build possible only on windows

Diff for: cmd/request.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"net/http"
7+
)
8+
9+
const (
10+
GET = "GET"
11+
)
12+
13+
func makeRequest(httpMethod, host, pipePath string) error {
14+
if httpMethod == "" {
15+
httpMethod = GET
16+
}
17+
18+
client := http.Client{
19+
Transport: transport(pipePath),
20+
}
21+
22+
req, err := http.NewRequest(httpMethod, host, nil)
23+
if err != nil {
24+
return err
25+
}
26+
27+
resp, err := client.Do(req)
28+
29+
if err != nil {
30+
fmt.Printf("Http Error: %s", err)
31+
return err
32+
}
33+
34+
bodyStr, _ := io.ReadAll(resp.Body)
35+
fmt.Println(string(bodyStr))
36+
37+
return nil
38+
}

Diff for: cmd/root.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
"os"
7+
)
8+
9+
var (
10+
pipePath string
11+
httpMethod string
12+
)
13+
14+
var rootCmd = &cobra.Command{
15+
Use: "pipe-curl",
16+
Short: "pipe-curl is a CLI to send HTTP Request thru windows named-pipe",
17+
Long: ``,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
// Do Stuff Here
20+
handleCommand(args)
21+
22+
},
23+
}
24+
25+
func init() {
26+
27+
rootCmd.PersistentFlags().StringVarP(&pipePath, "pipe", "p", "", "Path to Windows named pipe to interact with")
28+
rootCmd.MarkPersistentFlagRequired("pipe")
29+
30+
rootCmd.PersistentFlags().StringVarP(&httpMethod, "request", "X", "", "Change the method to use when starting the transfer")
31+
}
32+
33+
func handleCommand(args []string) {
34+
if len(args) != 1 {
35+
err := fmt.Errorf("only one argument is supported, got %s", args)
36+
printErrorAndExit(err)
37+
}
38+
39+
host := args[0]
40+
41+
err := makeRequest(httpMethod, host, pipePath)
42+
if err != nil {
43+
printErrorAndExit(err)
44+
}
45+
}
46+
47+
func printErrorAndExit(err error) {
48+
fmt.Println(err.Error())
49+
os.Exit(1)
50+
}
51+
52+
func Execute() {
53+
if err := rootCmd.Execute(); err != nil {
54+
fmt.Fprintln(os.Stderr, err)
55+
os.Exit(1)
56+
}
57+
58+
}

Diff for: cmd/transport.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"github.com/Microsoft/go-winio"
6+
"net"
7+
"net/http"
8+
)
9+
10+
func transport(pipePath string) *http.Transport {
11+
return &http.Transport{
12+
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
13+
return winio.DialPipeContext(ctx, pipePath)
14+
},
15+
}
16+
}

Diff for: go.mod

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
module pipe-curl
22

33
go 1.20
4+
5+
require (
6+
github.com/Microsoft/go-winio v0.6.1
7+
github.com/spf13/cobra v1.7.0
8+
)
9+
10+
require (
11+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
12+
github.com/spf13/pflag v1.0.5 // indirect
13+
golang.org/x/mod v0.8.0 // indirect
14+
golang.org/x/sys v0.5.0 // indirect
15+
golang.org/x/tools v0.6.0 // indirect
16+
)

Diff for: go.sum

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
2+
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
4+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
5+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
6+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7+
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
8+
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
9+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
10+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
11+
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
12+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
13+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
14+
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
15+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16+
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
17+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
18+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Diff for: main.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"pipe-curl/cmd"
7+
)
8+
9+
func main() {
10+
cmd.Execute()
11+
}

Diff for: vendor/github.com/Microsoft/go-winio/.gitattributes

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/Microsoft/go-winio/.gitignore

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/Microsoft/go-winio/.golangci.yml

+149
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/Microsoft/go-winio/CODEOWNERS

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/Microsoft/go-winio/LICENSE

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)