···
+
"tangled.sh/tangled.sh/core/types"
+
type UnsignedClient struct {
+
func NewUnsignedClient(domain string, dev bool) (*UnsignedClient, error) {
+
client := &http.Client{
+
Timeout: 5 * time.Second,
+
url, err := url.Parse(fmt.Sprintf("%s://%s", scheme, domain))
+
unsignedClient := &UnsignedClient{
+
return unsignedClient, nil
+
func (us *UnsignedClient) newRequest(method, endpoint string, query url.Values, body []byte) (*http.Request, error) {
+
reqUrl := us.Url.JoinPath(endpoint)
+
// add query parameters
+
reqUrl.RawQuery = query.Encode()
+
return http.NewRequest(method, reqUrl.String(), bytes.NewReader(body))
+
func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*http.Response, error) {
+
endpoint := fmt.Sprintf("/%s/%s/tree/%s", ownerDid, repoName, ref)
+
endpoint = fmt.Sprintf("/%s/%s", ownerDid, repoName)
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
return us.client.Do(req)
+
func (us *UnsignedClient) Log(ownerDid, repoName, ref string, page int) (*http.Response, error) {
+
endpoint := fmt.Sprintf("/%s/%s/log/%s", ownerDid, repoName, url.PathEscape(ref))
+
query.Add("page", strconv.Itoa(page))
+
query.Add("per_page", strconv.Itoa(60))
+
req, err := us.newRequest(Method, endpoint, query, nil)
+
return us.client.Do(req)
+
func (us *UnsignedClient) Branches(ownerDid, repoName string) (*http.Response, error) {
+
endpoint := fmt.Sprintf("/%s/%s/branches", ownerDid, repoName)
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
return us.client.Do(req)
+
func (us *UnsignedClient) Tags(ownerDid, repoName string) (*types.RepoTagsResponse, error) {
+
endpoint := fmt.Sprintf("/%s/%s/tags", ownerDid, repoName)
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
resp, err := us.client.Do(req)
+
body, err := io.ReadAll(resp.Body)
+
var result types.RepoTagsResponse
+
err = json.Unmarshal(body, &result)
+
func (us *UnsignedClient) Branch(ownerDid, repoName, branch string) (*http.Response, error) {
+
endpoint := fmt.Sprintf("/%s/%s/branches/%s", ownerDid, repoName, url.PathEscape(branch))
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
return us.client.Do(req)
+
func (us *UnsignedClient) DefaultBranch(ownerDid, repoName string) (*types.RepoDefaultBranchResponse, error) {
+
endpoint := fmt.Sprintf("/%s/%s/branches/default", ownerDid, repoName)
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
resp, err := us.client.Do(req)
+
defer resp.Body.Close()
+
var defaultBranch types.RepoDefaultBranchResponse
+
if err := json.NewDecoder(resp.Body).Decode(&defaultBranch); err != nil {
+
return &defaultBranch, nil
+
func (us *UnsignedClient) Capabilities() (*types.Capabilities, error) {
+
Endpoint = "/capabilities"
+
req, err := us.newRequest(Method, Endpoint, nil, nil)
+
resp, err := us.client.Do(req)
+
defer resp.Body.Close()
+
var capabilities types.Capabilities
+
if err := json.NewDecoder(resp.Body).Decode(&capabilities); err != nil {
+
return &capabilities, nil
+
func (us *UnsignedClient) Compare(ownerDid, repoName, rev1, rev2 string) (*types.RepoFormatPatchResponse, error) {
+
endpoint := fmt.Sprintf("/%s/%s/compare/%s/%s", ownerDid, repoName, url.PathEscape(rev1), url.PathEscape(rev2))
+
req, err := us.newRequest(Method, endpoint, nil, nil)
+
return nil, fmt.Errorf("Failed to create request.")
+
compareResp, err := us.client.Do(req)
+
return nil, fmt.Errorf("Failed to create request.")
+
defer compareResp.Body.Close()
+
switch compareResp.StatusCode {
+
return nil, fmt.Errorf("Branch comparisons not supported on this knot.")
+
respBody, err := io.ReadAll(compareResp.Body)
+
log.Println("failed to compare across branches")
+
return nil, fmt.Errorf("Failed to compare branches.")
+
defer compareResp.Body.Close()
+
var formatPatchResponse types.RepoFormatPatchResponse
+
err = json.Unmarshal(respBody, &formatPatchResponse)
+
log.Println("failed to unmarshal format-patch response", err)
+
return nil, fmt.Errorf("failed to compare branches.")
+
return &formatPatchResponse, nil