Documentation ¶
Index ¶
- Constants
- func Copy(source interface{}, destine interface{}) error
- func Debug(v ...interface{})
- func Die(args ...interface{})
- func Dief(args ...interface{})
- func Err(args ...interface{})
- func Errf(args ...interface{})
- func Fmt(s string, v ...interface{}) string
- func FromJSON(encoded []byte, v interface{}) error
- func GetEnv(key string, def string) string
- func GetPathPattern(t string) string
- func GetPathVars(t string, p string) (map[string]string, error)
- func IndexOf(i interface{}, l interface{}) int
- func Jsonify(v interface{}) []byte
- func Log(args ...interface{})
- func Logf(args ...interface{})
- func Merge(source interface{}, destine interface{}, override ...bool) (interface{}, error)
- func RawLog(typ string, useCaller bool, args ...interface{})
- func StatusText(code int) string
- func UseLogger(l *Logger)
- func War(args ...interface{})
- func Warf(args ...interface{})
- type Bullet
- type Config
- type Dict
- type Json
- type Logger
- type Pistol
- func (pistol *Pistol) Add(path string, route interface{}, methods ...string) *Pistol
- func (pistol *Pistol) AddPlugin(plugin Plugin) *Pistol
- func (pistol *Pistol) Error() error
- func (pistol *Pistol) GetPath() string
- func (pistol *Pistol) GetRoutes() Dict
- func (pistol *Pistol) Run(a ...interface{}) error
- func (pistol *Pistol) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (pistol *Pistol) SetErr(err error)
- type Plugin
- type Prop
- type Request
- type Response
Constants ¶
const ( LogLevelInfo = "\033[32;1m[info] \033[00m" LogLevelWarn = "\033[33;1m[warn] \033[00m" LogLevelError = "\033[31;1m[fail] \033[00m" )
const ( StatusContinue = 100 StatusSwitchingProtocols = 101 StatusProcessing = 102 StatusEarlyHints = 103 StatusOK = 200 StatusCreated = 201 StatusAccepted = 202 StatusNonAuthoritativeInfo = 203 StatusNoContent = 204 StatusResetContent = 205 StatusPartialContent = 206 StatusMultiStatus = 207 StatusAlreadyReported = 208 StatusIMUsed = 226 StatusMultipleChoices = 300 StatusMovedPermanently = 301 StatusFound = 302 StatusSeeOther = 303 StatusNotModified = 304 StatusUseProxy = 305 StatusTemporaryRedirect = 307 StatusPermanentRedirect = 308 StatusBadRequest = 400 StatusPaymentRequired = 402 StatusForbidden = 403 StatusNotFound = 404 StatusMethodNotAllowed = 405 StatusNotAcceptable = 406 StatusProxyAuthRequired = 407 StatusRequestTimeout = 408 StatusConflict = 409 StatusGone = 410 StatusLengthRequired = 411 StatusPreconditionFailed = 412 StatusRequestEntityTooLarge = 413 StatusRequestURITooLong = 414 StatusUnsupportedMediaType = 415 StatusRequestedRangeNotSatisfiable = 416 StatusExpectationFailed = 417 StatusTeapot = 418 StatusMisdirectedRequest = 421 StatusUnprocessableEntity = 422 StatusLocked = 423 StatusFailedDependency = 424 StatusTooEarly = 425 StatusUpgradeRequired = 426 StatusPreconditionRequired = 428 StatusTooManyRequests = 429 StatusRequestHeaderFieldsTooLarge = 431 StatusInternalServerError = 500 StatusNotImplemented = 501 StatusBadGateway = 502 StatusGatewayTimeout = 504 StatusHTTPVersionNotSupported = 505 StatusVariantAlsoNegotiates = 506 StatusInsufficientStorage = 507 StatusLoopDetected = 508 StatusNotExtended = 510 StatusNetworkAuthenticationRequired = 511 )
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
func Copy(source interface{}, destine interface{}) error
Sex utility function to make copy of map or struct to another map or struct Required: Destine need to be a pointer Example:
var m struct { Name string `json:"name"` } j := Dict{ "name": "Joao", } Sex.Copy(j, &m)
func Die ¶
func Die(args ...interface{})
Logging error logs with Sex.Logger() and killing the application
func Dief ¶ added in v0.3.0
func Dief(args ...interface{})
Logging error logs with Sex.Logger() and killing the application Example:
Dief("%s %+v", "joao", []string{"joao", "maria"}) Dief("%.2f", 409.845)
func Errf ¶ added in v0.3.0
func Errf(args ...interface{})
Logging error formated logs with Sex.Logger() Example:
Errf("%s %+v", "joao", []string{"joao", "maria"}) Errf("%.2f", 409.845)
func FromJSON ¶ added in v0.4.8
FromJSON function thats parse a byte list on a json and write on a variable Required: v needs to be a pointer
func GetPathPattern ¶
Function to get regex pattern of a Sex path template Example:
Sex.GetPathPattern("/hello/{name}")
func GetPathVars ¶
Function to get variables of a path using a Sex path template Example:
Sex.GetPathVars("/hello/{name}", "/hello/joao")
func IndexOf ¶ added in v0.4.8
func IndexOf(i interface{}, l interface{}) int
IndexOf function to index first ocurrence of string on string slice
func Jsonify ¶
func Jsonify(v interface{}) []byte
Jsonify function thats parse a byte list on a json and write on a variable
func Logf ¶ added in v0.3.0
func Logf(args ...interface{})
Logging information formated logs with Sex.Logger() Example:
Logf("%s %+v", "joao", []string{"joao", "maria"}) Logf("%.2f", 409.845)
func Merge ¶
Sex utility function to make merge of map or struct and another map or struct Required: Destine need to be a pointer Example:
var m := struct { Name string `json:"name"` } { Name: "Joao", } j := Dict{ "idade": "Joao", "name": nil, } f := Sex.Merge(m, &j)
Merge rules:
If the field on source dont exists on destine it will be created (just if destine are map) If the field on source exists on destine but are dont seted it will be seted If the field on source exists on destine but are seted it will not be seted If override are seted as true, the field on destine will be overrided by source
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
Types ¶
type Bullet ¶
type Bullet struct { Message string `json:"message,omitempty"` Type string `json:"type,omitempty"` Data interface{} `json:"data,omitempty"` }
Suggested template for Sex.Json endpoint functions
type Pistol ¶
Pistol is the Sex HTTP handler, who are used to setup http server Example:
router := Sex.NewPistol(). Add("/", func(Sex.Request) string { return "Hello World" }). Run()
func NewPistol ¶ added in v0.3.0
func NewPistol() *Pistol
Function thats create a Sex.Pistol and create the init configurations Example:
router := Sex.NewPistol()
func (*Pistol) Add ¶
Function to Add endpoints to the Sex.Pistol Server path are the endpoint location route is a void interface thats need to be on next format list:
- func (http.ResponseWriter, *http.Request)
- func (Sex.Request) Sex.Response (res, status)
- func (Sex.Request) string // Or (string, int)
- func (Sex.Request) []byte // Or ([]byte, int)
- func (Sex.Request) Sex.Json // Or (Sex.Json, int)
methods are a list of accepted HTTP methods to endpoint Example:
router.Add("/", func(Sex.Request) string { return "Hello World" }, "POST") router.Add("/ok", func(Sex.Request) Sex.Json, int { return map[stirng]bool{ "ok": true, }, 404 })
func (*Pistol) Run ¶
Function to execute de Sex.Pistol server Example:
pistol.Run(5000) // Will run server on port 5000 pistol.Run("/joao") // will run server on path "/joao" pistol.Run("/joao", 80) // will run server on path "/joao" and port 80 pistol.Run(80, "/joao") // will run server on path "/joao" and port 80
If you run a Sex Pistol server with $SEX_DEBUG setted as "true" thats function will to log list all Sex endpoints of router
type Prop ¶
Prop are map of properties
func (Prop) Add ¶ added in v0.4.8
Add adds the key, value pair to the header. It appends to any existing values associated with key. The key is case sensitive.
func (Prop) Del ¶ added in v0.4.8
Del deletes the values associated with key. The key is case sensitive.
func (Prop) Get ¶ added in v0.4.8
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". It is case sensitive.
func (Prop) Has ¶ added in v0.4.8
Has reports whether h has the provided key defined, even if it's set to 0-length slice.
type Request ¶
Request properties sent by client (*http.Request) with inproviments like path variables and Pistol Route configurations Example:
router.Add("/hello/{name}", func (r Sex.Request) string { name := r.PathVars["name"] return "Hello "+ name }
type Response ¶
Response to make complete response with Cookies, Headers, and all http.ResponseWrite another features
func (*Response) WriteHeader ¶ added in v0.4.2
Function to set Response status code