-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsession.go
More file actions
40 lines (32 loc) · 790 Bytes
/
session.go
File metadata and controls
40 lines (32 loc) · 790 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 Session struct {
UserID string `json:"user-id"`
Token string `json:"token"`
}
func NewSession(userID string, token string) *Session {
return &Session{
userID,
token,
}
}
func NewEnvSession() (*Session, error) {
userID, found := os.LookupEnv(UserIDEnvironmentVariable)
if !found {
return nil, fmt.Errorf("no %s found in environment", UserIDEnvironmentVariable)
}
token, found := os.LookupEnv(TokenEnvironmentVariable)
if !found {
return nil, fmt.Errorf("no %s found in environment", TokenEnvironmentVariable)
}
return &Session{
userID,
token,
}, nil
}