blademaster

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 41 Imported by: 0

README

net/http/blademaster

Blazing fast http framework for humans

项目简介

来自 bilibili 主站技术部的 http 框架,融合主站技术部的核心科技,带来如飞一般的体验。

项目特点

  • 模块化设计,核心足够轻量

编译环境

  • 请只用 Golang v1.8.x 以上版本编译执行

依赖包

  • No other dependency

Documentation

Overview

Example

This example start a http server and listen at port 8080, it will handle '/ping' and return response in html text

package main

import (
	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()
	engine.GET("/ping", func(c *blademaster.Context) {
		c.String(200, "%s", "pong")
	})
	engine.Run(":8080")
}
Output:

Index

Examples

Constants

View Source
const (
	// PlatAndroid is int8 for android.
	PlatAndroid = int8(0)
	// PlatIPhone is int8 for iphone.
	PlatIPhone = int8(1)
	// PlatIPad is int8 for ipad.
	PlatIPad = int8(2)
	// PlatWPhone is int8 for wphone.
	PlatWPhone = int8(3)
	// PlatAndroidG is int8 for Android Global.
	PlatAndroidG = int8(4)
	// PlatIPhoneI is int8 for Iphone Global.
	PlatIPhoneI = int8(5)
	// PlatIPadI is int8 for IPAD Global.
	PlatIPadI = int8(6)
	// PlatAndroidTV is int8 for AndroidTV Global.
	PlatAndroidTV = int8(7)
	// PlatAndroidI is int8 for Android Global.
	PlatAndroidI = int8(8)
	// PlatAndroidB is int8 for Android Blue.
	PlatAndroidB = int8(9)
	// PlatIPhoneB is int8 for Ios Blue
	PlatIPhoneB = int8(10)
	// PlatBilistudio is int8 for bilistudio
	PlatBilistudio = int8(11)
	// PlatAndroidTVYST is int8 for AndroidTV_YST Global.
	PlatAndroidTVYST = int8(12)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Key    string
	Secret string
}

App bilibili intranet authorization.

type CORSConfig

type CORSConfig struct {
	AllowAllOrigins bool

	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// Default value is []
	AllowOrigins []string

	// AllowOriginFunc is a custom function to validate the origin. It take the origin
	// as argument and returns true if allowed or false otherwise. If this option is
	// set, the content of AllowedOrigins is ignored.
	AllowOriginFunc func(origin string) bool

	// AllowedMethods is a list of methods the client is allowed to use with
	// cross-domain requests. Default value is simple methods (GET and POST)
	AllowMethods []string

	// AllowedHeaders is list of non simple headers the client is allowed to use with
	// cross-domain requests.
	AllowHeaders []string

	// AllowCredentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates.
	AllowCredentials bool

	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
	// API specification
	ExposeHeaders []string

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached
	MaxAge time.Duration
}

CORSConfig represents all available options for the middleware.

func (*CORSConfig) Validate

func (c *CORSConfig) Validate() error

Validate is check configuration of user defined.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is http client.

func NewClient

func NewClient(c *ClientConfig) *Client

NewClient new a http client.

func (*Client) Do

func (client *Client) Do(c context.Context, req *xhttp.Request, res interface{}, v ...string) (err error)

Do sends an HTTP request and returns an HTTP json response.

func (*Client) Get

func (client *Client) Get(c context.Context, uri, ip string, params url.Values, res interface{}) (err error)

Get issues a GET to the specified URL.

func (*Client) JSON

func (client *Client) JSON(c context.Context, req *xhttp.Request, res interface{}, v ...string) (err error)

JSON sends an HTTP request and returns an HTTP json response.

func (*Client) NewRequest

func (client *Client) NewRequest(method, uri, realIP string, params url.Values) (req *xhttp.Request, err error)

NewRequest new http request with method, uri, ip, values and headers. TODO(zhoujiahui): param realIP should be removed later.

func (*Client) PB

func (client *Client) PB(c context.Context, req *xhttp.Request, res proto.Message, v ...string) (err error)

PB sends an HTTP request and returns an HTTP proto response.

func (*Client) Post

func (client *Client) Post(c context.Context, uri, ip string, params url.Values, res interface{}) (err error)

Post issues a Post to the specified URL.

func (*Client) RESTfulGet

func (client *Client) RESTfulGet(c context.Context, uri, ip string, params url.Values, res interface{}, v ...interface{}) (err error)

RESTfulGet issues a RESTful GET to the specified URL.

func (*Client) RESTfulPost

func (client *Client) RESTfulPost(c context.Context, uri, ip string, params url.Values, res interface{}, v ...interface{}) (err error)

RESTfulPost issues a RESTful Post to the specified URL.

func (*Client) Raw

func (client *Client) Raw(c context.Context, req *xhttp.Request, v ...string) (bs []byte, err error)

Raw sends an HTTP request and returns bytes response

func (*Client) SetConfig

func (client *Client) SetConfig(c *ClientConfig)

SetConfig set client config.

func (*Client) SetTransport

func (client *Client) SetTransport(t xhttp.RoundTripper)

SetTransport set client transport

type ClientConfig

type ClientConfig struct {
	*App
	Dial      xtime.Duration
	Timeout   xtime.Duration
	KeepAlive xtime.Duration
	Breaker   *breaker.Config
	URL       map[string]*ClientConfig
	Host      map[string]*ClientConfig
}

ClientConfig is http client conf.

type Context

type Context struct {
	context.Context

	Request *http.Request
	Writer  http.ResponseWriter

	// Keys is a key/value pair exclusively for the context of each request.
	Keys map[string]interface{}

	Error error
	// contains filtered or unexported fields
}

Context is the most important part. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.

func (*Context) Abort

func (c *Context) Abort()

Abort prevents pending handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers for this request are not called.

Example

This example show how to protect your handlers by HTTP basic auth, it will validate the baisc auth and abort with status 403 if authentication is invalid

package main

import (
	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()
	engine.UseFunc(func(c *blademaster.Context) {
		user, pass, isok := c.Request.BasicAuth()
		if !isok || user != "root" || pass != "root" {
			c.AbortWithStatus(403)
			return
		}
	})

	engine.GET("/auth", func(c *blademaster.Context) {
		c.String(200, "%s", "Welcome")
	})

	engine.Run(":8080")
}
Output:

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus calls `Abort()` and writes the headers with the specified status code. For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).

func (*Context) Bind

func (c *Context) Bind(obj interface{}) error

Bind bind req arg with defult form binding.

Example

This example show how to using the default parameter binding to parse the url param from get request, it will validate the request and abort with status 400 if params is invalid

package main

import (
	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()
	engine.GET("/bind", func(c *blademaster.Context) {
		v := new(struct {
			// This mark field `mids` should exist and every element should greater than 1
			Mids    []int64 `form:"mids" validate:"dive,gt=1,required"`
			Title   string  `form:"title" validate:"required"`
			Content string  `form:"content"`
			// This mark field `cid` should between 1 and 10
			Cid int `form:"cid" validate:"min=1,max=10"`
		})

		err := c.Bind(v)
		if err != nil {
			// Do not call any write response method in this state,
			// the response body is already written in `c.BindWith` method
			return
		}
		c.String(200, "parse params by bind %+v", v)
	})

	engine.Run(":8080")
}
Output:

func (*Context) BindWith

func (c *Context) BindWith(obj interface{}, b binding.Binding) error

BindWith bind req arg with parser.

Example

This example show how to using the json binding to parse the json param from post request body, it will validate the request and abort with status 400 if params is invalid

package main

import (
	"go-common/library/net/http/blademaster"
	"go-common/library/net/http/blademaster/binding"
)

func main() {
	engine := blademaster.Default()
	engine.POST("/bindwith", func(c *blademaster.Context) {
		v := new(struct {
			// This mark field `mids` should exist and every element should greater than 1
			Mids    []int64 `json:"mids" validate:"dive,gt=1,required"`
			Title   string  `json:"title" validate:"required"`
			Content string  `json:"content"`
			// This mark field `cid` should between 1 and 10
			Cid int `json:"cid" validate:"min=1,max=10"`
		})

		err := c.BindWith(v, binding.JSON)
		if err != nil {
			// Do not call any write response method in this state,
			// the response body is already written in `c.BindWith` method
			return
		}
		c.String(200, "parse params by bindwith %+v", v)
	})

	engine.Run(":8080")
}
Output:

func (*Context) Bytes

func (c *Context) Bytes(code int, contentType string, data ...[]byte)

Bytes writes some data into the body stream and updates the HTTP code.

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted returns true if the current context was aborted.

func (*Context) JSON

func (c *Context) JSON(data interface{}, err error)

JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".

Example

This example show how to render response in json format, it will render structures as json like: `{"code":0,"message":"0","data":{"Time":"2017-11-14T23:03:22.0523199+08:00"}}`

package main

import (
	"time"

	"go-common/library/net/http/blademaster"
)

func main() {
	type Data struct {
		Time time.Time
	}

	engine := blademaster.Default()

	engine.GET("/ping", func(c *blademaster.Context) {
		var d Data
		d.Time = time.Now()
		c.JSON(d, nil)
	})

	engine.Run(":8080")
}
Output:

func (*Context) JSONMap

func (c *Context) JSONMap(data map[string]interface{}, err error)

JSONMap serializes the given map as map JSON into the response body. It also sets the Content-Type as "application/json".

func (*Context) Next

func (c *Context) Next()

Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler. See example in godoc.

func (*Context) Protobuf

func (c *Context) Protobuf(data proto.Message, err error)

Protobuf serializes the given struct as PB into the response body. It also sets the ContentType as "application/x-protobuf".

Example

This example show how to render response in protobuf format it will marshal whole response content to protobuf

package main

import (
	"time"

	"go-common/library/net/http/blademaster"
	"go-common/library/net/http/blademaster/tests"
)

func main() {
	engine := blademaster.Default()
	engine.GET("/ping.pb", func(c *blademaster.Context) {
		t := &tests.Time{
			Now: time.Now().Unix(),
		}
		c.Protobuf(t, nil)
	})

	engine.Run(":8080")
}
Output:

func (*Context) Redirect

func (c *Context) Redirect(code int, location string)

Redirect returns a HTTP redirect to the specific location.

func (*Context) Render

func (c *Context) Render(code int, r render.Render)

Render http response with http code by a render instance.

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.

func (*Context) Status

func (c *Context) Status(code int)

Status sets the HTTP response code.

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

String writes the given string into the response body.

func (*Context) XML

func (c *Context) XML(data interface{}, err error)

XML serializes the given struct as XML into the response body. It also sets the Content-Type as "application/xml".

Example

This example show how to render response in XML format, it will render structure as XML like: `<Data><Time>2017-11-14T23:03:49.2231458+08:00</Time></Data>`

package main

import (
	"time"

	"go-common/library/net/http/blademaster"
)

func main() {
	type Data struct {
		Time time.Time
	}

	engine := blademaster.Default()

	engine.GET("/ping", func(c *blademaster.Context) {
		var d Data
		d.Time = time.Now()
		c.XML(d, nil)
	})

	engine.Run(":8080")
}
Output:

type Device

type Device struct {
	Build       int64
	Buvid       string
	Buvid3      string
	Channel     string
	Device      string
	Sid         string
	RawPlatform string
	RawMobiApp  string
}

Device is the mobile device model

func (*Device) InvalidChannel

func (d *Device) InvalidChannel(cfgCh string) bool

InvalidChannel check source channel is not allow by config channel.

func (*Device) IsAndroid

func (d *Device) IsAndroid() bool

IsAndroid check plat is android or ipad.

func (*Device) IsIOS

func (d *Device) IsIOS() bool

IsIOS check plat is iphone or ipad.

func (*Device) IsOverseas

func (d *Device) IsOverseas() bool

IsOverseas is overseas

func (*Device) MobiAPPBuleChange

func (d *Device) MobiAPPBuleChange() string

MobiAPPBuleChange is app blue change.

func (*Device) MobiApp

func (d *Device) MobiApp() string

MobiApp by plat

func (*Device) Plat

func (d *Device) Plat() int8

Plat return platform from raw platform and mobiApp

type Engine

type Engine struct {
	RouterGroup
	// contains filtered or unexported fields
}

Engine is the framework's instance, it contains the muxer, middleware and configuration settings. Create an instance of Engine, by using New() or Default()

func Default deprecated

func Default() *Engine

Default returns an Engine instance with the Recovery, Logger and CSRF middleware already attached.

Deprecated: please use DefaultServer.

func DefaultServer

func DefaultServer(conf *ServerConfig) *Engine

DefaultServer returns an Engine instance with the Recovery, Logger and CSRF middleware already attached.

func New deprecated

func New() *Engine

New returns a new blank Engine instance without any middleware attached.

Deprecated: please use NewServer.

func NewServer

func NewServer(conf *ServerConfig) *Engine

NewServer returns a new blank Engine instance without any middleware attached.

func (*Engine) Inject

func (engine *Engine) Inject(pattern string, handlers ...HandlerFunc)

Inject is

Example
package main

import (
	"go-common/library/net/http/blademaster"
	"go-common/library/net/http/blademaster/middleware/auth"
	"go-common/library/net/http/blademaster/middleware/verify"
)

func main() {
	v := verify.New(nil)
	auth := auth.New(nil)
	engine := blademaster.Default()
	engine.Inject("^/index", v.Verify, auth.User)
	engine.POST("/index/hello", func(c *blademaster.Context) {
		c.JSON("hello, world", nil)
	})
	engine.Run(":8080")
}
Output:

func (*Engine) Ping

func (engine *Engine) Ping(handler HandlerFunc)

Ping is used to set the general HTTP ping handler.

func (*Engine) Register

func (engine *Engine) Register(handler HandlerFunc)

Register is used to export metadata to discovery.

func (*Engine) Router

func (engine *Engine) Router() http.Handler

Router return a http.Handler for using http.ListenAndServe() directly.

func (*Engine) Run

func (engine *Engine) Run(addr ...string) (err error)

Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Engine) RunServer

func (engine *Engine) RunServer(server *http.Server, l net.Listener) (err error)

RunServer will serve and start listening HTTP requests by given server and listener. Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Engine) RunTLS

func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error)

RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests. It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Engine) RunUnix

func (engine *Engine) RunUnix(file string) (err error)

RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests through the specified unix socket (ie. a file). Note: this method will block the calling goroutine indefinitely unless an error happens.

Example

This example start a http server through the specified unix socket, it will handle '/ping' and return reponse in html text

package main

import (
	"io/ioutil"
	"log"

	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()
	engine.GET("/ping", func(c *blademaster.Context) {
		c.String(200, "%s", "pong")
	})

	unixs, err := ioutil.TempFile("", "engine.sock")
	if err != nil {
		log.Fatalf("Failed to create temp file: %s", err)
	}

	if err := engine.RunUnix(unixs.Name()); err != nil {
		log.Fatalf("Failed to serve with unix socket: %s", err)
	}
}
Output:

func (*Engine) Server

func (engine *Engine) Server() *http.Server

Server is used to load stored http server.

func (*Engine) SetConfig

func (engine *Engine) SetConfig(conf *ServerConfig) (err error)

SetConfig is used to set the engine configuration. Only the valid config will be loaded.

func (*Engine) SetMethodConfig

func (engine *Engine) SetMethodConfig(path string, mc *MethodConfig)

SetMethodConfig is used to set config on specified path

func (*Engine) Shutdown

func (engine *Engine) Shutdown(ctx context.Context) error

Shutdown the http server without interrupting active connections.

func (*Engine) Start

func (engine *Engine) Start() error

Start listen and serve bm engine by given DSN.

func (*Engine) Use

func (engine *Engine) Use(middleware ...Handler) IRoutes

Use attachs a global middleware to the router. ie. the middleware attached though Use() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.

Example

This example add two middlewares in the root router by `Use` method, it will add CORS headers in response and log total consumed time

package main

import (
	"log"
	"time"

	"go-common/library/net/http/blademaster"
)

func main() {
	timeLogger := func() blademaster.HandlerFunc {
		return func(c *blademaster.Context) {
			start := time.Now()
			c.Next()
			log.Printf("total consume: %v", time.Since(start))
		}
	}

	engine := blademaster.Default()

	engine.Use(blademaster.CORS())
	engine.Use(timeLogger())

	engine.GET("/ping", func(c *blademaster.Context) {
		c.String(200, "%s", "pong")
	})
	engine.Run(":8080")
}
Output:

func (*Engine) UseFunc

func (engine *Engine) UseFunc(middleware ...HandlerFunc) IRoutes

UseFunc attachs a global middleware to the router. ie. the middleware attached though UseFunc() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.

Example

This example add two middlewares in the root router by `UseFunc` method, it will log total consumed time

package main

import (
	"log"
	"time"

	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()

	engine.UseFunc(func(c *blademaster.Context) {
		start := time.Now()
		c.Next()
		log.Printf("total consume: %v", time.Since(start))
	})

	engine.GET("/ping", func(c *blademaster.Context) {
		c.String(200, "%s", "pong")
	})
	engine.Run(":8080")
}
Output:

type Handler

type Handler interface {
	ServeHTTP(c *Context)
}

Handler responds to an HTTP request.

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc http request handler function.

func CORS

func CORS() HandlerFunc

CORS returns the location middleware with default configuration.

func CSRF

func CSRF() HandlerFunc

CSRF returns the csrf middleware to prevent invalid cross site request. Only referer is checked currently.

func Logger

func Logger() HandlerFunc

Logger is logger middleware

func Mobile

func Mobile() HandlerFunc

Mobile is the default handler

func Recovery

func Recovery() HandlerFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

func Trace

func Trace() HandlerFunc

