// SetupContext initializes global WebRocket context, loads configuration // and all the vhosts data, and generates thean access cookie if its necessary. func SetupContext() { s.Start("Initializing context") ctx = webrocket.NewContext() if err := ctx.SetStorageDir(StorageDir); err != nil { s.Fail(err.Error(), true) } if NodeName != "" { if err := ctx.SetNodeName(NodeName); err != nil { s.Fail(err.Error(), true) } } s.Ok() s.Start("Locking node") if err := ctx.Lock(); err != nil { s.Fail(err.Error(), true) } s.Ok() s.Start("Loading configuration") if err := ctx.Load(); err != nil { s.Fail(err.Error(), true) } s.Ok() s.Start("Generating cookie") if err := ctx.GenerateCookie(false); err != nil { s.Fail(err.Error(), true) } s.Ok() }
func init() { os.RemoveAll("./_testdata") ctx = webrocket.NewContext() ctx.SetLog(log.New(bytes.NewBuffer([]byte{}), "", log.LstdFlags)) ctx.SetNodeName("test") ctx.SetStorageDir("./_testdata") ctx.Load() ctx.GenerateCookie(false) admin := ctx.NewAdminEndpoint(":8072") go admin.ListenAndServe() go ctx.NewWebsocketEndpoint(":8070").ListenAndServe() go ctx.NewBackendEndpoint(":8071").ListenAndServe() for !admin.IsAlive() { <-time.After(500 * time.Nanosecond) } }