-
Notifications
You must be signed in to change notification settings - Fork 929
/
plugin_repository.go
53 lines (44 loc) · 1.19 KB
/
plugin_repository.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
44
45
46
47
48
49
50
51
52
53
package plugin
import (
"net/url"
"path"
"strings"
)
// PluginRepository represents a plugin repository
type PluginRepository struct {
Plugins []Plugin `json:"plugins"`
}
type PluginBinary struct {
Platform string `json:"platform"`
URL string `json:"url"`
Checksum string `json:"checksum"`
}
type Plugin struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
Binaries []PluginBinary `json:"binaries"`
}
func (client *Client) GetPluginRepository(repositoryURL string) (PluginRepository, error) {
parsedURL, err := url.Parse(repositoryURL)
if err != nil {
return PluginRepository{}, err
}
parsedURL.Path = strings.TrimSuffix(parsedURL.Path, "/")
if !strings.HasSuffix(parsedURL.Path, "/list") {
parsedURL.Path = path.Join(parsedURL.Path, "list")
}
request, err := client.newGETRequest(parsedURL.String())
if err != nil {
return PluginRepository{}, err
}
var pluginRepository PluginRepository
response := Response{
Result: &pluginRepository,
}
err = client.connection.Make(request, &response, nil)
if err != nil {
return PluginRepository{}, err
}
return pluginRepository, nil
}