-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
78 lines (67 loc) · 1.82 KB
/
client.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package go_archivematica
import (
"fmt"
"net/http"
"os"
"time"
"gopkg.in/yaml.v2"
)
type AMClient struct {
Username string
AMHost string
AMAPIKey string
SSHost string
SSAPIKey string
Client *http.Client
StagingLoc string
SSUserID string
SSUserEmail string
AIPStoreLocation string
}
func (a *AMClient) String() string {
return fmt.Sprintf("\nUsername\t%s\nAMHost\t\t%s\nSSHost\t\t%s", a.Username, a.AMHost, a.SSHost)
}
type AMEnvironment struct {
AMURL string `yaml:"am_url"`
SSURL string `yaml:"ss_url"`
Username string `yaml:"username"`
AMAPIKey string `yaml:"am_api_key"`
SSAPIKey string `yaml:"ss_api_key"`
StagingLoc string `yaml:"staging_location"`
SSUserID string `yaml:"ss_user_id"`
SSUserEmail string `yaml:"ss_user_email"`
AIPStoreLocation string `yaml:"aip_store_location"`
}
func NewAMClient(config string, timeout int) (*AMClient, error) {
transport := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: time.Duration(timeout) * time.Second,
DisableCompression: true,
}
nclient := &http.Client{
Transport: transport,
}
configBytes, err := os.ReadFile(config)
if err != nil {
return nil, err
}
var amEnv AMEnvironment
if err := yaml.Unmarshal(configBytes, &amEnv); err != nil {
return nil, err
}
return &AMClient{
Username: amEnv.Username,
AMHost: amEnv.AMURL,
SSHost: amEnv.SSURL,
AMAPIKey: amEnv.AMAPIKey,
SSAPIKey: amEnv.SSAPIKey,
Client: nclient,
StagingLoc: amEnv.StagingLoc,
SSUserID: amEnv.SSUserID,
SSUserEmail: amEnv.SSUserEmail,
AIPStoreLocation: amEnv.AIPStoreLocation,
}, nil
}
func (a *AMClient) GetVersion() string {
return version
}