summaryrefslogtreecommitdiff
path: root/go/internal/gitlabnet/socketclient.go
diff options
context:
space:
mode:
authorIgor <idrozdov@gitlab.com>2019-04-24 11:12:28 +0000
committerNick Thomas <nick@gitlab.com>2019-04-24 11:12:28 +0000
commit9d9e1617ab7173ed245860612280284c7c904b58 (patch)
tree0c7eae65818430d632f60433195aa08ce122aa8f /go/internal/gitlabnet/socketclient.go
parent6e9b4dec537171c643e67fc6a73b79dd29afd068 (diff)
downloadgitlab-shell-9d9e1617ab7173ed245860612280284c7c904b58.tar.gz
Support calling internal api using HTTP
Diffstat (limited to 'go/internal/gitlabnet/socketclient.go')
-rw-r--r--go/internal/gitlabnet/socketclient.go66
1 files changed, 0 insertions, 66 deletions
diff --git a/go/internal/gitlabnet/socketclient.go b/go/internal/gitlabnet/socketclient.go
deleted file mode 100644
index fd97535..0000000
--- a/go/internal/gitlabnet/socketclient.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package gitlabnet
-
-import (
- "bytes"
- "context"
- "encoding/json"
- "net"
- "net/http"
- "strings"
-
- "gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
-)
-
-const (
- // We need to set the base URL to something starting with HTTP, the host
- // itself is ignored as we're talking over a socket.
- socketBaseUrl = "http://unix"
- UnixSocketProtocol = "http+unix://"
-)
-
-type GitlabSocketClient struct {
- httpClient *http.Client
- config *config.Config
-}
-
-func buildSocketClient(config *config.Config) *GitlabSocketClient {
- path := strings.TrimPrefix(config.GitlabUrl, UnixSocketProtocol)
- httpClient := &http.Client{
- Transport: &http.Transport{
- DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
- return net.Dial("unix", path)
- },
- },
- }
-
- return &GitlabSocketClient{httpClient: httpClient, config: config}
-}
-
-func (c *GitlabSocketClient) Get(path string) (*http.Response, error) {
- path = normalizePath(path)
-
- request, err := http.NewRequest("GET", socketBaseUrl+path, nil)
- if err != nil {
- return nil, err
- }
-
- return doRequest(c.httpClient, c.config, request)
-}
-
-func (c *GitlabSocketClient) Post(path string, data interface{}) (*http.Response, error) {
- path = normalizePath(path)
-
- jsonData, err := json.Marshal(data)
- if err != nil {
- return nil, err
- }
-
- request, err := http.NewRequest("POST", socketBaseUrl+path, bytes.NewReader(jsonData))
- request.Header.Add("Content-Type", "application/json")
-
- if err != nil {
- return nil, err
- }
-
- return doRequest(c.httpClient, c.config, request)
-}