2021-07-21 00:15:57 +02:00
|
|
|
package api
|
2021-07-20 12:18:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-22 15:26:13 +02:00
|
|
|
"net/http"
|
2021-07-20 12:18:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-07-20 12:25:05 +02:00
|
|
|
URLRequestListVHost = "/v1/vhosts"
|
|
|
|
URLRequestListApp = "/v1/vhosts/%s/apps"
|
2021-07-20 12:18:00 +02:00
|
|
|
URLRequestListStream = "/v1/vhosts/%s/apps/%s/streams"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResponseList struct {
|
2021-07-20 12:25:05 +02:00
|
|
|
Message string `json:"message"`
|
|
|
|
StatusCode int `json:"statusCode"`
|
|
|
|
Data []string `json:"response,omitempty"`
|
2021-07-20 12:18:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:50:33 +02:00
|
|
|
// RequestListVHosts to get list of vhosts
|
2021-07-21 00:15:57 +02:00
|
|
|
func (c *Client) RequestListVHosts() (*ResponseList, error) {
|
2021-07-20 12:18:00 +02:00
|
|
|
req := ResponseList{}
|
|
|
|
url := fmt.Sprintf(URLRequestListVHost)
|
2021-08-22 15:26:13 +02:00
|
|
|
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
|
2021-07-20 12:18:00 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &req, nil
|
|
|
|
}
|
|
|
|
|
2021-07-28 14:50:33 +02:00
|
|
|
// RequestListApps to get list of apps on given vhost
|
2021-07-21 00:15:57 +02:00
|
|
|
func (c *Client) RequestListApps(vhost string) (*ResponseList, error) {
|
2021-07-20 12:18:00 +02:00
|
|
|
req := ResponseList{}
|
|
|
|
url := fmt.Sprintf(URLRequestListApp, vhost)
|
2021-08-22 15:26:13 +02:00
|
|
|
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
|
2021-07-20 12:18:00 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &req, nil
|
|
|
|
}
|
|
|
|
|
2021-07-28 14:50:33 +02:00
|
|
|
// RequestDefaultListApps to get list of apps on default vhost
|
|
|
|
func (c *Client) RequestDefaultListApps() (*ResponseList, error) {
|
|
|
|
return c.RequestListApps(c.DefaultVHost)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestDefaultListStreams to get list of streams on given vhost and app
|
2021-07-21 00:15:57 +02:00
|
|
|
func (c *Client) RequestListStreams(vhost, app string) (*ResponseList, error) {
|
2021-07-20 12:18:00 +02:00
|
|
|
req := ResponseList{}
|
|
|
|
url := fmt.Sprintf(URLRequestListStream, vhost, app)
|
2021-08-22 15:26:13 +02:00
|
|
|
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
|
2021-07-20 12:18:00 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &req, nil
|
|
|
|
}
|
2021-07-28 14:50:33 +02:00
|
|
|
|
|
|
|
// RequestDefaultListStreams to get list of streams on default vhost and app
|
|
|
|
func (c *Client) RequestDefaultListStreams() (*ResponseList, error) {
|
|
|
|
return c.RequestListStreams(c.DefaultVHost, c.DefaultApp)
|
|
|
|
}
|