cmd: allow import/running ctrld as library

This commit is contained in:
Cuong Manh Le
2023-08-15 11:15:37 +00:00
committed by Cuong Manh Le
parent 4896563e3c
commit 829e93c079
34 changed files with 195 additions and 188 deletions
+29
View File
@@ -0,0 +1,29 @@
package cli
import (
"context"
"io"
"net"
"net/http"
"time"
)
type controlClient struct {
c *http.Client
}
func newControlClient(addr string) *controlClient {
return &controlClient{c: &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
d := net.Dialer{}
return d.DialContext(ctx, "unix", addr)
},
},
Timeout: time.Second * 30,
}}
}
func (c *controlClient) post(path string, data io.Reader) (*http.Response, error) {
return c.c.Post("http://unix"+path, contentTypeJson, data)
}