forked from harness/gitness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contents.go
43 lines (35 loc) · 1.08 KB
/
contents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package bitbucket
import (
"fmt"
)
type Source struct {
Node string `json:"node"`
Path string `json:"path"`
Data string `json:"data"`
Size int64 `json:"size"`
}
// Use the Bitbucket src resource to browse directories and view files.
// This is a read-only resource.
//
// https://confluence.atlassian.com/display/BITBUCKET/src+Resources
type SourceResource struct {
client *Client
}
// Gets information about an individual file in a repository
func (r *SourceResource) Find(owner, slug, revision, path string) (*Source, error) {
src := Source{}
url_path := fmt.Sprintf("/repositories/%s/%s/src/%s/%s", owner, slug, revision, path)
if err := r.client.do("GET", url_path, nil, nil, &src); err != nil {
return nil, err
}
return &src, nil
}
// Gets a list of the src in a repository.
func (r *SourceResource) List(owner, slug, revision, path string) ([]*Source, error) {
src := []*Source{}
url_path := fmt.Sprintf("/repositories/%s/%s/src/%s/%s", owner, slug, revision, path)
if err := r.client.do("GET", url_path, nil, nil, &src); err != nil {
return nil, err
}
return src, nil
}