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