http

package
v0.1.0-ad8fb07 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 18 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_COOPHIVE_SIGNATURE_HEADER = "X-CoopHive-Signature"

this is the signature of the message

View Source
const X_COOPHIVE_USER_HEADER = "X-CoopHive-User"

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

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