Sex

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: MPL-2.0 Imports: 15 Imported by: 2

README

Sex Pistol Icon

Sex Pistol


A Sex web micro framework for GoLang.

Get Started


Install

It is easy, just take that command on your favorite terminal:

$ go get github.com/Plankiton/SexPistol

First Code

Its so easy like that:

package main
import "github.com/Plankiton/SexPistol"
func main() {
    Sex.NewPistol().
    Add("/{name}", func (r Sex.Request) string {
        return Sex.Fmt("Hello, %s", r.PathVars["name"])
    }).
    Run()
}

Too sex no? That code make the same thing what the code above:

Code using default library from Go

package main
import (
    "net/http"
    "fmt"
    "strings"
)

func main() {
    http.HandleFunc("/",func Hello (w http.ResponseWriter, r *http.Request) {
        path := strings.Split(r.URL.Path, "/")

        w.WriteHeader(200)
        w.Write([]byte(fmt.Sprintf(
            "Hello, %s", path[len(path)-1],
        )))
    })

    http.ListenAndServe(":8000", nil)
}

Md Documentation | Html Documentation

Documentation

Index

Constants

View Source
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
	StatusUnauthorized                 = 401 // RFC 7235, 3.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
	StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3

	StatusInternalServerError           = 500 // RFC 7231, 6.6.1
	StatusNotImplemented                = 501 // RFC 7231, 6.6.2
	StatusBadGateway                    = 502 // RFC 7231, 6.6.3
	StatusServiceUnavailable            = 503 // RFC 7231, 6.6.4
	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

func Die

func Die(args ...interface{})

func Dief added in v0.3.0

func Dief(args ...interface{})

func Err

func Err(args ...interface{})

func Errf added in v0.3.0

func Errf(args ...interface{})

func Fmt

func Fmt(s string, v ...interface{}) string

func FromJson

func FromJson(encoded []byte, v interface{}) error

func GenericBuff

func GenericBuff() reflect.Type

func GenericForm

func GenericForm() reflect.Type

func GenericInt

func GenericInt() reflect.Type

func GenericInterface

func GenericInterface() reflect.Type

func GenericJsonArray

func GenericJsonArray() reflect.Type

func GenericJsonObj

func GenericJsonObj() reflect.Type

func GenericMultipartForm

func GenericMultipartForm() reflect.Type

func GenericString

func GenericString() reflect.Type

func GetEnv

func GetEnv(key string, def string) string

func GetPathPattern

func GetPathPattern(t string) string

func GetPathVars

func GetPathVars(t string, p string) (map[string]string, error)

func Jsonify

func Jsonify(v interface{}) []byte

func Log

func Log(args ...interface{})

func Logf added in v0.3.0

func Logf(args ...interface{})

func Logger added in v0.3.0

func Logger() *log.Logger

func Merge

func Merge(source interface{}, destine interface{}) (map[string]interface{}, error)

func StatusText

func StatusText(code int) string

StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.

func SuperPut

func SuperPut(v ...interface{})

func ToLabel

func ToLabel(ID interface{}, Type string) string

func TypeParse

func TypeParse(t string) string

func ValidateData

func ValidateData(data interface{}, t func() reflect.Type) bool

func War

func War(args ...interface{})

func Warf added in v0.3.0

func Warf(args ...interface{})

Types

type Bullet

type Bullet struct {
	Message string      `json:"message,omitempty"`
	Type    string      `json:"type,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

type Dict

type Dict map[string]Prop

type Json

type Json interface{}

type Pistol

type Pistol struct {
	RootPath   string
	RouteConfs Dict
	Routes     Dict
	Auth       bool
	Mux        *http.ServeMux
}

func NewPistol added in v0.3.0

func NewPistol() *Pistol

func (*Pistol) Add

func (router *Pistol) Add(path string, route interface{}, methods ...string) *Pistol

func (*Pistol) Fusion added in v0.3.3

func (router *Pistol) Fusion(mux *http.ServeMux) *Pistol

func (*Pistol) RootRoute

func (router *Pistol) RootRoute(w http.ResponseWriter, r *http.Request)

func (*Pistol) Run

func (router *Pistol) Run(a ...interface{}) error

type Prop

type Prop map[string]interface{}

type Request

type Request struct {
	*http.Request
	PathVars map[string]string
	Conf     Prop
	Writer   *Response
}

func (*Request) JsonBody

func (self *Request) JsonBody(v interface{}) error

func (*Request) MkResponse

func (self *Request) MkResponse() *Response

func (*Request) RawBody

func (self *Request) RawBody(b *[]byte) error

type Response

type Response struct {
	http.ResponseWriter
	Body   []byte
	Status int
}

func (*Response) SetBody

func (self *Response) SetBody(v []byte) *Response

func (*Response) SetCookie

func (self *Response) SetCookie(key string, value string, expires time.Duration) *Response

func (*Response) SetStatus

func (self *Response) SetStatus(code int) *Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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