gofmt
This commit is contained in:
parent
64ca86effa
commit
d1605ee841
2
main.go
2
main.go
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
|
||||
"dev.sum7.eu/genofire/golang-lib/file"
|
||||
"github.com/bdlm/log"
|
||||
|
|
|
@ -2,16 +2,16 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (c *configData) Request(url string, value interface{}) error {
|
||||
netClient := &http.Client{
|
||||
Timeout: time.Second * 20,
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodGet, c.Host + url, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, c.Host+url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -30,4 +30,3 @@ func (c *configData) Request(url string, value interface{}) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -5,22 +5,21 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
URLRequestListVHost = "/v1/vhosts"
|
||||
URLRequestListApp = "/v1/vhosts/%s/apps"
|
||||
URLRequestListVHost = "/v1/vhosts"
|
||||
URLRequestListApp = "/v1/vhosts/%s/apps"
|
||||
URLRequestListStream = "/v1/vhosts/%s/apps/%s/streams"
|
||||
|
||||
)
|
||||
|
||||
type ResponseList struct {
|
||||
Message string `json:"message"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
Data []string `json:"response,omitempty"`
|
||||
Message string `json:"message"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
Data []string `json:"response,omitempty"`
|
||||
}
|
||||
|
||||
func (c *configData) RequestListVHosts() (*ResponseList, error) {
|
||||
req := ResponseList{}
|
||||
url := fmt.Sprintf(URLRequestListVHost)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
@ -29,7 +28,7 @@ func (c *configData) RequestListVHosts() (*ResponseList, error) {
|
|||
func (c *configData) RequestListApps(vhost string) (*ResponseList, error) {
|
||||
req := ResponseList{}
|
||||
url := fmt.Sprintf(URLRequestListApp, vhost)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
@ -38,7 +37,7 @@ func (c *configData) RequestListApps(vhost string) (*ResponseList, error) {
|
|||
func (c *configData) RequestListStreams(vhost, app string) (*ResponseList, error) {
|
||||
req := ResponseList{}
|
||||
url := fmt.Sprintf(URLRequestListStream, vhost, app)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
|
|
@ -7,16 +7,15 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
URLRequestStatsVHost = "/v1/stats/current/vhosts/%s"
|
||||
URLRequestStatsApp = "/v1/stats/current/vhosts/%s/apps/%s"
|
||||
URLRequestStatsVHost = "/v1/stats/current/vhosts/%s"
|
||||
URLRequestStatsApp = "/v1/stats/current/vhosts/%s/apps/%s"
|
||||
URLRequestStatsStream = "/v1/stats/current/vhosts/%s/apps/%s/streams/%s"
|
||||
|
||||
)
|
||||
|
||||
type ResponseStats struct {
|
||||
Message string `json:"message"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
Data *ResponseStatsData `json:"response,omitempty"`
|
||||
Message string `json:"message"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
Data *ResponseStatsData `json:"response,omitempty"`
|
||||
}
|
||||
|
||||
type ResponseStatsData struct {
|
||||
|
@ -24,23 +23,22 @@ type ResponseStatsData struct {
|
|||
CreatedTime string `json:"createdTime" example:"2021-07-19T23:13:12.162+0200"`
|
||||
LastRecvTime string `json:"lastRecvTime" example:"2021-07-19T23:23:27.274+0200"`
|
||||
LastSentTime string `json:"lastSentTime" example:"2021-07-19T23:23:27.077+0200"`
|
||||
LastUpdatedTime string `json:"lastUpdatedTime" example:"2021-07-19T23:23:27.274+0200"`
|
||||
LastUpdatedTime string `json:"lastUpdatedTime" example:"2021-07-19T23:23:27.274+0200"`
|
||||
MaxTotalConnectionTime string `json:"maxTotalConnectionTime" example:"2021-07-19T23:16:37.851+0200"`
|
||||
// - coonnections
|
||||
TotalConnections int `json:"totalConnections" example:"1"`
|
||||
MaxTotalConnections int `json:"maxTotalConnections" example:"2"`
|
||||
TotalConnections int `json:"totalConnections" example:"1"`
|
||||
MaxTotalConnections int `json:"maxTotalConnections" example:"2"`
|
||||
// - traffic
|
||||
TotalBytesIn uint64 `json:"totalBytesIn" example:"120197570"`
|
||||
TotalBytesOut uint64 `json:"totalBytesOut" example:"117022184"`
|
||||
TotalBytesIn uint64 `json:"totalBytesIn" example:"120197570"`
|
||||
TotalBytesOut uint64 `json:"totalBytesOut" example:"117022184"`
|
||||
}
|
||||
|
||||
|
||||
func (resp *ResponseStats) Log(log *log.Entry) {
|
||||
logger := log
|
||||
if resp.Data != nil {
|
||||
logger.WithFields(map[string]interface{}{
|
||||
"max_clients": resp.Data.MaxTotalConnections,
|
||||
"clients": resp.Data.TotalConnections,
|
||||
"clients": resp.Data.TotalConnections,
|
||||
})
|
||||
}
|
||||
logger.Info(resp.Message)
|
||||
|
@ -48,7 +46,7 @@ func (resp *ResponseStats) Log(log *log.Entry) {
|
|||
func (c *configData) RequestStatsVHost(vhost string) (*ResponseStats, error) {
|
||||
req := ResponseStats{}
|
||||
url := fmt.Sprintf(URLRequestStatsVHost, vhost)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
@ -57,7 +55,7 @@ func (c *configData) RequestStatsVHost(vhost string) (*ResponseStats, error) {
|
|||
func (c *configData) RequestStatsApp(vhost, app string) (*ResponseStats, error) {
|
||||
req := ResponseStats{}
|
||||
url := fmt.Sprintf(URLRequestStatsApp, vhost, app)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
@ -66,7 +64,7 @@ func (c *configData) RequestStatsApp(vhost, app string) (*ResponseStats, error)
|
|||
func (c *configData) RequestStatsStream(vhost, app, stream string) (*ResponseStats, error) {
|
||||
req := ResponseStats{}
|
||||
url := fmt.Sprintf(URLRequestStatsStream, vhost, app, stream)
|
||||
if err := c.Request(url, &req); err != nil{
|
||||
if err := c.Request(url, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
|
|
Loading…
Reference in New Issue