Compare commits

..

No commits in common. "c10bf83c419eb5d85aa3170a7155cdc1a2152031" and "03c73750645222c25ae2f7d47a4e4b75719f7b0e" have entirely different histories.

2 changed files with 7 additions and 41 deletions

View File

@ -19,7 +19,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"log" "log"
"net/url" "net/url"
@ -30,10 +29,6 @@ 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)
} }
@ -107,8 +102,6 @@ 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" {
@ -163,9 +156,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
c.Logging = *verbose performCommands(&c, os.Args[1:])
performCommands(&c, flag.Args())
} }
func performCommands(sub microsub.Microsub, commands []string) { func performCommands(sub microsub.Microsub, commands []string) {

View File

@ -3,9 +3,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/http" "net/http"
"net/http/httputil"
"net/url" "net/url"
"strings" "strings"
@ -16,8 +14,6 @@ type Client struct {
Me *url.URL Me *url.URL
MicrosubEndpoint *url.URL MicrosubEndpoint *url.URL
Token string Token string
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,19 +34,7 @@ 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 { return client.Do(req)
x, _ := httputil.DumpRequestOut(req, true)
log.Printf("REQUEST:\n\n%s\n\n", x)
}
res, err := client.Do(req)
if c.Logging {
x, _ := httputil.DumpResponse(res, true)
log.Printf("RESPONSE:\n\n%s\n\n", x)
}
return res, err
} }
func (c *Client) microsubPostRequest(action string, args map[string]string) (*http.Response, error) { func (c *Client) microsubPostRequest(action string, args map[string]string) (*http.Response, error) {
@ -71,19 +55,7 @@ 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 { return client.Do(req)
x, _ := httputil.DumpRequestOut(req, true)
log.Printf("REQUEST:\n\n%s\n\n", x)
}
res, err := client.Do(req)
if c.Logging {
x, _ := httputil.DumpResponse(res, true)
log.Printf("RESPONSE:\n\n%s\n\n", x)
}
return res, err
} }
func (c *Client) microsubPostFormRequest(action string, args map[string]string, data url.Values) (*http.Response, error) { func (c *Client) microsubPostFormRequest(action string, args map[string]string, data url.Values) (*http.Response, error) {
@ -122,10 +94,13 @@ func (c *Client) ChannelsGetList() ([]microsub.Channel, error) {
dec := json.NewDecoder(res.Body) dec := json.NewDecoder(res.Body)
var channels channelsResponse var channels channelsResponse
err = dec.Decode(&channels) err = dec.Decode(&channels)
if err != nil {
return channels.Channels, err return channels.Channels, err
} }
return channels.Channels, nil
}
func (c *Client) TimelineGet(before, after, channel string) (microsub.Timeline, error) { func (c *Client) TimelineGet(before, after, channel string) (microsub.Timeline, error) {
args := make(map[string]string) args := make(map[string]string)
args["after"] = after args["after"] = after