bifrost

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 38 Imported by: 2

README

Bifröst

Description Project

forthebadge forthebadge

Prerequisites

  • Go 1.16+

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization            = "Authorization"
	HeaderContentDisposition       = "Content-Disposition"
	HeaderContentEncoding          = "Content-Encoding"
	HeaderContentLength            = "Content-Length"
	HeaderContentType              = "Content-Type"
	HeaderCookie                   = "Cookie"
	HeaderXCSRFToken               = "X-CSRF-Token"
	HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"
	HeaderXTraceId                 = "X-Trace-Id"
	HeaderUberTraceId              = "Uber-Trace-Id"
)
View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + charsetUTF8
	MIMETextXML                          = "text/xml"
	MIMETextXMLCharsetUTF8               = MIMETextXML + "; " + charsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextCSV                          = "text/csv"
	MIMETextCSVCharsetUTF8               = MIMETextCSV + "; " + charsetUTF8
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + charsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
	MIMEImageJPEG                        = "image/jpeg"
	MIMEImagePNG                         = "image/png"
)

MIME types

View Source
const (
	ContentTypeUnknown = iota
	ContentTypePlainText
	ContentTypeHTML
	ContentTypeJSON
	ContentTypeXML
	ContentTypeForm
	ContentTypeMultipartForm
	ContentTypeEventStream
)

ContentTypes handled by this package.

Variables

View Source
var (
	CtxResponse = ctxKeyResponse{Name: "context Respond"}
	CtxVersion  = ctxKeyVersion{Name: "context version"}
)
View Source
var (
	ContentTypeCtxKey = &ctxRender{HeaderContentType}
)
View Source
var CtxError = ctxError{Name: "context error"}
View Source
var (
	RenderContext = ctxRender{Name: "context render"}
)
View Source
var TracerContext = tracerContext{Name: "context Respond"}

Functions

func Base64ToImg added in v0.2.6

func Base64ToImg(w io.Writer, base string) (string, error)

func BindBody added in v0.2.6

func BindBody(r *http.Request, i interface{}) error

func ErrBadGateway added in v0.2.0

func ErrBadGateway(w http.ResponseWriter, r *http.Request, err error) error

ErrBadGateway error http StatusBadGateway

func ErrBadRequest added in v0.2.0

func ErrBadRequest(w http.ResponseWriter, r *http.Request, err error) error

ErrBadRequest error http StatusBadRequest

func ErrForbidden added in v0.2.0

func ErrForbidden(w http.ResponseWriter, r *http.Request, err error) error

ErrForbidden error http StatusForbidden

func ErrGatewayTimeout added in v0.2.0

func ErrGatewayTimeout(w http.ResponseWriter, r *http.Request, err error) error

ErrGatewayTimeout error http StatusGatewayTimeout

func ErrInternalServerError added in v0.2.0

func ErrInternalServerError(w http.ResponseWriter, r *http.Request, err error) error

ErrInternalServerError error http StatusInternalServerError

func ErrMethodNotAllowed added in v0.2.0

func ErrMethodNotAllowed(w http.ResponseWriter, r *http.Request, err error) error

ErrMethodNotAllowed error http StatusMethodNotAllowed

func ErrNotAcceptable added in v0.2.0

func ErrNotAcceptable(w http.ResponseWriter, r *http.Request, err error) error

ErrNotAcceptable error http StatusNotAcceptable

func ErrPaymentRequired added in v0.2.0

func ErrPaymentRequired(w http.ResponseWriter, r *http.Request, err error) error

ErrPaymentRequired error http StatusPaymentRequired

func ErrProxyAuthRequired added in v0.2.0

func ErrProxyAuthRequired(w http.ResponseWriter, r *http.Request, err error) error

ErrProxyAuthRequired error http StatusProxyAuthRequired

func ErrRequestTimeout added in v0.2.0

func ErrRequestTimeout(w http.ResponseWriter, r *http.Request, err error) error

ErrRequestTimeout error http StatusRequestTimeout

func ErrServiceUnavailable added in v0.2.0

func ErrServiceUnavailable(w http.ResponseWriter, r *http.Request, err error) error

ErrServiceUnavailable error http StatusServiceUnavailable

func ErrUnauthorized added in v0.2.0

func ErrUnauthorized(w http.ResponseWriter, r *http.Request, err error) error

ErrUnauthorized error http StatusUnauthorized

func ErrUnprocessableEntity added in v0.2.0

func ErrUnprocessableEntity(w http.ResponseWriter, r *http.Request, err error) error

ErrUnprocessableEntity error http StatusUnprocessableEntity

func ErrUnsupportedMediaType added in v0.2.0

func ErrUnsupportedMediaType(w http.ResponseWriter, r *http.Request, err error) error

ErrUnsupportedMediaType error http StatusUnsupportedMediaType

func GetIdxContentType added in v0.2.6

func GetIdxContentType(s ContentType) string

GetIdxContentType is a middleware that forces response Content-Type.

func GetRootSchema

func GetRootSchema(graphql embed.FS, dir string) (string, error)

func Graph

