-
Notifications
You must be signed in to change notification settings - Fork 1
/
passage.go
53 lines (45 loc) · 1.01 KB
/
passage.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
44
45
46
47
48
49
50
51
52
53
package passage
import (
"context"
"fmt"
"net/http"
)
// Passage is the main struct for the Passage SDK.
type Passage struct {
Auth *auth
User *user
}
// New creates a new Passage instance.
func New(appID string, apiKey string) (*Passage, error) {
client, err := NewClientWithResponses(
"https://api.passage.id/v1/",
withPassageVersion(),
withAPIKey(apiKey),
)
if err != nil {
return nil, err
}
auth, err := newAuth(appID, client)
if err != nil {
return nil, err
}
user := newUser(appID, client)
return &Passage{
User: user,
Auth: auth,
}, nil
}
func withPassageVersion() ClientOption {
return WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
req.Header.Set("Passage-Version", fmt.Sprintf("passage-go %s", version))
return nil
})
}
func withAPIKey(apiKey string) ClientOption {
return WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
if apiKey != "" {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
}
return nil
})
}