-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (51 loc) · 1.16 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
package main
import (
"fmt"
"log"
"os"
mfst "github.com/fixate/redirect-server/manifest"
srv "github.com/fixate/redirect-server/server"
"github.com/urfave/cli"
)
const version string = "0.1.0"
func main() {
app := cli.NewApp()
app.Name = "redirect server"
app.Version = version
app.Usage = "Redirect according to yaml config"
app.Action = run
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "m, manifest",
Usage: "path to the redirect manifest",
EnvVar: "REDIRECT_MANIFEST_PATH",
},
cli.StringFlag{
Name: "b, bind",
Usage: "bind address",
EnvVar: "REDIRECT_BIND_ADDRESS",
Value: "0.0.0.0:3000",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
manifest := mfst.Manifest{}
manifestPath := c.String("manifest")
if len(manifestPath) == 0 {
return fmt.Errorf("Manifest path not specified")
}
if err := mfst.Load(manifestPath, &manifest); err != nil {
return err
}
bind := c.String("bind")
log.Printf("Starting server on %s\n", bind)
server := srv.NewServer(&srv.ServerOptions{
Manifest: &manifest,
Bind: bind,
})
panic(server.ListenAndServe())
return nil
}