forked from influxdata/chronograf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinks.go
59 lines (50 loc) · 1.77 KB
/
links.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
54
55
56
57
58
59
package server
import (
"errors"
"net/url"
)
type getFluxLinksResponse struct {
AST string `json:"ast"`
Self string `json:"self"`
Suggestions string `json:"suggestions"`
}
type getConfigLinksResponse struct {
Self string `json:"self"` // Location of the whole global application configuration
Auth string `json:"auth"` // Location of the auth section of the global application configuration
}
type getOrganizationConfigLinksResponse struct {
Self string `json:"self"` // Location of the organization configuration
LogViewer string `json:"logViewer"` // Location of the organization-specific log viewer configuration
}
type getExternalLinksResponse struct {
StatusFeed *string `json:"statusFeed,omitempty"` // Location of the a JSON Feed for client's Status page News Feed
CustomLinks []CustomLink `json:"custom,omitempty"` // Any custom external links for client's User menu
}
// CustomLink is a handler that returns a custom link to be used in server's routes response, within ExternalLinks
type CustomLink struct {
Name string `json:"name"`
URL string `json:"url"`
}
// NewCustomLinks transforms `--custom-link` CLI flag data or `CUSTOM_LINKS` ENV
// var data into a data structure that the Chronograf client will expect
func NewCustomLinks(links map[string]string) ([]CustomLink, error) {
customLinks := make([]CustomLink, 0, len(links))
for name, link := range links {
if name == "" {
return nil, errors.New("CustomLink missing key for Name")
}
if link == "" {
return nil, errors.New("CustomLink missing value for URL")
}
_, err := url.Parse(link)
if err != nil {
return nil, err
}
customLink := CustomLink{
Name: name,
URL: link,
}
customLinks = append(customLinks, customLink)
}
return customLinks, nil
}