http

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = http.DefaultClient

Functions

func GetReqID

func GetReqID(r *http.Request) string

GetReqID is

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe just copies the http package ListenAndServe function later on I should refactor this to actually create my own server and handlers for now yolo

func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error

ListenAndServeTLS just copies the http package ListenAndServe function later on I should refactor this to actually create my own server and handlers for now yolo

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware creates a id for each request coming in. It then passes it down via context

func RespondAccepted

func RespondAccepted(w http.ResponseWriter, v interface{})

Accepted encodes a JSON response and sets the status to HTTP Status to 200 OK

func RespondCreated

func RespondCreated(w http.ResponseWriter, v interface{})

RespondCreated encodes a JSON response and sets the status to HTTP Status to 201 CREATED

func RespondError

func RespondError(w http.ResponseWriter, err error, code int, reqID string)

RespondError writes an API error message to the response and logger.

func RespondMessage

func RespondMessage(w http.ResponseWriter, msg string)

func RespondNotFound

func RespondNotFound(w http.ResponseWriter)

NotFound writes an API error message to the response.

func RespondOK

func RespondOK(w http.ResponseWriter, v interface{})

OK encodes a JSON response and sets the status to HTTP Status to 200 OK

func RespondServeFile

func RespondServeFile(w http.ResponseWriter, f *mahi.FileBlob)

func Serve

func Serve(handler http.Handler, port int, https bool, sslCertPath, sslKeyPath string) error

Serve is

Types

type Error

type Error struct {
	Error     string `json:"error,omitempty"`
	Type      string `json:"type"`
	RequestID string `json:"requestId"`
	HTTPCode  int    `json:"httpCode"`
}

Error is a generic HTTP response body for errors.

type HealthStats

type HealthStats struct {
	AllocatedMemory      uint64 `json:"allocatedMemory"`
	TotalAllocatedMemory uint64 `json:"totalAllocatedMemory"`
	Goroutines           int    `json:"goroutines"`
	GCCycles             uint32 `json:"completedGCCycles"`
	NumberOfCPUs         int    `json:"cpus"`
	HeapSys              uint64 `json:"maxHeapUsage"`
	HeapAllocated        uint64 `json:"heapInUse"`
	ObjectsInUse         uint64 `json:"objectsInUse"`
	OSMemoryObtained     uint64 `json:"OSMemoryObtained"`
}

type LinksData

type LinksData struct {
	Self string `json:"self"`
	Next string `json:"next"`
}

type Message

type Message struct {
	Data *MessageData `json:"data"`
}

type MessageData

type MessageData struct {
	Message string `json:"message"`
}

type PaginationData

type PaginationData struct {
	Links   LinksData `json:"links"`
	Count   int       `json:"count"`
	SinceID string    `json:"sinceId"`
}

type RelationshipData

type RelationshipData struct {
	ID   string `json:"id"`
	HREF string `json:"href"`
}

type RelationshipsData

type RelationshipsData struct {
	HREF string `json:"href"`
}

type Server

type Server struct {
	ApplicationService mahi.ApplicationService
	UploadService      mahi.UploadService
	FileServeService   mahi.FileServeService
	UsageService       mahi.UsageService
	FileService        mahi.FileService

	QueryDecoder *schema.Decoder

	AuthToken string

	Log zerolog.Logger

	*mux.Router
}

func NewServer

func NewServer(c *ServerConfig) *Server

func (*Server) Authenticate

func (s *Server) Authenticate(next http.Handler) http.Handler

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerConfig

type ServerConfig struct {
	ApplicationService mahi.ApplicationService
	UploadService      mahi.UploadService
	FileServeService   mahi.FileServeService
	UsageService       mahi.UsageService
	FileService        mahi.FileService

	QueryDecoder *schema.Decoder

	AuthToken string

	Log zerolog.Logger
}

Jump to

Keyboard shortcuts

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