func (i *iriscontrol) listen(f *iris.Framework) { // set the path logger to the parent which will send the log via websocket to the browser f.MustUseFunc(func(ctx *iris.Context) { status := ctx.Response.StatusCode() path := ctx.PathString() method := ctx.MethodString() subdomain := ctx.Subdomain() ip := ctx.RemoteAddr() startTime := time.Now() ctx.Next() //no time.Since in order to format it well after endTime := time.Now() date := endTime.Format("01/02 - 15:04:05") latency := endTime.Sub(startTime) info := logInfo{ Date: date, Status: status, Latency: latency, IP: ip, Method: method, Subdomain: subdomain, Path: path, } i.Emit("log", info) //send this text to the browser, }) i.parent = f i.parentLastOp = time.Now() i.initializeChild() }
// New Prepares and returns a new test framework based on the api // is useful when you need to have more than one test framework for the same iris instance // usage: // iris.Get("/mypath", func(ctx *iris.Context){ctx.Write("my body")}) // ... // e := httptest.New(iris.Default, t) // e.GET("/mypath").Expect().Status(iris.StatusOK).Body().Equal("my body") // // You can find example on the https://github.com/kataras/iris/glob/master/context_test.go func New(api *iris.Framework, t *testing.T, setters ...OptionSetter) *httpexpect.Expect { conf := DefaultConfiguration() for _, setter := range setters { setter.Set(conf) } api.Set(iris.OptionDisableBanner(true)) baseURL := "" if !api.Plugins.PreBuildFired() { api.Build() } if !conf.ExplicitURL { baseURL = api.Config.VScheme + api.Config.VHost // if it's still empty then set it to the default server addr if baseURL == "" { baseURL = iris.SchemeHTTP + iris.DefaultServerAddr } } testConfiguration := httpexpect.Config{ BaseURL: baseURL, Client: &http.Client{ Transport: httpexpect.NewFastBinder(api.Router), Jar: httpexpect.NewJar(), }, Reporter: httpexpect.NewAssertReporter(t), } if conf.Debug { testConfiguration.Printers = []httpexpect.Printer{ httpexpect.NewDebugPrinter(t, true), } } return httpexpect.WithConfig(testConfiguration) }