good morning!!!!

Skip to content
Snippets Groups Projects
Commit 3a25d081 authored by a's avatar a
Browse files

ok

parent 9392a45f
Branches
Tags
No related merge requests found
Pipeline #867 passed
......@@ -3,6 +3,7 @@ package fs_actions
import (
"errors"
"log"
"net/http"
"strings"
"gfx.cafe/open/goutil/filing"
......@@ -21,7 +22,7 @@ type SyncOptions struct {
func ConnectFilesystem(s *SyncOptions) filing.HashedFS {
var out filing.HashedFS
if strings.HasPrefix(s.Path, "http") {
client := api_weed.NewClient(httpclient.NewAuthClient(s.User, s.Pass))
client := api_weed.NewClient(httpclient.New(http.DefaultClient).WithGFX(s.User, s.Pass))
out = fs_weed.New(s.Path, client)
} else if strings.HasPrefix(s.Path, "/") || strings.HasPrefix(s.Path, ".") {
out = fs_local.New(s.Path)
......
......@@ -2,6 +2,7 @@ package fs_weed_test
import (
"log"
"net/http"
"os"
"testing"
......@@ -15,7 +16,7 @@ func TestHashUnicode(t *testing.T) {
user := os.Getenv("FILER_USER")
pass := os.Getenv("FILER_PASS")
client := api_weed.NewClient(httpclient.NewAuthClient(user, pass))
client := api_weed.NewClient(httpclient.New(http.DefaultClient).WithGFX(user, pass))
filer := fs_weed.New(url, client)
log.Println(filer.ListFiles())
......
......@@ -7,20 +7,38 @@ import (
type AuthClient struct {
user string
key string
headers map[string]string
client *http.Client
}
func NewAuthClient(user, key string) *AuthClient {
return &AuthClient{
user: user,
key: key,
client: &http.Client{},
func New(c *http.Client) *AuthClient {
return &AuthClient{client: c, headers: map[string]string{}}
}
func (A *AuthClient) WithGFX(user, key string) *AuthClient {
A.user = user
A.key = key
return A
}
func (A *AuthClient) WithHeaders(m map[string]string) {
for k, v := range m {
A.WithHeader(k, v)
}
}
func (A *AuthClient) WithHeader(k, v string) {
A.headers[k] = v
}
func (A *AuthClient) Do(req *http.Request) (*http.Response, error) {
req.Header.Add("GFX-API-TOKEN", A.key)
req.Header.Add("GFX-API-USER", A.user)
for k, v := range A.headers {
req.Header.Add(k, v)
}
req.Header.Add("Accept", "application/json")
return A.client.Do(req)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment