This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
91 lines (83 loc) · 2.05 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
/*
This is an asgi protocol server and should be an alternative to daphne.
*/
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
"github.com/ostcar/geiss/asgi"
"github.com/ostcar/geiss/asgi/redis"
)
var channelLayer asgi.ChannelLayer
var debug bool
// Version to show in the help text and the --version flag. It is not set
// directly in the sourcecode but set at complite time with
// go build -ldflags "-X main.Version=1.0.0
var Version = "development"
func main() {
app := cli.NewApp()
app.Name = "geiss"
app.Usage = "an asgi protocol server"
app.HideHelp = true
app.Version = Version
app.ArgsUsage = " " // If it is an empty string, then it shows a stupid default text
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "host, H",
Value: "localhost",
Usage: "host to listen on",
},
cli.IntFlag{
Name: "port, p",
Value: 8000,
Usage: "port to listen on",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "if set, sends error messages to the client",
Destination: &debug,
},
cli.StringSliceFlag{
Name: "static, s",
Value: nil,
Usage: "url and file path to serve static files in the form /static/:/path/to/files",
},
cli.StringFlag{
Name: "redis, r",
Value: ":6379",
Usage: "host and port of the redis server in the form HOST:Port",
},
cli.StringFlag{
Name: "redis-prefix",
Value: "asgi:",
Usage: "prefix of the redis keys",
},
cli.IntFlag{
Name: "redis-capacity",
Value: 100,
Usage: "channel capacity",
},
cli.IntFlag{
Name: "redis-expiry",
Value: 60,
Usage: "seconds until a message to the redis channel layer will expire",
},
}
app.Action = func(c *cli.Context) error {
channelLayer = redis.NewChannelLayer(
c.Int("redis-expiry"),
c.String("redis"),
c.String("redis-prefix"),
c.Int("redis-capacity"))
go globalReceive()
startHTTPServer(
fmt.Sprintf("%s:%d", c.String("host"), c.Int64("port")),
c.StringSlice("static"))
return nil
}
if err := app.Run(os.Args); err != nil {
log.Fatalf("Received an error: %s", err)
}
}