tracker

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 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"
	"fmt"

	"github.com/vicanso/elton"

	bodyparser "github.com/vicanso/elton-body-parser"
	tracker "github.com/vicanso/elton-tracker"
)

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

	d.Use(bodyparser.NewDefault())

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

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

	d.ListenAndServe(":7001")
}

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

Jump to

Keyboard shortcuts

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