http

package
v0.0.0-...-9d56a58 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(vey vey.Vey, sender email.Sender, open *url.URL) http.Handler

func Wrap

func Wrap(h Handler) http.Handler

func WrapF

func WrapF(f func(http.ResponseWriter, *http.Request) error) http.Handler

func WriteJSON

func WriteJSON(w http.ResponseWriter, statusCode int, out interface{}) error

Types

type Body

type Body struct {
	Email     string        `json:"email,omitempty"`
	PublicKey vey.PublicKey `json:"publicKey,omitempty"`
	Token     []byte        `json:"token,omitempty"`
	Challenge []byte        `json:"challenge,omitempty"`
	Signature []byte        `json:"signature,omitempty"`
}

type BodyFunc

type BodyFunc func(http.ResponseWriter, *http.Request, Body) error

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client is a HTTP client that consumes Vey's HTTP APIs.

func NewClient

func NewClient(root string) Client

NewClient creates a new HTTP client that consumes Vey's HTTP APIs, given a root URL.

func (Client) BeginDelete

func (c Client) BeginDelete(email string, publicKey vey.PublicKey) error

BeginDelete calls the BeginDelete interface on the Vey server.

func (Client) BeginPut

func (c Client) BeginPut(email string, publicKey vey.PublicKey) error

BeginPut calls the BeginPut interface on the Vey server.

func (Client) CommitDelete

func (c Client) CommitDelete(token []byte) error

CommitDelete calls the CommitDelete interface on the Vey server.

func (Client) CommitPut

func (c Client) CommitPut(challenge, signature []byte) error

CommitPut calls the CommitPut interface on the Vey server.

func (Client) Do

func (c Client) Do(path string, body Body) (*http.Response, error)

Do does request preparation and error handling common to all of Vey's HTTP APIs. Caller should Close the response.Body when error is nil.

func (Client) Get

func (c Client) Get(path string, q url.Values) (*http.Response, error)

func (Client) GetKeys

func (c Client) GetKeys(email string) ([]vey.PublicKey, error)

GetKeys calls the GetKeys interface on the Vey server and returns a slice of PublicKeys.

func (Client) Open

func (c Client) Open(query url.Values) (string, error)

Open calls the /open path on the Vey server, and returns the redirect response's Location header.

type ClientError

type ClientError struct {
	Msg string         // Error message
	Res *http.Response // The *http.Response returned from http.Client if it was returned from http.Client
	Err error          // underlying error if any
}

func (ClientError) Error

func (e ClientError) Error() string

ClientError implements error interface.

func (ClientError) Unwrap

func (e ClientError) Unwrap() error

type Error

type Error struct {
	Code int    `json:"-"`
	Msg  string `json:"message"`
	Err  error  `json:"-"`
}

func NewError

func NewError(err error) Error

func (Error) Error

func (e Error) Error() string

Error implements error interface.

func (Error) Unwrap

func (e Error) Unwrap() error

type Handler

type Handler interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request) error
}

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

func AcceptJSON

func AcceptJSON(h BodyFunc) HandlerFunc

AcceptJSON parses the request body into Body struct. Be careful that, the request body is EOF when later trying to read it again. AcceptJSON responds and doesn't call h, if JSON decoding to Body struct fails.

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error

type Logger

type Logger interface {
	// Error logs an error.
	// err can be of type Error and unwrapped to return the underlying error.
	Error(err error)
}

Logger logs errors.

var Log Logger = NewLogger()

Log is package global variable that holds Logger.

func NewLogger

func NewLogger() Logger

NewLogger returns a new default Logger that logs to stderr.

func NilLogger

func NilLogger() Logger

type VeyHandler

type VeyHandler struct {
	*http.ServeMux
	Vey     vey.Vey
	Sender  email.Sender
	OpenURL *url.URL
}

func (*VeyHandler) BeginDelete

func (h *VeyHandler) BeginDelete(w http.ResponseWriter, r *http.Request, b Body) error

func (*VeyHandler) BeginPut

func (h *VeyHandler) BeginPut(w http.ResponseWriter, r *http.Request, b Body) error

func (*VeyHandler) CommitDelete

func (h *VeyHandler) CommitDelete(w http.ResponseWriter, r *http.Request) error

CommitDelete handles the final step of deleting the public key. The user receives the URL to CommitDelete in the email and opens it in their browser. token parameter should be in query.

func (*VeyHandler) CommitPut

func (h *VeyHandler) CommitPut(w http.ResponseWriter, r *http.Request, b Body) error

func (*VeyHandler) GetKeys

func (h *VeyHandler) GetKeys(w http.ResponseWriter, r *http.Request, b Body) error

func (*VeyHandler) Open

Jump to

Keyboard shortcuts

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