-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
43 lines (32 loc) · 838 Bytes
/
session.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
35
36
37
38
39
40
41
42
43
//go:generate go run tools/withoutctx.go
package redash
import (
"context"
"github.com/winebarrel/redash-go/v2/internal/util"
)
type Session struct {
ClientConfig ClientConfig `json:"client_config"`
Messages []string `json:"messages"`
OrgSlug string `json:"org_slug"`
User User `json:"user"`
}
func (client *Client) TestCredentials(ctx context.Context) error {
_, close, err := client.Get(ctx, "api/session", nil)
defer close()
if err != nil {
return err
}
return nil
}
func (client *Client) GetSession(ctx context.Context) (*Session, error) {
res, close, err := client.Get(ctx, "api/session", nil)
defer close()
if err != nil {
return nil, err
}
session := &Session{}
if err := util.UnmarshalBody(res, &session); err != nil {
return nil, err
}
return session, nil
}