func Graph(endpoint string) http.HandlerFunc

Graph handler func

func Graphql

func Graphql(graphql embed.FS, dir string, resolver interface{}, opts ...graph.SchemaOpt) http.HandlerFunc

Graphql handler func

func HandlerAdapter added in v0.2.0

func HandlerAdapter(a Adapter) http.HandlerFunc

func HttpTracer added in v0.2.0

func HttpTracer(next http.Handler) http.Handler

func ImgToBase64 added in v0.2.6

func ImgToBase64(r io.ReadCloser) (string, error)

func JSONResponse added in v0.2.0

func JSONResponse(w http.ResponseWriter)

JSONResponse set header content-type to json format

func Redirect added in v0.1.9

func Redirect(w http.ResponseWriter, r *http.Request, url string)

func RenderReader added in v0.1.9

func RenderReader(r *http.Request) interface{}

func RenderWriter added in v0.1.9

func RenderWriter(r *http.Request, value interface{})

func RequestJSONBody added in v0.2.0

func RequestJSONBody(r *http.Request, extract interface{}) error

RequestJSONBody get json body format

func ResponseCSVPayload added in v0.2.0

func ResponseCSVPayload(w http.ResponseWriter, code int, rows [][]string, filename string) error

ResponseCSVPayload set csv payload for response http

func ResponseJSONPayload added in v0.3.0

func ResponseJSONPayload(w http.ResponseWriter, r *http.Request, code int, responses ...interface{}) error

ResponseJSONPayload set payload for response http

func SemanticVersion

func SemanticVersion(r *http.Request, label string, version string)

func SetContentType added in v0.2.6

func SetContentType(contentType ContentType) func(next http.Handler) http.Handler

SetContentType is a middleware that forces response Content-Type.

func ToDelimited added in v0.3.1

func ToDelimited(s string, delimiter uint8) string

ToDelimited converts a string to delimited.snake.case (in this case `delimiter = '.'`)

func ToScreamingDelimited added in v0.3.1

func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string

ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `delimiter = '.'; screaming = true`) or delimited.snake.case (in this case `delimiter = '.'; screaming = false`)

func Transport

func Transport(tlsInsecure bool, timeout int) http.Client

Transport constructs a HTTP client with keep-alive turned off and a dial-timeout of 30 seconds.

func Welkommen

func Welkommen() string

Types

type Adapter added in v0.2.0

type Adapter func(w http.ResponseWriter, r *http.Request) error

type ContentType added in v0.2.6

type ContentType int

ContentType is an enumeration of common HTTP content types.

func GetContentType added in v0.2.6

func GetContentType(s string) ContentType

GetContentType is a middleware that forces response Content-Type.

func GetRequestContentType added in v0.2.6

func GetRequestContentType(r *http.Request) ContentType

GetRequestContentType is a helper function that returns ContentType based on context or request headers.

type GRPCCallback

type GRPCCallback func(*rpc.Server)

type GRPCOpts

type GRPCOpts struct {
	Port GRPCPort
	Opts []rpc.ServerOption
}

type GRPCPort

type GRPCPort int

type GRpc

type GRpc struct {
	Port GRPCPort
	Opts []rpc.ServerOption
	// contains filtered or unexported fields
}

func NewServerGRPC

func NewServerGRPC(opts GRPCOpts) *GRpc

func (*GRpc) Quiet

func (g *GRpc) Quiet()

func (*GRpc) Run

func (g *GRpc) Run(callback GRPCCallback) error

func (*GRpc) Stop

func (g *GRpc) Stop()

type Https

type Https bool

type Meta

type Meta struct {
	Code    string `json:"code,omitempty"`
	Type    string `json:"error_type,omitempty"`
	Message string `json:"error_message,omitempty"`
}

type Pagination added in v0.3.0

type Pagination struct {
	Limit      int         `json:"limit"`
	NextCursor interface{} `json:"next_cursor"`
}

func (Pagination) GetLimit added in v0.3.0

func (p Pagination) GetLimit() int

type Response

type Response struct {
	Version    interface{} `json:"version,omitempty"`
	Meta       interface{} `json:"meta,omitempty"`
	Data       interface{} `json:"data,omitempty"`
	Pagination interface{} `json:"pagination,omitempty"`
}

type ServeOpts

type ServeOpts struct {
	Port     WebPort
	TimeOut  WebTimeOut
	TLS      Https
	CertFile string
	KeyFile  string
}

type Server

type Server struct {
	Port     WebPort
	TimeOut  WebTimeOut
	TLS      Https
	CertFile string
	KeyFile  string
	// contains filtered or unexported fields
}

func NewServerMux

func NewServerMux(opts ServeOpts) *Server

func (*Server) Quiet

func (s *Server) Quiet(ctx context.Context)

func (*Server) Run

func (s *Server) Run(handler http.Handler) error

func (*Server) Stop

func (s *Server) Stop()

type Version

type Version struct {
	Label  string `json:"label,omitempty"`
	Number string `json:"number,omitempty"`
}

type WebPort

type WebPort int

type WebTimeOut

type WebTimeOut int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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