diff options
Diffstat (limited to 'skate/cmd')
-rw-r--r-- | skate/cmd/skate-dot/main.go | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/skate/cmd/skate-dot/main.go b/skate/cmd/skate-dot/main.go deleted file mode 100644 index 573209e..0000000 --- a/skate/cmd/skate-dot/main.go +++ /dev/null @@ -1,74 +0,0 @@ -// [wip] skate-dot generates dot files from inbound and outbound citation -// links. Just a demo, replacement for a couple python scripts. We want things -// like: https://git.io/JObzq. -package main - -import ( - "context" - "flag" - "fmt" - "io" - "log" - "os" - - "github.com/elastic/go-elasticsearch/esapi" - elasticsearch "github.com/elastic/go-elasticsearch/v7" -) - -var ( - es = flag.String("es", "http://localhost:9200", "elasticsearch holding fatcat_ref index") - index = flag.String("x", "fatcat_ref_v01", "index name") - fatcat = flag.String("f", "https://api.fatcat.wiki/v0", "fatcat api") - ident = flag.String("i", "2kw3xjf2cbcmdlm3ihkoz2t4lu", "release ident") -) - -func main() { - flag.Parse() - cfg := elasticsearch.Config{Addresses: []string{*es}} - es, err := elasticsearch.NewClient(cfg) - if err != nil { - log.Fatal(err) - } - client := &Client{ - Api: *fatcat, - Es: es, - Index: *index, - } - client.Outbound(*ident) -} - -// A client for fatcat and elasticsearch. -type Client struct { - Api string - Es *elasticsearch.Client - Index string -} - -func (c *Client) String() string { - info, _ := c.Es.Info() - return fmt.Sprintf("%s %s (%s) %s", c.Api, info, elasticsearch.Version, c.Index) -} - -func (c *Client) Inbound(ident string) []string { - resp, err := c.Es.Search( - c.Es.Search.WithContext(context.Background()), - c.Es.Search.WithIndex(c.Index), - ) - if err != nil { - log.Fatal(err) - } - io.Copy(os.Stdout, resp.Body) - return nil -} - -func (c *Client) Outbound(ident string) []string { - req := &esapi.SearchRequest{ - Query: fmt.Sprintf("source_release_ident:%s", ident), - } - resp, err := req.Do(context.Background(), c.Es) - if err != nil { - log.Fatal(err) - } - io.Copy(os.Stdout, resp.Body) - return nil -} |