-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
49 lines (42 loc) · 887 Bytes
/
env.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
package main
import (
"errors"
"log"
)
const (
TOKEN_ENV_KEY = "GITHUB_PAT"
GITHUB_HANDLER_ENV_KEY = "GITHUB_HANDLER"
)
type Env struct {
GITHUB_HOST *string
GITHUB_PAT *string
GITHUB_HANDLER *string
}
func (e Env) getToken() (*string, error) {
token, isSet := wf.Config.Env.Lookup(TOKEN_ENV_KEY)
if !isSet {
return nil, errors.New("token is not set as environment variable")
}
return &token, nil
}
func (e Env) getHandler() (*string, error) {
handler, ok := wf.Config.Env.Lookup(GITHUB_HANDLER_ENV_KEY)
if !ok {
return nil, errors.New("github handler is not specified")
}
return &handler, nil
}
func (e Env) New() Env {
env := Env{}
token, err := env.getToken()
if err != nil {
log.Fatalln(err)
}
env.GITHUB_PAT = token
handler, err := env.getHandler()
if err != nil {
log.Fatalln(err)
}
env.GITHUB_HANDLER = handler
return env
}