Documentation ¶
Index ¶
- Constants
- Variables
- func Env(target interface{}, dotEnvFilePaths ...string) error
- func EnvReadFiles(dotEnvFilePaths ...string)
- func EnvUnmarshal(target interface{}) error
- func LoggerAddRequestID(r *http.Request) *http.Request
- func LoggerGetRequestID(r *http.Request) string
- func RespondHTML(w http.ResponseWriter, statusCode int, body []byte)
- func RespondJSON(w http.ResponseWriter, statusCode int, v interface{})
- func RespondText(w http.ResponseWriter, statusCode int, body []byte)
- func Run(app App)
- type App
- type AuthorizeBearer
- type HTTPLogger
- type HTTPRouter
- type HTTPStatic
- type Logger
- type LoggerJSON
- func (logger *LoggerJSON) Debug(r *http.Request, message string, context map[string]interface{}) error
- func (logger *LoggerJSON) Error(r *http.Request, message string, context map[string]interface{}) error
- func (logger *LoggerJSON) Info(r *http.Request, message string, context map[string]interface{}) error
- func (logger *LoggerJSON) Warning(r *http.Request, message string, context map[string]interface{}) error
- type Response
- type RestAuthorizer
- type RestClient
Constants ¶
const ( LogLevelError = "error" LogLevelWarning = "warning" LogLevelInfo = "info" LogLevelDebug = "debug" )
Log Levels
const ( HeaderContentType = "Content-Type" HeaderCacheControl = "Cache-Control" )
Header Constants
const (
ResponseTextNotFound = "Not Found"
)
Response Constants
Variables ¶
var ( // ErrInvalidValue returned when the value passed to Unmarshal is nil or not a // pointer to a struct. ErrInvalidValue = errors.New("value must be a non-nil pointer to a struct") // ErrUnsupportedType returned when a field with tag "env" is unsupported. ErrUnsupportedType = errors.New("field is an unsupported type") // ErrUnexportedField returned when a field with tag "env" is not exported. ErrUnexportedField = errors.New("field must be exported") )
Functions ¶
func EnvReadFiles ¶ added in v0.1.3
func EnvReadFiles(dotEnvFilePaths ...string)
EnvReadFiles locates and parses .env files
func EnvUnmarshal ¶ added in v0.1.3
func EnvUnmarshal(target interface{}) error
EnvUnmarshal into a target struct
func LoggerAddRequestID ¶ added in v0.1.3
LoggerAddRequestID adds the request ID to the request
func LoggerGetRequestID ¶ added in v0.1.3
LoggerGetRequestID gets the request ID off of the request if there is one
func RespondHTML ¶ added in v0.1.3
func RespondHTML(w http.ResponseWriter, statusCode int, body []byte)
RespondHTML responds to an http.Request with a text body
func RespondJSON ¶ added in v0.1.3
func RespondJSON(w http.ResponseWriter, statusCode int, v interface{})
RespondJSON responds to an http.Request with a JSON body
func RespondText ¶ added in v0.1.3
func RespondText(w http.ResponseWriter, statusCode int, body []byte)
RespondText responds to an http.Request with a text body
Types ¶
type AuthorizeBearer ¶ added in v0.1.3
type AuthorizeBearer struct {
Token string
}
AuthorizeBearer authorizes a http request using a bearer token
type HTTPLogger ¶ added in v0.1.3
HTTPLogger logs all request before passing off to the Handler
func (*HTTPLogger) ServeHTTP ¶ added in v0.1.3
func (logger *HTTPLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServerHTTP satisfies the http.Handler interface
type HTTPRouter ¶ added in v0.1.3
HTTPRouter serves http.Requests for a predefined map of Paths
func (*HTTPRouter) ServeHTTP ¶ added in v0.1.3
func (router *HTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServerHTTP satisfies the http.Handler interface
type HTTPStatic ¶ added in v0.1.3
type HTTPStatic struct { FileSystem http.FileSystem NotFoundHandler http.Handler // contains filtered or unexported fields }
HTTPStatic servers static files without directory listings
func (*HTTPStatic) ServeHTTP ¶ added in v0.1.3
func (static *HTTPStatic) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServerHTTP satisfies the http.Handler interface
type Logger ¶
type Logger interface { // Error logs an error message Error(r *http.Request, message string, context map[string]interface{}) error // Info logs an info message Info(r *http.Request, message string, context map[string]interface{}) error // Warning logs a warning message Warning(r *http.Request, message string, context map[string]interface{}) error // Debug logs a debug message Debug(r *http.Request, message string, context map[string]interface{}) error }
Logger Service
type LoggerJSON ¶ added in v0.1.3
LoggerJSON is a JSON logger
func (*LoggerJSON) Debug ¶ added in v0.1.3
func (logger *LoggerJSON) Debug(r *http.Request, message string, context map[string]interface{}) error
Debug logs a debug message
func (*LoggerJSON) Error ¶ added in v0.1.3
func (logger *LoggerJSON) Error(r *http.Request, message string, context map[string]interface{}) error
Error logs an error message
type Response ¶
type Response struct { Status bool `json:"status"` Message string `json:"message"` Data interface{} `json:"data"` }
Response is a basic response structure
type RestAuthorizer ¶ added in v0.1.3
RestAuthorizer defines how to authorize http requests
type RestClient ¶ added in v0.1.3
type RestClient struct {
Authorizer RestAuthorizer
}
RestClient sets up a way to make http requests