-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcredentials.go
More file actions
40 lines (32 loc) · 835 Bytes
/
credentials.go
File metadata and controls
40 lines (32 loc) · 835 Bytes
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
// Copyright 2017 Josh Komoroske. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE.txt file.
package posh
import (
"fmt"
"os"
)
type Credentials struct {
Email string `json:"email"`
Password string `json:"password"`
}
func NewCredentials(email string, password string) *Credentials {
return &Credentials{
email,
password,
}
}
func NewEnvCredentials() (*Credentials, error) {
email, found := os.LookupEnv(EmailEnvironmentVariable)
if !found {
return nil, fmt.Errorf("no %s found in environment", EmailEnvironmentVariable)
}
password, found := os.LookupEnv(PasswordEnvironmentVariable)
if !found {
return nil, fmt.Errorf("no %s found in environment", PasswordEnvironmentVariable)
}
return &Credentials{
email,
password,
}, nil
}