tracker

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: Apache-2.0 Imports: 4 Imported by: 1

README

elton-tracker

Build Status

Tracker middleware for elton, it can track route params, include query, params, form and handle result.

package main

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/vicanso/elton"

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

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

	loginTracker := tracker.New(tracker.Config{
		OnTrack: func(info *tracker.Info, _ *elton.Context) {
			buf, _ := json.Marshal(info)
			fmt.Println(string(buf))
		},
	})

	e.Use(func(c *elton.Context) error {
		c.RequestBody = []byte(`{
			"account": "tree.xie",
			"password": "123456"
		}`)
		return c.Next()
	})

	e.POST("/user/login", loginTracker, func(c *elton.Context) (err error) {
		c.SetHeader(elton.HeaderContentType, elton.MIMEApplicationJSON)
		c.BodyBuffer = bytes.NewBuffer(c.RequestBody)
		return
	})

	err := e.ListenAndServe(":3000")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	// HandleSuccess handle success
	HandleSuccess = iota
	// HandleFail handle fail
	HandleFail
)

Variables

This section is empty.

Functions

func New

func New(config Config) elton.Handler

New create a tracker middleware

Types

type Config

type Config struct {
	OnTrack OnTrack
	Mask    *regexp.Regexp
	Skipper elton.Skipper
}

Config tracker config

type Info

type Info struct {
	CID    string                 `json:"cid,omitempty"`
	Query  map[string]string      `json:"query,omitempty"`
	Params map[string]string      `json:"params,omitempty"`
	Form   map[string]interface{} `json:"form,omitempty"`
	Result int                    `json:"result,omitempty"`
	Err    error                  `json:"err,omitempty"`
}

Info tracker info

type OnTrack

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

OnTrack on track function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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