()
| 17 | ) |
| 18 | |
| 19 | func main() { |
| 20 | flag.Parse() |
| 21 | |
| 22 | // Create a kite |
| 23 | k := kite.New("math", "1.0.0") |
| 24 | |
| 25 | // Add our handler method |
| 26 | k.HandleFunc("square", Square) |
| 27 | |
| 28 | // Get config from kite.Key directly, usually it's under ~/.kite/kite.key |
| 29 | c := config.MustGet() |
| 30 | k.Config = c |
| 31 | k.Config.Port = *flagPort |
| 32 | k.SetLogLevel(kite.DEBUG) |
| 33 | k.Id = c.Id |
| 34 | |
| 35 | // by default it's already WebSocket |
| 36 | if *flagTransport != "" && *flagTransport == "xhrpolling" { |
| 37 | k.Config.Transport = config.XHRPolling |
| 38 | } |
| 39 | |
| 40 | // Register to kite with this url |
| 41 | kiteURL := &url.URL{Scheme: "http", Host: "localhost:" + strconv.Itoa(*flagPort), Path: "/kite"} |
| 42 | |
| 43 | // Register us ... |
| 44 | err := k.RegisterForever(kiteURL) |
| 45 | if err != nil { |
| 46 | log.Fatal(err) |
| 47 | } |
| 48 | |
| 49 | // And finally attach to a server and run it |
| 50 | k.Run() |
| 51 | } |
| 52 | |
| 53 | func Square(r *kite.Request) (interface{}, error) { |
| 54 | // Unmarshal method arguments |
nothing calls this directly
no test coverage detected