Created
February 14, 2022 09:40
-
-
Save anjannath/01b9593427906dd94169b0c56d54a970 to your computer and use it in GitHub Desktop.
quickly test the crc daemon api on window via namedpipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"io/ioutil" | |
"net" | |
"net/http" | |
"os" | |
"time" | |
"github.com/Microsoft/go-winio" | |
) | |
func main() { | |
// create http client connecting to the daemon namedpipe | |
client := &http.Client{ | |
Transport: &http.Transport{ | |
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | |
return winio.DialPipeContext(ctx, `\\.\pipe\crc-http`) | |
}, | |
}, | |
Timeout: 3 * time.Second, | |
} | |
fmt.Printf("Sending %s command ==> %s\n\n", os.Args[1], os.Args[2]) | |
// send the requested http method to the requested url | |
switch os.Args[1] { | |
case "get", "GET": | |
if resp, err := client.Get(os.Args[2]); err == nil { | |
b, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println(resp.Status) | |
fmt.Println(string(b)) | |
} | |
case "post", "POST": | |
fmt.Println("not implemented") | |
default: | |
fmt.Println("not implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment