muxtrace

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: GPL-3.0 Imports: 5 Imported by: 0

README

muxtrace

Gorilla Logo

A mux wrapper with opentracer



Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Things you need to use the package

  • Gorilla Mux - Router and dispatcher
  • Opentracing - Vendor-neutral APIs and instrumentation for distributed tracing
Installing

With go:

$ go get -u github.com/anthonyhartanto/muxtrace

Example

package main

import (
    "fmt"
    "github.com/anthonyhartanto/muxtrace"
    "net/http"
)

func main() {

    router := muxtrace.NewRouter()
    
    // Run server
    server := &http.Server{
        Addr:    ":8080",
        Handler: router,
    }
    server.ListenAndServe()
}

Built With

  • Go - The language used

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TraceAndServe

func TraceAndServe(h http.Handler, w http.ResponseWriter, r *http.Request, service, resource string, spanopts ...opentracing.StartSpanOption)

TraceAndServe will apply tracing to the given http.Handler using the passed tracer under the given service and resource.

Types

type Router

type Router struct {
	*mux.Router
	// contains filtered or unexported fields
}

Router registers routes to be matched and dispatches a handler.

func NewRouter

func NewRouter(opts ...RouterOption) *Router

NewRouter returns a new router instance traced with the global tracer.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. We only need to rewrite this function to be able to trace all the incoming requests to the underlying multiplexer

func (*Router) SkipClean

func (r *Router) SkipClean(value bool) *Router

SkipClean defines the path cleaning behaviour for new routes. The initial value is false. Users should be careful about which routes are not cleaned

When true, if the route path is "/path//to", it will remain with the double slash. This is helpful if you have a route like: /fetch/http://xkcd.com/534/

When false, the path will be cleaned, so /fetch/http://xkcd.com/534/ will become /fetch/http/xkcd.com/534

func (*Router) StrictSlash

func (r *Router) StrictSlash(value bool) *Router

StrictSlash defines the trailing slash behavior for new routes. The initial value is false.

When true, if the route path is "/path/", accessing "/path" will perform a redirect to the former and vice versa. In other words, your application will always see the path as specified in the route.

When false, if the route path is "/path", accessing "/path/" will not match this route and vice versa.

The re-direct is a HTTP 301 (Moved Permanently). Note that when this is set for routes with a non-idempotent method (e.g. POST, PUT), the subsequent re-directed request will be made as a GET by most clients. Use middleware or client settings to modify this behaviour as needed.

Special case: when a route sets a path prefix using the PathPrefix() method, strict slash is ignored for that route because the redirect behavior can't be determined from a prefix alone. However, any subrouters created from that route inherit the original StrictSlash setting.

func (*Router) UseEncodedPath

func (r *Router) UseEncodedPath() *Router

UseEncodedPath tells the router to match the encoded original path to the routes. For eg. "/path/foo%2Fbar/to" will match the path "/path/{var}/to".

If not called, the router will match the unencoded path to the routes. For eg. "/path/foo%2Fbar/to" will match the path "/path/foo/bar/to"

type RouterOption

type RouterOption func(*routerConfig)

RouterOption represents an option that can be passed to NewRouter.

func WithServiceName

func WithServiceName(name string) RouterOption

WithServiceName sets the given service name for the router.

func WithSpanOptions

func WithSpanOptions(opts ...opentracing.StartSpanOption) RouterOption

WithSpanOptions applies the given set of options to the spans started by the router.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL