Documentation ¶
Index ¶
- Constants
- func Copy(source interface{}, destine interface{}) error
- 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 GenericBuff() reflect.Type
- func GenericForm() reflect.Type
- func GenericInt() reflect.Type
- func GenericInterface() reflect.Type
- func GenericJsonArray() reflect.Type
- func GenericJsonObj() reflect.Type
- func GenericMultipartForm() reflect.Type
- func GenericString() reflect.Type
- func GetEnv(key string, def string) string
- func GetPathPattern(t string) string
- func GetPathVars(t string, p string) (map[string]string, error)
- func Jsonify(v interface{}) []byte
- func Log(args ...interface{})
- func Logf(args ...interface{})
- func Logger() *log.Logger
- func Merge(source interface{}, destine interface{}, override ...bool) (map[string]interface{}, error)
- func StatusText(code int) string
- func SuperPut(v ...interface{})
- func TypeParse(t string) string
- func ValidateData(data interface{}, t func() reflect.Type) bool
- func War(args ...interface{})
- func Warf(args ...interface{})
- type Bullet
- type Dict
- type Json
- type Pistol
- func (pistol *Pistol) Add(path string, route interface{}, methods ...string) *Pistol
- func (pistol *Pistol) AddRaw(path string, f func(http.ResponseWriter, *http.Request), methods ...string) *Pistol
- func (pistol *Pistol) Run(a ...interface{}) error
- func (pistol *Pistol) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Prop
- type Request
- type Response
Constants ¶
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 StatusEarlyHints = 103 // RFC 8297 StatusOK = 200 // RFC 7231, 6.3.1 StatusCreated = 201 // RFC 7231, 6.3.2 StatusAccepted = 202 // RFC 7231, 6.3.3 StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4 StatusNoContent = 204 // RFC 7231, 6.3.5 StatusResetContent = 205 // RFC 7231, 6.3.6 StatusPartialContent = 206 // RFC 7233, 4.1 StatusMultiStatus = 207 // RFC 4918, 11.1 StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusMovedPermanently = 301 // RFC 7231, 6.4.2 StatusFound = 302 // RFC 7231, 6.4.3 StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusNotModified = 304 // RFC 7232, 4.1 StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusPermanentRedirect = 308 // RFC 7538, 3 StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusForbidden = 403 // RFC 7231, 6.5.3 StatusNotFound = 404 // RFC 7231, 6.5.4 StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusConflict = 409 // RFC 7231, 6.5.8 StatusGone = 410 // RFC 7231, 6.5.9 StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusTeapot = 418 // RFC 7168, 2.3.3 StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusTooEarly = 425 // RFC 8470, 5.2. StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 StatusNotExtended = 510 // RFC 2774, 7 StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 )
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 := map[string]interface{}{ "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 ¶
Function thats parse a byte list on a json and write on a variable Required: v needs to be a pointer
func GenericBuff ¶
func GenericForm ¶
func GenericInt ¶
func GenericInterface ¶
func GenericJsonArray ¶
func GenericJsonObj ¶
func GenericMultipartForm ¶
func GenericString ¶
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 Jsonify ¶
func Jsonify(v interface{}) []byte
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 ¶
func Merge(source interface{}, destine interface{}, override ...bool) (map[string]interface{}, error)
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 := map[string]interface{}{ "idade": "Joao", "name": nil, } Sex.Copy(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.
func ValidateData ¶
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 ¶
type Pistol struct { *http.ServeMux RootPath string RouteConfs Dict Routes Dict RawRoutes []string Auth bool }
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) AddRaw ¶ added in v0.3.5
func (pistol *Pistol) AddRaw(path string, f func(http.ResponseWriter, *http.Request), methods ...string) *Pistol
Function to Add golang raw http endpoints to the Sex.Pistol Server Example:
router.AddRaw("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World")) })
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 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 }
func (*Request) JsonBody ¶
Request function to write Json body on a variable Example:
var data map[string]interface{} // Can be Structs too r.JsonBody(&data)
func (*Request) MkResponse ¶
Request function to get Response Writer
type Response ¶
type Response struct { http.ResponseWriter Body []byte Status int }
Response to make complete response with Cookies, Headers, and all http.ResponseWrite another features