Exemplo n.º 1
0
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()
}