This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
forked from thoas/picfit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (82 loc) · 2.06 KB
/
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
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
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/honeybadger-io/honeybadger-go"
"github.com/lizdeika/picfit/application"
"github.com/lizdeika/picfit/signature"
)
func main() {
honeybadger.Configure(honeybadger.Configuration{APIKey: "11b9f693"})
defer honeybadger.Monitor()
app := cli.NewApp()
app.Name = "picfit"
app.Author = "thoas"
app.Email = "[email protected]"
app.Usage = "Display, manipulate, transform and cache your images"
app.Version = application.Version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Config file path",
EnvVar: "PICFIT_CONFIG_PATH",
},
}
app.Commands = []cli.Command{
{
Name: "version",
ShortName: "v",
Usage: "Retrieve the version number",
Action: func(c *cli.Context) {
fmt.Printf("picfit %s\n", application.Version)
},
},
{
Name: "signature",
ShortName: "s",
Usage: "Verify that your client application is generating correct signatures",
Flags: []cli.Flag{
cli.StringFlag{
Name: "key",
Usage: "The signing key",
},
},
Action: func(c *cli.Context) {
key := c.String("key")
if key == "" {
fmt.Fprintf(os.Stderr, "You must provide a key\n")
os.Exit(1)
}
if len(c.Args()) < 1 {
fmt.Fprintf(os.Stderr, "You must provide a Query String\n")
os.Exit(1)
}
qs := c.Args()[0]
sig := signature.Sign(key, qs)
appended := signature.AppendSign(key, qs)
fmt.Fprintf(os.Stdout, "Query String: %s\n", qs)
fmt.Fprintf(os.Stdout, "Signature: %s\n", sig)
fmt.Fprintf(os.Stdout, "Signed Query String: %s\n", appended)
},
},
}
app.Action = func(c *cli.Context) {
config := c.String("config")
if config != "" {
if _, err := os.Stat(config); err != nil {
fmt.Fprintf(os.Stderr, "Can't find config file `%s`\n", config)
os.Exit(1)
}
} else {
fmt.Fprintf(os.Stderr, "Can't find config file\n")
os.Exit(1)
}
err := application.Run(config)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
}
app.Run(os.Args)
}