Trace is trace middleware

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(c *Context)

ServeHTTP calls f(ctx).

type IRouter

type IRouter interface {
	IRoutes
	Group(string, ...HandlerFunc) *RouterGroup
}

IRouter http router framework interface.

type IRoutes

type IRoutes interface {
	UseFunc(...HandlerFunc) IRoutes
	Use(...Handler) IRoutes

	Handle(string, string, ...HandlerFunc) IRoutes
	HEAD(string, ...HandlerFunc) IRoutes
	GET(string, ...HandlerFunc) IRoutes
	POST(string, ...HandlerFunc) IRoutes
	PUT(string, ...HandlerFunc) IRoutes
	DELETE(string, ...HandlerFunc) IRoutes
}

IRoutes http router interface.

type MethodConfig

type MethodConfig struct {
	Timeout xtime.Duration
}

MethodConfig is

type RouterGroup

type RouterGroup struct {
	Handlers []HandlerFunc
	// contains filtered or unexported fields
}

RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix and an array of handlers (middleware).

Example

This example use `RouterGroup` to separate different requests, it will handle ('/group1/ping', '/group2/ping') and return response in json

package main

import (
	"go-common/library/net/http/blademaster"
)

func main() {
	engine := blademaster.Default()

	group := engine.Group("/group1", blademaster.CORS())
	group.GET("/ping", func(c *blademaster.Context) {
		c.JSON(map[string]string{"message": "hello"}, nil)
	})

	group2 := engine.Group("/group2", blademaster.CORS())
	group2.GET("/ping", func(c *blademaster.Context) {
		c.JSON(map[string]string{"message": "welcome"}, nil)
	})

	engine.Run(":8080")
}
Output:

func (*RouterGroup) BasePath

func (group *RouterGroup) BasePath() string

BasePath router group base path.

func (*RouterGroup) DELETE

func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes

DELETE is a shortcut for router.Handle("DELETE", path, handle).

func (*RouterGroup) GET

func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes

GET is a shortcut for router.Handle("GET", path, handle).

func (*RouterGroup) Group

func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup

Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix. For example, all the routes that use a common middlware for authorization could be grouped.

func (*RouterGroup) HEAD

func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes

HEAD is a shortcut for router.Handle("HEAD", path, handle).

func (*RouterGroup) Handle

func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes

Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in doc.

For HEAD, GET, POST, PUT, and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func (*RouterGroup) POST

func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes

POST is a shortcut for router.Handle("POST", path, handle).

func (*RouterGroup) PUT

func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes

PUT is a shortcut for router.Handle("PUT", path, handle).

func (*RouterGroup) SetMethodConfig

func (group *RouterGroup) SetMethodConfig(config *MethodConfig) *RouterGroup

SetMethodConfig is used to set config on specified method

func (*RouterGroup) Use

func (group *RouterGroup) Use(middleware ...Handler) IRoutes

Use adds middleware to the group, see example code in doc.

func (*RouterGroup) UseFunc

func (group *RouterGroup) UseFunc(middleware ...HandlerFunc) IRoutes

UseFunc adds middleware to the group, see example code in doc.

type ServerConfig

type ServerConfig struct {
	Network string `dsn:"network"`
	// FIXME: rename to Address
	Addr         string         `dsn:"address"`
	Timeout      xtime.Duration `dsn:"query.timeout"`
	ReadTimeout  xtime.Duration `dsn:"query.readTimeout"`
	WriteTimeout xtime.Duration `dsn:"query.writeTimeout"`
}

ServerConfig is the bm server config model

type TraceTransport

type TraceTransport struct {

	// The actual RoundTripper to use for the request. A nil
	// RoundTripper defaults to http.DefaultTransport.
	http.RoundTripper
	// contains filtered or unexported fields
}

TraceTransport wraps a RoundTripper. If a request is being traced with Tracer, Transport will inject the current span into the headers, and set HTTP related tags on the span.

func NewTraceTracesport

func NewTraceTracesport(rt http.RoundTripper, peerService string, internalTags ...trace.Tag) *TraceTransport

NewTraceTracesport NewTraceTracesport

func (*TraceTransport) RoundTrip

func (t *TraceTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface

Directories

Path Synopsis
example
Package example is a generated protocol buffer package.
Package example is a generated protocol buffer package.
middleware
cache
Package cache is a generated protocol buffer package.
Package cache is a generated protocol buffer package.
tag
Package render is a generated protocol buffer package.
Package render is a generated protocol buffer package.
Package tests is a generated protocol buffer package.
Package tests is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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