Top.Mail.Ru
package nethttp — KubFly SDK for Go

KubFly SDK for Go / nethttp

package nethttp

import "kubfly.io/sdk/nethttp"

Package nethttp is the integration of net/http: a Handler for the server and a RoundTripper for the client. Each request is a frame of a scope, the metrics of its route and an edge of the stream traffic; the headers of KubFly carry the caller to the server and the identity of the processes both ways — the kubfly-sdk-http module of the Java SDK with the filters of its frameworks.

mux := http.NewServeMux()
mux.HandleFunc("GET /orders/{id}", order)
server := &http.Server{Handler: nethttp.Handler(mux)}

client := &http.Client{Transport: nethttp.Transport(http.DefaultTransport)}

The server:

handler), cancelled (the client left before the answer). The route is the pattern of http.ServeMux without its method and host: "GET /orders/{id}" — orders.{id}, "/" — root; a request no pattern took — unmatched;

The client:

Constants

const (
	// ClientHostsVariable is the most hosts of the metrics of the client: the rest are other.
	ClientHostsVariable = "KUBFLY_HTTP_CLIENT_HOSTS"
	// DefaultClientHosts is the most hosts by default.
	DefaultClientHosts = 100
	// ClientRoutesVariable is the most routes of one host: the rest are <METHOD>:other.
	ClientRoutesVariable = "KUBFLY_HTTP_CLIENT_ROUTES"
	// DefaultClientRoutes is the most routes of a host by default.
	DefaultClientRoutes = 100
)

The variables of the integration, with their defaults.

const ServerThread = "http"

ServerThread is the name of the thread of each request: a goroutine has no name, the work of a request is named here, with a number of its own per request — in the frame of the request itself (api.Scope.OnThread).

Variables

var Config = registerConfig(configOf(api.Config.Vars))

Config is the configuration of the integration.

Functions

func ClientHost

func ClientHost(target *url.URL) string

ClientHost is the host of a request in lower case, with its port if it has one: the level of the metrics of its routes, the address of its peer; unknown without one.

func ClientPath

func ClientPath(target *url.URL) string

ClientPath is the path of a request, as it went, without the query — tokens in it never reach a journal; / for none.

func Handler

func Handler(next http.Handler) http.Handler

Handler is a handler that serves each request of the next one in a frame of sdk/http/server/nethttp/request, with the caller of the request as its caller, on a thread of its own (ServerThread), and records the metrics of its route and its edge of the stream traffic. The route is the pattern http.ServeMux matched (http.Request.Pattern): wrap the mux, not a handler of one route.

func ServerAnswer

func ServerAnswer(caller *api.Caller, frame *api.Frame, set func(name string, value string))

ServerAnswer puts KubFly-Frame and KubFly-Peer of the frame that serves a request into its answer, when its caller is of KubFly (api.PeerAnswers) — for a server of another library.

func ServerPeer

func ServerPeer(caller *api.Caller, header func(name string) string) api.PeerSeen

ServerPeer is the peer of an incoming request by its caller and its headers: the caller of KubFly with the names of its KubFly-Peer, else api.PeerExternal — for a server of another library.

func Transport

func Transport(next http.RoundTripper) http.RoundTripper

Transport is a RoundTripper that sends each request with the next one (nil — http.DefaultTransport) in a frame of sdk/http/client/nethttp/request, the headers of its frame and the identity of the process on it, and records the metrics of its route and its edge of the stream traffic. The request of the caller is never changed: one with headers is a clone.

Types

type Configuration

type Configuration struct {
	// ClientHosts is the most hosts of the metrics of the client (KUBFLY_HTTP_CLIENT_HOSTS, 100).
	ClientHosts *api.Param[int]
	// ClientRoutes is the most routes of one host (KUBFLY_HTTP_CLIENT_ROUTES, 100).
	ClientRoutes *api.Param[int]
	// Problems are the wrong values that fell back to their defaults.
	Problems []string
}

Configuration is the configuration of the integration, taken once from api.Config.Vars when the package loads.