mulch

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mulch provides shared methods, structures and variables used by mulery client library, server library and server application.

Index

Constants

View Source
const (
	ProxyErrorCode  = 526
	ClientErrorCode = 527
)

Custom HTTP error codes shared by client and server.

View Source
const HandshakeTimeout = 15 * time.Second
View Source
const SecretKeyHeader = "x-secret-key"

Variables

This section is empty.

Functions

func HashKeyID added in v0.0.6

func HashKeyID(secret string, clientID string) string

HashKeyID creates a unique client ID hash. If a custom key validator returns a secret(string), hash that with the client id to create a new client id. This is custom logic you probably don't need, and you can avoid it by returning an empty string from the custom key validator.

func NewHTTPResponse

func NewHTTPResponse(code int, size int64) []byte

NewHTTPResponse creates a new HTTPResponse.

func SerializeHTTPResponse

func SerializeHTTPResponse(resp *http.Response) []byte

SerializeHTTPResponse create a new HTTPResponse json blob from a http.Response.

func UnserializeHTTPRequest

func UnserializeHTTPRequest(req *HTTPRequest) *http.Request

UnserializeHTTPRequest create a new http.Request from a HTTPRequest.

Types

type DefaultLogger

type DefaultLogger struct {
	Silent bool
}

DefaultLogger is a simple wrapper around the provided Logger interface. Use this if you only need simple log output.

func (*DefaultLogger) Debugf

func (l *DefaultLogger) Debugf(format string, v ...interface{})

Debugf prints a message with DEBUG prefixed.

func (*DefaultLogger) Errorf

func (l *DefaultLogger) Errorf(format string, v ...interface{})

Errorf prints a message with ERROR prefixed.

func (*DefaultLogger) Printf

func (l *DefaultLogger) Printf(format string, v ...interface{})

Printf prints a message with INFO prefixed.

type HTTPRequest

type HTTPRequest struct {
	Method        string              `json:"method"`
	URL           string              `json:"url"`
	Header        map[string][]string `json:"header"`
	ContentLength int64               `json:"contentLength"`
	RemoteAddr    string              `json:"remoteAddr"`
	Host          string              `json:"host"`
	Proto         string              `json:"proto"`
	RequestURI    string              `json:"requestUri"`
}

HTTPRequest is a serializable version of http.Request (with only useful fields).

func SerializeHTTPRequest

func SerializeHTTPRequest(req *http.Request) *HTTPRequest

SerializeHTTPRequest create a new HTTPRequest from a http.Request.

type HTTPResponse

type HTTPResponse struct {
	StatusCode    int         `json:"statusCode"`
	Header        http.Header `json:"header"`
	ContentLength int64       `json:"contentLength"`
}

HTTPResponse is a serializable version of http.Response (with only useful fields).

type Handshake

type Handshake struct {
	Size     int    `json:"size"`     // idle connections.
	MaxSize  int    `json:"max"`      // buffer pool size.
	ID       string `json:"id"`       // client ID
	Name     string `json:"name"`     // For logs only.
	Compress string `json:"compress"` // gzip, bzip, etc, not used yet.
	// ClientIDs is for you to identify your clients with your own ID(s).
	ClientIDs []interface{} `json:"clientIds"`
}

type Logger

type Logger interface {
	// Debugf is used sparingly.
	Debugf(format string, v ...interface{})
	// Errorf is the most used of the loggers.
	Errorf(format string, v ...interface{})
	// Printf is only used when a custom Handler is not provided.
	Printf(format string, v ...interface{})
}

Logger is the log-output input interface for this package. Provide your own log interface, or use the DefaultLogger to simply wrap the log package. Leaving the interface nil disables all log output.

Jump to

Keyboard shortcuts

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