generated from golang-templates/seed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
33 lines (30 loc) · 1.02 KB
/
auth.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
// Package desec provides generic client code for the deSEC DNS server API
package desec
import (
"context"
"fmt"
"net/http"
)
// NewAuthClient creates a new Client, with the server's required authtoken and reasonable defaults.
func NewAuthClient(server string, authtoken string, opts ...ClientOption) (*Client, error) {
return NewClient(
server,
append(
[]ClientOption{WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Token %s", authtoken))
return nil
})},
opts...,
)...,
)
}
// NewAuthClientWithResponses creates a new ClientWithResponses, which wraps
// Client with return type handling and the server's required authtoken.
func NewAuthClientWithResponses(server string, authtoken string, opts ...ClientOption) (*ClientWithResponses, error) {
client, err := NewAuthClient(server, authtoken, opts...)
if err != nil {
return nil, err
}
return &ClientWithResponses{client}, nil
}