aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings/connection.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2020-01-15 12:28:46 -0600
committerbaude <bbaude@redhat.com>2020-01-15 14:22:25 -0600
commita6ea17455cb0c7bdc3d250e57e20d6dc9f5df45d (patch)
treef213779a9052f2aa375ca7bcf63156e9a0449466 /pkg/bindings/connection.go
parent34429f3b534960d2505789fcb0ac0278fc4aa4c0 (diff)
downloadpodman-a6ea17455cb0c7bdc3d250e57e20d6dc9f5df45d.tar.gz
podman-a6ea17455cb0c7bdc3d250e57e20d6dc9f5df45d.tar.bz2
podman-a6ea17455cb0c7bdc3d250e57e20d6dc9f5df45d.zip
[CI:DOCS]swagger cleanup and left-hand nav
add a static tags file so we can dictate the left-hand navigation. in doing so we now override the tag in the swagger:operation. we now have images and images (compat) as a way to differentiate. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/connection.go')
-rw-r--r--pkg/bindings/connection.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go
new file mode 100644
index 000000000..551a63c62
--- /dev/null
+++ b/pkg/bindings/connection.go
@@ -0,0 +1,62 @@
+package bindings
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+)
+
+const (
+ defaultConnection string = "http://localhost:8080/v1.24/libpod"
+ pingConnection string = "http://localhost:8080/_ping"
+)
+
+type APIResponse struct {
+ *http.Response
+ Request *http.Request
+}
+
+type Connection struct {
+ url string
+ client *http.Client
+}
+
+func NewConnection(url string) (Connection, error) {
+ if len(url) < 1 {
+ url = defaultConnection
+ }
+ newConn := Connection{
+ url: url,
+ client: &http.Client{},
+ }
+ response, err := http.Get(pingConnection)
+ if err != nil {
+ return newConn, err
+ }
+ if err := response.Body.Close(); err != nil {
+ return newConn, err
+ }
+ return newConn, err
+}
+
+func (c Connection) makeEndpoint(u string) string {
+ return fmt.Sprintf("%s%s", defaultConnection, u)
+}
+
+func (c Connection) newRequest(httpMethod, endpoint string, httpBody io.Reader, params map[string]string) (*APIResponse, error) {
+ e := c.makeEndpoint(endpoint)
+ req, err := http.NewRequest(httpMethod, e, httpBody)
+ if err != nil {
+ return nil, err
+ }
+ if len(params) > 0 {
+ // if more desirable we could use url to form the encoded endpoint with params
+ r := req.URL.Query()
+ for k, v := range params {
+ r.Add(k, v)
+ }
+ req.URL.RawQuery = r.Encode()
+ }
+ response, err := c.client.Do(req) // nolint
+ return &APIResponse{response, req}, err
+}