httpserver

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeHeader is the name of the content-type header field
	ContentTypeHeader = "Content-Type"
	// ContentTypeJSON is the JSON content-type
	ContentTypeJSON = "application/json"
	// ContentTypeText is the text content-type
	ContentTypeText = "text/plain"
	// ContentTypeBinary is the binary content type
	ContentTypeBinary = "application/octet-stream"
)

Variables

View Source
var (
	// ServerError is an internal server error
	ServerError = NewError(http.StatusInternalServerError, StatusServerError)
	// NotFoundError indicates that the requested content was not found
	NotFoundError = NewError(http.StatusNotFound, StatusNotFound)
	// BadRequestError indicates that the request is invalid
	BadRequestError = NewError(http.StatusBadRequest, StatusBadRequest)
)

Functions

This section is empty.

Types

type Error added in v0.1.3

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

Error holds additional context associated with the HTTP request

func NewError added in v0.1.3

func NewError(status int, msg StatusMsg) *Error

NewError returns a new Error

func (*Error) Error added in v0.1.3

func (e *Error) Error() string

Error returns the error string

func (*Error) Status added in v0.1.3

func (e *Error) Status() int

Status returns the status code

func (*Error) StatusMsg added in v0.1.3

func (e *Error) StatusMsg() StatusMsg

StatusMsg returns the status message

type ResponseWriter added in v0.1.3

type ResponseWriter struct {
	http.ResponseWriter
}

ResponseWriter wraps the http response writer and implements utility functions

func NewResponseWriter added in v0.1.3

func NewResponseWriter(rw http.ResponseWriter) *ResponseWriter

NewResponseWriter returns a new response writer

func (*ResponseWriter) Write added in v0.1.3

func (rw *ResponseWriter) Write(status int, bytes []byte, contentType string)

Write writes the response

func (*ResponseWriter) WriteError added in v0.1.3

func (rw *ResponseWriter) WriteError(err error)

WriteError writes the given error to the response writer

func (*ResponseWriter) WriteText added in v0.1.3

func (rw *ResponseWriter) WriteText(status int, text string)

WriteText writes the given text to the response writer

type Server

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

Server implements an HTTP server

func New

func New(url, certFile, keyFile string, handlers ...common.HTTPHandler) *Server

New returns a new HTTP server

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server in a separate Go routine

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stops the REST service

type StatusMsg added in v0.1.3

type StatusMsg = string

StatusMsg is a descriptive message that's returned in the response

const (
	// StatusBadRequest indicate that the request was invalid
	StatusBadRequest StatusMsg = "bad-request"
	// StatusEmptyContent indicates that no content was provided in the POST
	StatusEmptyContent StatusMsg = "empty-content"
	// StatusNotFound indicates that the content for the provided hash was not found
	StatusNotFound StatusMsg = "not-found"
	// StatusServerError indicates that the server experienced an unexpected error
	StatusServerError StatusMsg = "server-error"
)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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