-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcastflow.go
More file actions
87 lines (78 loc) · 2.37 KB
/
castflow.go
File metadata and controls
87 lines (78 loc) · 2.37 KB
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
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
var (
now = time.Now()
// db setting
flagRegion = flag.String("region", "ap-northeast-2", "AWS region name")
flagProfile = flag.String("profile", "lazypic", "AWS Credentials profile name")
flagTable = flag.String("table", "castflow", "AWS Dynamodb table name")
// mode and partition key
flagAdd = flag.Bool("add", false, "character addition mode")
flagSet = flag.Bool("set", false, "character update mode")
// date
flagHelp = flag.Bool("help", false, "print help")
// attributes
flagID = flag.String("id", "", "character name")
flagRegnum = flag.String("regnum", "", "registration number")
flagManager = flag.String("manager", "", "project start date")
flagFieldOfActivity = flag.String("foa", "", "field of activity")
flagConcept = flag.String("concept", "", "character concept")
flagStartDate = flag.String("start", now.Format(time.RFC3339), "project end date")
flagEmail = flag.String("email", "", "character e-mail")
flagSearchword = flag.String("search", "", "search word")
)
func main() {
log.SetPrefix("castflow: ")
log.SetFlags(0)
flag.Parse()
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{Region: aws.String(*flagRegion)},
Profile: *flagProfile,
}))
db := dynamodb.New(sess)
// 테이블이 존재하는지 점검하고 없다면 테이블을 생성한다.
if !validTable(*db, *flagTable) {
_, err := db.CreateTable(tableStruct(*flagTable))
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Println("Created table:", *flagTable)
fmt.Println("Please try again in one minute.")
os.Exit(0)
}
if *flagHelp {
flag.Usage()
}
if *flagAdd && *flagID != "" {
err := AddCharacter(*db)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
} else if *flagSet && *flagID != "" {
err := SetCharacter(*db)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
} else if *flagSearchword != "" {
err := GetCharacters(*db, *flagSearchword)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
} else {
flag.PrintDefaults()
}
}