Documentation ¶
Index ¶
- Constants
- Variables
- func ClientHTTPStatusAndError(err error) (int, error)
- func DiffConfig(defaultConfig, actualConfig map[interface{}]interface{}) (map[interface{}]interface{}, error)
- func GetFirstAddressOf(names []string) (string, error)
- func InstrumentedHTTPClient() *http.Client
- func IsWSHandshakeRequest(req *http.Request) bool
- func LoggerWithContext(ctx context.Context, l log.Logger) log.Logger
- func LoggerWithTraceID(traceID string, l log.Logger) log.Logger
- func LoggerWithUserID(userID string, l log.Logger) log.Logger
- func LoggerWithUserIDs(userIDs []string, l log.Logger) log.Logger
- func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
- func ShuffleShardExpectedInstances(shardSize, numZones int) int
- func ShuffleShardExpectedInstancesPerZone(shardSize, numZones int) int
- func ShuffleShardSeed(identifier, zone string) int64
- func StringsContain(values []string, search string) bool
- func StringsMap(values []string) map[string]bool
- func UnsafeGetBytes(s string) []byte
- func UnsafeGetString(buf []byte) string
- func WithSourceIPs(sourceIPs string, l log.Logger) log.Logger
- func WithTimeout(timeout time.Duration) connect.Interceptor
- func WrapWithInstrumentedHTTPTransport(next http.RoundTripper) http.RoundTripper
- func WriteError(err error, w http.ResponseWriter)
- func WriteHTMLResponse(w http.ResponseWriter, message string)
- func WriteJSONResponse(w http.ResponseWriter, v interface{})
- func WriteTextResponse(w http.ResponseWriter, message string)
- func WriteYAMLResponse(w http.ResponseWriter, v interface{})
- func YAMLMarshalUnmarshal(in interface{}) (map[interface{}]interface{}, error)
- func YoloBuf(s string) []byte
- type ActiveUsers
- type ActiveUsersCleanupService
- type Log
- type RoundTripperFunc
Constants ¶
const ( ErrClientCanceled = "The request was cancelled by the client." ErrDeadlineExceeded = "" /* 160-byte string literal not displayed */ )
const ( // Sharding strategies. ShardingStrategyDefault = "default" ShardingStrategyShuffle = "shuffle-sharding" )
const StatusClientClosedRequest = 499
StatusClientClosedRequest is the status code for when a client request cancellation of an http request
Variables ¶
var ( RecoveryHTTPMiddleware = middleware.Func(func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { defer func() { if p := recover(); p != nil { WriteError(onPanic(p), w) } }() next.ServeHTTP(w, req) }) }) RecoveryGRPCStreamInterceptor = grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(onPanic)) RecoveryGRPCUnaryInterceptor = grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandler(onPanic)) )
var Logger = log.NewNopLogger()
Logger is a global logger to use only where you cannot inject a logger.
Functions ¶
func ClientHTTPStatusAndError ¶
ClientHTTPStatusAndError returns error and http status that is "safe" to return to client without exposing any implementation details.
func DiffConfig ¶
func DiffConfig(defaultConfig, actualConfig map[interface{}]interface{}) (map[interface{}]interface{}, error)
DiffConfig utility function that returns the diff between two config map objects
func GetFirstAddressOf ¶ added in v0.2.0
GetFirstAddressOf returns the first IPv4 address of the supplied interface names, omitting any 169.254.x.x automatic private IPs if possible.
func InstrumentedHTTPClient ¶
InstrumentedHTTPClient returns a HTTP client with tracing instrumented default RoundTripper.
func IsWSHandshakeRequest ¶ added in v0.1.1
IsWSHandshakeRequest returns true if the given request is a websocket handshake request.
func LoggerWithContext ¶ added in v0.2.0
LoggerWithContext returns a Logger that has information about the current user or users and trace in its details.
e.g.
log = util.WithContext(ctx, log) # level=error user=user-1|user-2 traceID=123abc msg="Could not chunk chunks" err="an error" level.Error(log).Log("msg", "Could not chunk chunks", "err", err)
func LoggerWithTraceID ¶ added in v0.2.0
LoggerWithTraceID returns a Logger that has information about the traceID in its details.
func LoggerWithUserID ¶ added in v0.2.0
LoggerWithUserID returns a Logger that has information about the current user in its details.
func LoggerWithUserIDs ¶ added in v0.2.0
LoggerWithUserIDs returns a Logger that has information about the current user or users (separated by "|") in its details.
func NewHTTPMetricMiddleware ¶ added in v0.1.1
func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
NewHTTPMetricMiddleware creates a new middleware that automatically instruments HTTP requests from the given router.
func ShuffleShardExpectedInstances ¶ added in v0.2.0
ShuffleShardExpectedInstances returns the total number of instances that should be selected for a given tenant. If zone-aware replication is disabled, the input numZones should be 1.
func ShuffleShardExpectedInstancesPerZone ¶ added in v0.2.0
ShuffleShardExpectedInstancesPerZone returns the number of instances that should be selected for each zone when zone-aware replication is enabled. The algorithm expects the shard size to be divisible by the number of zones, in order to have nodes balanced across zones. If it's not, we do round up.
func ShuffleShardSeed ¶ added in v0.2.0
ShuffleShardSeed returns seed for random number generator, computed from provided identifier.
func StringsContain ¶ added in v0.2.0
StringsContain returns true if the search value is within the list of input values.
func StringsMap ¶ added in v0.2.0
StringsMap returns a map where keys are input values.
func UnsafeGetBytes ¶
func UnsafeGetString ¶
func WithSourceIPs ¶ added in v0.2.0
WithSourceIPs returns a Logger that has information about the source IPs in its details.
func WithTimeout ¶ added in v0.2.0
NewTimeoutInterceptor returns a new timeout interceptor.
func WrapWithInstrumentedHTTPTransport ¶
func WrapWithInstrumentedHTTPTransport(next http.RoundTripper) http.RoundTripper
WrapWithInstrumentedHTTPTransport wraps the given RoundTripper with an tracing instrumented one.
func WriteError ¶
func WriteError(err error, w http.ResponseWriter)
WriteError write a go error with the correct status code.
func WriteHTMLResponse ¶ added in v0.2.0
func WriteHTMLResponse(w http.ResponseWriter, message string)
WriteHTMLResponse sends message as text/html response with 200 status code.
func WriteJSONResponse ¶ added in v0.4.0
func WriteJSONResponse(w http.ResponseWriter, v interface{})
WriteJSONResponse writes some JSON as a HTTP response.
func WriteTextResponse ¶ added in v0.3.0
func WriteTextResponse(w http.ResponseWriter, message string)
WriteTextResponse sends message as text/plain response with 200 status code.
func WriteYAMLResponse ¶
func WriteYAMLResponse(w http.ResponseWriter, v interface{})
WriteYAMLResponse writes some YAML as a HTTP response.
func YAMLMarshalUnmarshal ¶
func YAMLMarshalUnmarshal(in interface{}) (map[interface{}]interface{}, error)
YAMLMarshalUnmarshal utility function that converts a YAML interface in a map doing marshal and unmarshal of the parameter
Types ¶
type ActiveUsers ¶ added in v0.2.0
type ActiveUsers struct {
// contains filtered or unexported fields
}
ActiveUsers keeps track of latest user's activity timestamp, and allows purging users that are no longer active.
func NewActiveUsers ¶ added in v0.2.0
func NewActiveUsers() *ActiveUsers
func (*ActiveUsers) PurgeInactiveUsers ¶ added in v0.2.0
func (m *ActiveUsers) PurgeInactiveUsers(deadline int64) []string
PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.
func (*ActiveUsers) UpdateUserTimestamp ¶ added in v0.2.0
func (m *ActiveUsers) UpdateUserTimestamp(userID string, ts int64)
type ActiveUsersCleanupService ¶ added in v0.2.0
type ActiveUsersCleanupService struct { services.Service // contains filtered or unexported fields }
ActiveUsersCleanupService tracks active users, and periodically purges inactive ones while running.
func NewActiveUsersCleanupService ¶ added in v0.2.0
func NewActiveUsersCleanupService(cleanupInterval, inactiveTimeout time.Duration, cleanupFn func(string)) *ActiveUsersCleanupService
func NewActiveUsersCleanupWithDefaultValues ¶ added in v0.2.0
func NewActiveUsersCleanupWithDefaultValues(cleanupFn func(string)) *ActiveUsersCleanupService
func (*ActiveUsersCleanupService) UpdateUserTimestamp ¶ added in v0.2.0
func (s *ActiveUsersCleanupService) UpdateUserTimestamp(user string, now time.Time)
type Log ¶ added in v0.1.1
type Log struct { Log logging.Interface LogRequestHeaders bool // LogRequestHeaders true -> dump http headers at debug log level LogRequestAtInfoLevel bool // LogRequestAtInfoLevel true -> log requests at info log level SourceIPs *middleware.SourceIPExtractor }
Log middleware logs http requests