-
Notifications
You must be signed in to change notification settings - Fork 0
/
gjobctl.go
65 lines (55 loc) · 1.24 KB
/
gjobctl.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
package gjobctl
import (
"fmt"
"log"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"gopkg.in/yaml.v3"
)
type App struct {
config *AppConfig
}
func New() (*App, error) {
var app App
err := app.setup()
if err != nil {
log.Println(err)
}
return &app, nil
}
func (app *App) setup() error {
f, err := os.Open("gjobctl.yml")
if err != nil {
return fmt.Errorf("failed to open config file: %w", err)
}
defer f.Close()
// Config構造体にデシリアライズ
var conf AppConfig
if err := yaml.NewDecoder(f).Decode(&conf); err != nil {
return fmt.Errorf("failed to decode config file: %w", err)
}
app.config = &conf
return nil
}
func (app *App) getJobSettingFileName() string {
if app.config.JobSettingFile != "" {
return app.config.JobSettingFile
} else {
return app.config.JobName + ".json"
}
}
func (app *App) createAWSSession() (*session.Session, error) {
sess, err := session.NewSession(&aws.Config{
Region: &app.config.Region},
)
if err != nil {
return nil, fmt.Errorf("failed to create session: %w", err)
}
return sess, nil
}
type AppConfig struct {
Region string `yaml:"region"`
JobName string `yaml:"job_name"`
JobSettingFile string `yaml:"job_setting_file"`
}