This commit is contained in:
parent
c23802216e
commit
c10bf83c41
|
@ -19,6 +19,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -29,6 +30,10 @@ import (
|
||||||
"p83.nl/go/ekster/pkg/microsub"
|
"p83.nl/go/ekster/pkg/microsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
verbose = flag.Bool("verbose", false, "show verbose logging")
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
|
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
|
||||||
}
|
}
|
||||||
|
@ -102,6 +107,8 @@ func loadEndpoints(c *client.Client, me *url.URL, filename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
configDir := fmt.Sprintf("%s/.config/microsub", os.Getenv("HOME"))
|
configDir := fmt.Sprintf("%s/.config/microsub", os.Getenv("HOME"))
|
||||||
|
|
||||||
if len(os.Args) == 3 && os.Args[1] == "connect" {
|
if len(os.Args) == 3 && os.Args[1] == "connect" {
|
||||||
|
@ -156,7 +163,9 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
performCommands(&c, os.Args[1:])
|
c.Logging = *verbose
|
||||||
|
|
||||||
|
performCommands(&c, flag.Args())
|
||||||
}
|
}
|
||||||
|
|
||||||
func performCommands(sub microsub.Microsub, commands []string) {
|
func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ type Client struct {
|
||||||
MicrosubEndpoint *url.URL
|
MicrosubEndpoint *url.URL
|
||||||
Token string
|
Token string
|
||||||
|
|
||||||
logging bool
|
Logging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) microsubGetRequest(action string, args map[string]string) (*http.Response, error) {
|
func (c *Client) microsubGetRequest(action string, args map[string]string) (*http.Response, error) {
|
||||||
|
@ -38,14 +38,14 @@ func (c *Client) microsubGetRequest(action string, args map[string]string) (*htt
|
||||||
|
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
||||||
|
|
||||||
if c.logging {
|
if c.Logging {
|
||||||
x, _ := httputil.DumpRequestOut(req, true)
|
x, _ := httputil.DumpRequestOut(req, true)
|
||||||
log.Printf("REQUEST:\n\n%s\n\n", x)
|
log.Printf("REQUEST:\n\n%s\n\n", x)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
if c.logging {
|
if c.Logging {
|
||||||
x, _ := httputil.DumpResponse(res, true)
|
x, _ := httputil.DumpResponse(res, true)
|
||||||
log.Printf("RESPONSE:\n\n%s\n\n", x)
|
log.Printf("RESPONSE:\n\n%s\n\n", x)
|
||||||
}
|
}
|
||||||
|
@ -71,14 +71,14 @@ func (c *Client) microsubPostRequest(action string, args map[string]string) (*ht
|
||||||
|
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
||||||
|
|
||||||
if c.logging {
|
if c.Logging {
|
||||||
x, _ := httputil.DumpRequestOut(req, true)
|
x, _ := httputil.DumpRequestOut(req, true)
|
||||||
log.Printf("REQUEST:\n\n%s\n\n", x)
|
log.Printf("REQUEST:\n\n%s\n\n", x)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
if c.logging {
|
if c.Logging {
|
||||||
x, _ := httputil.DumpResponse(res, true)
|
x, _ := httputil.DumpResponse(res, true)
|
||||||
log.Printf("RESPONSE:\n\n%s\n\n", x)
|
log.Printf("RESPONSE:\n\n%s\n\n", x)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user