(name string, conf *Config)
| 97 | } |
| 98 | |
| 99 | func NewHelloKite(name string, conf *Config) (*HelloKite, error) { |
| 100 | k := kite.New(name, "1.0.0") |
| 101 | k.Config = conf.Config.Copy() |
| 102 | k.Config.Port = 0 |
| 103 | k.Config.KiteKey = testutil.NewToken(name, conf.Private, conf.Public).Raw |
| 104 | // k.SetLogLevel(kite.DEBUG) |
| 105 | |
| 106 | k.HandleFunc("hello", func(r *kite.Request) (interface{}, error) { |
| 107 | return fmt.Sprintf("%s says hello", name), nil |
| 108 | }) |
| 109 | |
| 110 | go k.Run() |
| 111 | <-k.ServerReadyNotify() |
| 112 | |
| 113 | u := &url.URL{ |
| 114 | Scheme: "http", |
| 115 | Host: fmt.Sprintf("127.0.0.1:%d", k.Port()), |
| 116 | Path: "/kite", |
| 117 | } |
| 118 | |
| 119 | hk := &HelloKite{ |
| 120 | Kite: k, |
| 121 | URL: u, |
| 122 | clients: make(map[string]*kite.Client), |
| 123 | regs: make(chan *protocol.RegisterResult, 16), |
| 124 | toks: make(chan struct{}, 16), |
| 125 | renew: make(chan struct{}, 16), |
| 126 | } |
| 127 | |
| 128 | hk.Kite.OnRegister(hk.onRegister) |
| 129 | |
| 130 | if err := conf.Register(hk); err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | |
| 134 | return hk, nil |
| 135 | } |
| 136 | |
| 137 | func (hk *HelloKite) onRegister(reg *protocol.RegisterResult) { |
| 138 | hk.regs <- reg |
no test coverage detected