http

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const API_SUB_PATH = "/api/v1"

the sub path any API's are served over

View Source
const CONTEXT_ADDRESS = "address"

the context name we keep the address

View Source
const WEBSOCKET_SUB_PATH = "/ws"

the sub path the websocket server is mounted on

View Source
const X_ANURA_SERVER_HEADER = "X-Anura-Server"

the address of the anura server

View Source
const X_ANURA_SIGNATURE_HEADER = "X-Anura-Key"

the signature of the anura server

View Source
const X_LILYPAD_SIGNATURE_HEADER = "X-Lilypad-Signature"

this is the signature of the message

View Source
const X_LILYPAD_USER_HEADER = "X-Lilypad-User"

write some string constants for x-lilypad headers this is the address of the user

View Source
const X_LILYPAD_VERSION_HEADER = "X-Lilypad-Version"

the version run by the client or service

Variables

This section is empty.

Functions

func AddAnuraHeaders

func AddAnuraHeaders(
	req *retryablehttp.Request,
	privateKey *ecdsa.PrivateKey,
	address string,
) error

func AddHeaders

func AddHeaders(
	req *retryablehttp.Request,
	privateKey *ecdsa.PrivateKey,
	address string,
) error

func CheckAnuraSignature

func CheckAnuraSignature(req *http.Request, approvedAddresses []string) (string, error)

func CheckSignature

func CheckSignature(req *http.Request) (string, error)

Use the client headers to ensure that a message was signed by the holder of a private key for a specific address. The "X-Lilypad-User" header contains the address. The "X-Lilypad-Signature" header contains the signature. We use the signature to verify that the message was signed by the private key.

func ConnectWebSocket

func ConnectWebSocket(
	url string,
	ctx context.Context,
) chan []byte

ConnectWebSocket establishes a new WebSocket connection

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

func GenericJSONPostClient

func GenericJSONPostClient(url string, json string) (*http.Response, error)

func GetHandler

func GetHandler[T any](handler httpGetWrapper[T]) func(res http.ResponseWriter, req *http.Request)

wrap a http handler with some error handling so if it returns an error we handle it

func GetRequest

func GetRequest[ResultType any](
	options ClientOptions,
	path string,
	queryParams map[string]string,
) (ResultType, error)

func GetRequestBuffer

func GetRequestBuffer(
	options ClientOptions,
	path string,
	queryParams map[string]string,
) (*bytes.Buffer, error)

func GetVersionFromHeaders

func GetVersionFromHeaders(req *http.Request) (string, error)

func IsAnura

func IsAnura(req *http.Request, approvedAddresses []string) bool

func PostHandler

func PostHandler[RequestType any, ResultType any](handler httpPostWrapper[RequestType, ResultType]) func(res http.ResponseWriter, req *http.Request)

func PostRequest

func PostRequest[RequestType any, ResultType any](
	options ClientOptions,
	path string,
	data RequestType,
) (ResultType, error)

func PostRequestBuffer

func PostRequestBuffer[ResultType any](
	options ClientOptions,
	path string,
	data *bytes.Buffer,
) (ResultType, error)

func ReadBody

func ReadBody[T any](req *http.Request) (T, error)

func StartWebSocketServer

func StartWebSocketServer(
	r *mux.Router,
	path string,
	messageChan chan []byte,
	ctx context.Context,
	connectCB func(params WSConnectionParams),
	disconnectCB func(params WSConnectionParams),
)

StartWebSocketServer starts a WebSocket server

func URL

func URL(options ClientOptions, path string) string

func WebsocketURL

func WebsocketURL(options ClientOptions, path string) string

Types

type AccessControlOptions

type AccessControlOptions struct {
	EnableResourceProviderAllowlist bool
	ValidationTokenSecret           string
	ValidationTokenExpiration       int
	ValidationTokenKid              string
	AnuraAddresses                  []string
	OfferTimestampDiffSeconds       int
	EnableVersionCheck              bool
	MinimumVersion                  string
}

type AuthUser

type AuthUser struct {
	Address string `json:"address"`
}

type ClientOptions

type ClientOptions struct {
	URL           string
	PrivateKey    string
	PublicAddress string
	Type          string
}

type ConnectionWrapper

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

type HTTPError

type HTTPError struct {
	Message    string
	StatusCode int
}

func (HTTPError) Error

func (e HTTPError) Error() string

type RateLimiterOptions

type RateLimiterOptions struct {
	RequestLimit int
	WindowLength int
}

type ServerOptions

type ServerOptions struct {
	URL           string
	Host          string
	Port          int
	AccessControl AccessControlOptions
	RateLimiter   RateLimiterOptions
}

type ValidationToken

type ValidationToken struct {
	JWT string
}

type WSConnectionParams

type WSConnectionParams struct {
	ID          string
	Type        string
	CountryCode string
	IP          string
}

Jump to

Keyboard shortcuts

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