handler

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileHandler

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

FileHandler implements the Handler interface It takes in a fileName which specifies the file on which the operations have to be performed.

func NewFileHandler

func NewFileHandler(fileName string) *FileHandler

NewFileHandler takes in a fileName It returns a FileHandler instance.

func (*FileHandler) Read

func (fh *FileHandler) Read() ([]byte, error)

Read function returns the bytes read from the given file or an error in case something went wrong.

func (*FileHandler) Write

func (fh *FileHandler) Write(input []byte) error

Write function writes the bytes of data to the given file and returns an error in case something went wrong.

type HTTPRequestHandler

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

HTTPRequestHandler implements the Handler interface It takes in pointer to a http.Request and a http.ResponseWriter on which the operations have to be performed.

func NewHTTPRequestHandler

func NewHTTPRequestHandler(rw http.ResponseWriter, req *http.Request) *HTTPRequestHandler

NewHTTPRequestHandler takes in http.ResponseWriter and pointer to a http.Request. It returns a HTTPRequestHandler instance.

func (*HTTPRequestHandler) Read

func (rh *HTTPRequestHandler) Read() ([]byte, error)

Read function returns the bytes read from the given http.Request or an error in case something went wrong.

func (*HTTPRequestHandler) Write

func (rh *HTTPRequestHandler) Write(input []byte) error

Write function writes the bytes of data using the given http.ResponseWriter. It returns an error in case something went wrong.

type HTTPResponseHandler

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

HTTPResponseHandler implements the Handler interface It takes in pointer to a http.Response on which the operations have to be performed.

func NewHTTPResponseHandler

func NewHTTPResponseHandler(res *http.Response) *HTTPResponseHandler

NewHTTPResponseHandler takes in a pointer to http.Response. It returns a HTTPResponseHandler instance.

func (*HTTPResponseHandler) Read

func (rh *HTTPResponseHandler) Read() ([]byte, error)

Read function returns the bytes read from the given http.Response or an error in case something went wrong.

func (*HTTPResponseHandler) Write

func (rh *HTTPResponseHandler) Write(input []byte) error

Write operation is not allowed on a http.Response.

type Handler

type Handler interface {
	// Read function returns the bytes read or an error in case something went wrong.
	Read() ([]byte, error)

	// Write function writes the bytes of data and returns an error in case something went wrong.
	Write([]byte) error
}

Handler interface defines the following functions:

Read() ([]byte, error) ->
	This function helps in reading from a specific source.
	It returns the data read in form of bytes else an error describing what went wrong.

Write([]byte) error
	This function helps in writing data.
	It returns an error describing what went wrong.

type Noop

type Noop struct{}

Noop implements the Handler interface This is a default handler when no input is provided.

func NewNoopHandler

func NewNoopHandler() *Noop

NewNoopHandler takes returns a Noop instance.

func (*Noop) Read

func (noop *Noop) Read() ([]byte, error)

Read function returns the empty bytes and a nil error.

func (*Noop) Write

func (noop *Noop) Write(d []byte) error

Write operation returns a nil error.

Jump to

Keyboard shortcuts

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