httputils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetContentType added in v0.0.3

func SetContentType(w http.ResponseWriter, file io.Reader, fileName string)

SetContentType Setst the content type to the responsewriter by the filename or the content

func SetContentTypeWithName added in v0.0.3

func SetContentTypeWithName(w http.ResponseWriter, fileName string) bool

Types

type HTTPFileContainer added in v0.0.3

type HTTPFileContainer struct {
	FileStorage storageabstraction.IFileStorage
	RootDir     string
}

func (HTTPFileContainer) ProvideFileHandler added in v0.0.3

func (container HTTPFileContainer) ProvideFileHandler() http.Handler

type HTTPServer added in v0.0.3

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

func NewHTTPServer added in v0.0.3

func NewHTTPServer(logger log.Logger) *HTTPServer

func (*HTTPServer) SetRoutes added in v0.0.3

func (server *HTTPServer) SetRoutes(routes http.Handler)

func (*HTTPServer) StartHTTPSServer added in v0.0.3

func (server *HTTPServer) StartHTTPSServer()

func (*HTTPServer) StartHTTPServer added in v0.0.3

func (server *HTTPServer) StartHTTPServer()

type TResponse

type TResponse struct {
	StatusCode int         `json:"statusCode"`
	Status     string      `json:"status"`
	Message    string      `json:"message"`
	Content    interface{} `json:"content"`
}

TResponse is the default response to the client

func GetDefaultResponse

func GetDefaultResponse(msg string, content interface{}) *TResponse

GetDefaultResponse creats a successful response with content

func GetErrorResponse

func GetErrorResponse(msg string, code int, args ...interface{}) *TResponse

GetErrorResponse creates a error response with message and errorcode

func HTTPRoutingErrorHandler added in v0.0.3

func HTTPRoutingErrorHandler(logMsg string, err error) *TResponse

func (*TResponse) Encode

func (response *TResponse) Encode(w http.ResponseWriter) error

Encode writes the response to the writer and sets the content type with status code 200

func (*TResponse) EncodeStatus

func (response *TResponse) EncodeStatus(w http.ResponseWriter, statusCode int) error

EncodeStatus writes the response to the responseWriter and sets also the status code

Jump to

Keyboard shortcuts

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