-
Notifications
You must be signed in to change notification settings - Fork 18
/
internal.go
34 lines (27 loc) · 916 Bytes
/
internal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package proton
import (
"bytes"
"context"
"strings"
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
)
// Quark runs a quark command.
func (m *Manager) Quark(ctx context.Context, command string, args ...string) error {
if _, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command); err != nil {
return err
}
return nil
}
// QuarkRes is the same as Quark, but returns the content extracted from the response body.
func (m *Manager) QuarkRes(ctx context.Context, command string, args ...string) ([]byte, error) {
res, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command)
if err != nil {
return nil, err
}
doc, err := html.Parse(bytes.NewReader(res.Body()))
if err != nil {
return nil, err
}
return []byte(strings.TrimSpace(goquery.NewDocumentFromNode(doc).Find(".content").Text())), nil
}