forked from codemicro/readingList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 879 Bytes
/
main.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
package main
import (
"errors"
"fmt"
"os"
"time"
)
const readingListFile = "readingList.csv"
type readingListEntry struct {
URL string `csv:"url,omitempty"`
Title string `csv:"title,omitempty"`
Description string `csv:"description,omitempty"`
Image string `csv:"image,omitempty"`
Date time.Time `csv:"date,omitempty"`
HackerNewsURL string `csv:"hnurl,omitempty"`
}
func run() error {
if len(os.Args) == 1 || !(os.Args[1] == "add" || os.Args[1] == "generateSite") {
return fmt.Errorf("usage: %s [add|generateSite]", os.Args[0])
}
var f func() error
switch os.Args[1] {
case "add":
f = AddRowToCSV
case "generateSite":
f = GenerateSite
default:
return errors.New("unreachable")
}
return f()
}
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}