stats

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2020 License: Apache-2.0 Imports: 7 Imported by: 1

README

elton-stats

Build Status

Route handle stats middleware for elton, it can get some information of route handle, such as status, consuming, size and etc.

package main

import (
	"bytes"
	"fmt"

	"github.com/vicanso/elton"

	stats "github.com/vicanso/elton-stats"
)

func main() {
	e := elton.New()

	e.Use(stats.New(stats.Config{
		OnStats: func(info *stats.Info, _ *elton.Context) {
			buf, _ := json.Marshal(info)
			fmt.Println(string(buf))
		},
	}))

	e.GET("/", func(c *elton.Context) (err error) {
		c.BodyBuffer = bytes.NewBufferString("abcd")
		return
	})
	err := e.ListenAndServe(":3000")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config Config) elton.Handler

New create a new stats middleware

Types

type Config

type Config struct {
	OnStats OnStats
	Skipper elton.Skipper
}

Config stats config

type Info

type Info struct {
	CID        string        `json:"cid,omitempty"`
	IP         string        `json:"ip,omitempty"`
	Method     string        `json:"method,omitempty"`
	Route      string        `json:"route,omitempty"`
	URI        string        `json:"uri,omitempty"`
	Status     int           `json:"status,omitempty"`
	Consuming  time.Duration `json:"consuming,omitempty"`
	Type       int           `json:"type,omitempty"`
	Size       int           `json:"size,omitempty"`
	Connecting uint32        `json:"connecting,omitempty"`
}

Info stats's info

type OnStats

type OnStats func(*Info, *elton.Context)

OnStats on stats function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL