MCPcopy Index your code
hub / github.com/koding/kite / NewWithConfig

Function NewWithConfig

kite.go:168–229  ·  view source on GitHub ↗

NewWithConfig builds a new kite value for the given configuration.

(name, version string, cfg *config.Config)

Source from the content-addressed store, hash-verified

166
167// NewWithConfig builds a new kite value for the given configuration.
168func NewWithConfig(name, version string, cfg *config.Config) *Kite {
169 if name == "" {
170 panic("kite: name cannot be empty")
171 }
172
173 if digits := strings.Split(version, "."); len(digits) != 3 {
174 panic("kite: version must be 3-digits semantic version")
175 }
176
177 kiteID := uuid.Must(uuid.NewV4())
178
179 l, setlevel := newLogger(name)
180
181 kClient := &kontrolClient{
182 readyConnected: make(chan struct{}),
183 readyRegistered: make(chan struct{}),
184 registerChan: make(chan *url.URL, 1),
185 }
186
187 k := &Kite{
188 Config: cfg,
189 Log: l,
190 SetLogLevel: setlevel,
191 Authenticators: make(map[string]func(*Request) error),
192 handlers: make(map[string]*Method),
193 kontrol: kClient,
194 name: name,
195 version: version,
196 Id: kiteID.String(),
197 readyC: make(chan bool),
198 closeC: make(chan bool),
199 heartbeatC: make(chan *heartbeatReq, 1),
200 muxer: mux.NewRouter(),
201 }
202
203 if cfg != nil && cfg.UseWebRTC {
204 k.WebRTCHandler = NewWebRCTHandler()
205 }
206
207 // All sockjs communication is done through this endpoint..
208 k.muxer.PathPrefix("/kite").Handler(sockjs.NewHandler("/kite", *cfg.SockJS, k.sockjsHandler))
209
210 // Add useful debug logs
211 k.OnConnect(func(c *Client) { k.Log.Debug("New session: %s", c.session.ID()) })
212 k.OnFirstRequest(func(c *Client) { k.Log.Debug("Session %q is identified as %q", c.session.ID(), c.Kite) })
213 k.OnDisconnect(func(c *Client) { k.Log.Debug("Kite has disconnected: %q", c.Kite) })
214 k.OnRegister(k.updateAuth)
215
216 // Every kite should be able to authenticate the user from token.
217 // Tokens are granted by Kontrol Kite.
218 k.Authenticators["token"] = k.AuthenticateFromToken
219
220 // A kite accepts requests with the same username.
221 k.Authenticators["kiteKey"] = k.AuthenticateFromKiteKey
222
223 // Register default methods and handlers.
224 k.addDefaultHandlers()
225

Callers 1

NewFunction · 0.85

Calls 11

OnConnectMethod · 0.95
OnFirstRequestMethod · 0.95
OnDisconnectMethod · 0.95
OnRegisterMethod · 0.95
addDefaultHandlersMethod · 0.95
processHeartbeatsMethod · 0.95
newLoggerFunction · 0.85
NewWebRCTHandlerFunction · 0.85
DebugMethod · 0.80
StringMethod · 0.45
IDMethod · 0.45

Tested by

no test coverage detected