http

package
v0.0.0-pr110 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeaders

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

func ConnectWebSocket

func ConnectWebSocket(
	url string,
	messageChan chan []byte,
	ctx context.Context,
) *websocket.Conn

ConnectWebSocket establishes a new WebSocket connection

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

func GetAddressFromHeaders

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

this will use the client headers to ensure that a message was signed by the holder of a private key for a specific address there is a "X-CoopHive-User" header that will contain the address there is a "X-CoopHive-Signature" header that will contain the signature we use the signature to verify that the message was signed by the private key

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 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,
)

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 AuthUser

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

type ClientOptions

type ClientOptions struct {
	URL        string
	PrivateKey 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 ServerOptions

type ServerOptions struct {
	URL  string
	Host string
	Port int
}

Jump to

Keyboard shortcuts

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