Documentation ¶
Index ¶
- func AnyError(errors []error) error
- func BinarySize(v interface{}) int
- func CollectErrors(channels []chan error) []error
- func ContainsString(values []string, key string) bool
- func ContainsToken(values []types.TokenRanges, key types.Token) bool
- func CreateErrAndLog(format string, v ...interface{}) error
- func FindGenByToken(generations []types.Generation, token types.Token) int
- func FromUnixMillis(millis int64) time.Time
- func GetServiceAddress(port int, localInfo *types.BrokerInfo, config conf.BasicConfig) string
- func IfEmpty(value string, defaultValue string) string
- func InParallel(length int, f func(int) error) []chan error
- func InParallelAnyError(length int, f func(int) error) error
- func IsSuccess(code int) bool
- func Jitter(t time.Duration) time.Duration
- func MaxVersion(values ...*types.Generation) types.GenVersion
- func Min(a, b int) int
- func NewBufferCap(initialCap int) *bytes.Buffer
- func NewSingleConnListener(conn net.Conn) net.Listener
- func NoContentResponse(w http.ResponseWriter, retryAfter int)
- func PanicIfErr(err error, message string)
- func ReadBodyClose(resp *http.Response) (string, error)
- func ReadIntoBuffers(reader io.Reader, buffers [][]byte, length int) error
- func RespondText(w http.ResponseWriter, message string)
- func ToBlob(v uuid.UUID) []byte
- func ToCsv(values []int) string
- func ToHandle(he HandleWithError) httprouter.Handle
- func ToPostHandle(he HandleWithError) httprouter.Handle
- func ToUnixMillis(t time.Time) int64
- func ValidRingLength(length int) int
- func WriteBytes(w io.Writer, buf []byte) error
- type CopyOnWriteMap
- type Debouncer
- type HandleWithError
- type MultiBufferReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySize ¶
func BinarySize(v interface{}) int
BinarySize gets the amount of bytes required to write the value, validating that all types are fixed-sized.
func CollectErrors ¶
Collects single messages from each channel
func ContainsString ¶
func ContainsToken ¶
func ContainsToken(values []types.TokenRanges, key types.Token) bool
func CreateErrAndLog ¶
func FindGenByToken ¶
func FindGenByToken(generations []types.Generation, token types.Token) int
func FromUnixMillis ¶
func GetServiceAddress ¶
func GetServiceAddress(port int, localInfo *types.BrokerInfo, config conf.BasicConfig) string
GetServiceAddress determines whether it should be bind to all interfaces or it should use a single host name
func InParallel ¶
Runs in parallel and collects the results in channels
func InParallelAnyError ¶
Runs in parallel and returns an error if any is found
func MaxVersion ¶
func MaxVersion(values ...*types.Generation) types.GenVersion
MaxVersion gets the maximum version value of the non-nil generations provided. Defaults to zero.
func NewBufferCap ¶
NewBufferCap returns a buffer with the initial provided initial capacity
func NoContentResponse ¶
func NoContentResponse(w http.ResponseWriter, retryAfter int)
Sets the response status as 204 (NoContent) w/ no cache and optionally setting the retry after header.
func ReadBodyClose ¶
Reads the body as a string and closes it
func ReadIntoBuffers ¶ added in v0.7.0
Reads from the reader into the provided buffers until length, returning an error otherwise
func RespondText ¶
func RespondText(w http.ResponseWriter, message string)
Writes a text message in the response
func ToHandle ¶
func ToHandle(he HandleWithError) httprouter.Handle
ToHandle wraps a handle func with error and converts it to a `httprouter.Handle`
func ToPostHandle ¶
func ToPostHandle(he HandleWithError) httprouter.Handle
ToPostHandle wraps a handle func with error, returns plain text "OK" and converts it to a `httprouter.Handle`
func ToUnixMillis ¶
func ValidRingLength ¶
For a given number, it returns the last ring length that can contain it. For example: given 3 it returns 3; for 4 -> 3; for 5 -> 3; for 7 -> 6
Types ¶
type CopyOnWriteMap ¶
type CopyOnWriteMap struct {
// contains filtered or unexported fields
}
CopyOnWriteMap provides basic functionality of a copy-on-write dictionary that uses a valueCreator function (instead of a value like sync.Map)
func NewCopyOnWriteMap ¶
func NewCopyOnWriteMap() *CopyOnWriteMap
func (*CopyOnWriteMap) LoadOrStore ¶
func (c *CopyOnWriteMap) LoadOrStore(key interface{}, valueCreator func() (interface{}, error)) (value interface{}, loaded bool, err error)
type Debouncer ¶
type Debouncer func(func())
func Debounce ¶
Creates a debouncer that will stop the previous timer when the time that has passed is below the threshold. For example: if we set it to 5 mins and only few seconds passed, it will stop the previous one and create a new timer. On the other hand, if several minutes passed it will not stop the previous and only issue a new one.
type HandleWithError ¶
type HandleWithError func(http.ResponseWriter, *http.Request, httprouter.Params) error
type MultiBufferReader ¶ added in v0.7.0
type MultiBufferReader interface { io.Reader ReadUint8() (uint8, error) ReadUint32() (uint32, error) ReadUint64() (uint64, error) ReadString(length int) (string, error) ReadStringBytes() (string, error) // Returns the unread portion of the buffers and the total length Bytes() ([][]byte, int) }
Represents a reader that attempts to read without allocating new buffers.
func NewMultiBufferReader ¶ added in v0.7.0
func NewMultiBufferReader(buffers [][]byte, bufferSize int, length int) MultiBufferReader
Returns a reader that wraps multiple []byte buffers and tries to read without allocating new buffers.