picoweb

package module
v0.0.0-...-a22e4d6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 30 Imported by: 1

README

WIP - Not ready to use

picoweb - tiny web franework

Teeny Tiny Web Wrapper around httprouter

Features

  • Fast - thanks to httprouter
  • graceful shutdown
  • socketio
  • raw WebSocket (soon)
  • more on the way
    package main

    import (
        "fmt"

        "github.com/sfi2k7/picoweb"
    )

    func Home(c *picoweb.Context) {
        fmt.Fprint(c, "Hello Pico")
    }

    func main() {
        pico := picoweb.New()
        pico.Static("/static", "./static")
        pico.Get("/", Home)
        pico.Listen(7777)
    }

Enable Production Mode

    pico.Production()

Parameters

    pico.Get("/:name",func (c *picoweb.Context){
        userName := c.Params("name")
    })

License

MIT - Please see the LICENSE file

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelClosed = errors.New("channel closed")
)
View Source
var WsForceClose = WsData{"close": true}

Functions

func ID

func ID() string

func NewGenericHandler

func NewGenericHandler(c *websocket.Conn) *genericconnectionhandler

func WsDataGoChannel

func WsDataGoChannel(cap int) *wsDataGoChannel

Types

type Context

type Context struct {
	SessionId string

	Start       time.Time
	IsWebsocket bool
	UserManager *usermanager
	AppName     string
	User        interface{}
	State       interface{}
	// contains filtered or unexported fields
}

func (*Context) BasicAuth

func (c *Context) BasicAuth() (string, string, bool)

func (*Context) Body

func (c *Context) Body() ([]byte, error)

func (*Context) Bytes

func (c *Context) Bytes() []byte

func (*Context) File

func (c *Context) File(filePath string, mimeType string)

func (*Context) FileHTML

func (c *Context) FileHTML(filePath string)

func (*Context) Form

func (c *Context) Form(key string) string

func (*Context) GetCookie

func (c *Context) GetCookie(name string) string

func (*Context) GetStaticDirFile

func (c *Context) GetStaticDirFile() (string, string)

func (*Context) GetStaticFile

func (c *Context) GetStaticFile() string

func (*Context) GetStaticFileExt

func (c *Context) GetStaticFileExt() string

func (*Context) GetStaticFilePath

func (c *Context) GetStaticFilePath() string

func (*Context) HasPrefix

func (c *Context) HasPrefix(prefix string) bool

func (*Context) Header

func (c *Context) Header(key string) string

func (*Context) Host

func (c *Context) Host() string

func (*Context) IsStatic

func (c *Context) IsStatic() bool

func (*Context) Json

func (c *Context) Json(data interface{}) (int, error)

func (*Context) Method

func (c *Context) Method() string

func (*Context) Mongo

func (c *Context) Mongo() (*mgo.Session, error)

func (*Context) Params

func (c *Context) Params(name string) string

func (*Context) ParseBody

func (c *Context) ParseBody(target interface{}) error

func (*Context) Path

func (c *Context) Path() string

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) QueryBool

func (c *Context) QueryBool(key string) (bool, error)

func (*Context) QueryCaseIn

func (c *Context) QueryCaseIn(key string) string

func (*Context) QueryInt

func (c *Context) QueryInt(key string) (int, error)

func (*Context) R

func (c *Context) R() *http.Request

func (*Context) Redirect

func (c *Context) Redirect(url string, code int)

func (*Context) Redis

func (c *Context) Redis() (*redis.Client, error)

func (*Context) RemoteIP

func (c *Context) RemoteIP() string

func (*Context) RemoveCookie

func (c *Context) RemoveCookie(name string)

func (*Context) ResponseHeader

func (c *Context) ResponseHeader() http.Header

func (*Context) SessionHash

func (c *Context) SessionHash() string

func (*Context) SetCookie

func (c *Context) SetCookie(name, value string, expireIn time.Duration)

func (*Context) SetHeader

func (c *Context) SetHeader(key string, value string)

func (*Context) Status

func (c *Context) Status(statusCode int)

func (*Context) Status401

func (c *Context) Status401()

func (*Context) Status403

func (c *Context) Status403()

func (*Context) Status404

func (c *Context) Status404()

func (*Context) StatusServerError

func (c *Context) StatusServerError()

func (*Context) String

func (c *Context) String(str string)

func (*Context) URL

func (c *Context) URL() *url.URL

func (*Context) URLHashPart

func (c *Context) URLHashPart() string

func (*Context) Upgrade

func (c *Context) Upgrade() (*websocket.Conn, error)

func (*Context) View

func (c *Context) View(filePath string, data interface{}) error

func (*Context) W

func (c *Context) W() http.ResponseWriter

func (Context) Write

func (c Context) Write(b []byte) (int, error)

func (Context) WriteHeader

func (c Context) WriteHeader(n int)

type Flash

type Flash map[string]interface{}

func (Flash) Clear

func (f Flash) Clear()

func (Flash) Get

func (f Flash) Get(sessionId string) interface{}

func (Flash) Has

func (f Flash) Has(sessionId string) bool

func (Flash) Set

func (f Flash) Set(sessionId string, value interface{})

type GenericWsGoServer

type GenericWsGoServer struct {
	MessageHandler WsHandler
	// contains filtered or unexported fields
}

func (*GenericWsGoServer) Close

func (wsg *GenericWsGoServer) Close()

func (*GenericWsGoServer) Handle

func (wsg *GenericWsGoServer) Handle(c *Context)

type GoChannel

type GoChannel struct {
	IsClosed bool
	// contains filtered or unexported fields
}

func Channel

func Channel(cap int) *GoChannel

func (*GoChannel) Close

func (gc *GoChannel) Close()

func (*GoChannel) In

func (gc *GoChannel) In(v interface{}) error

func (*GoChannel) Out

func (gc *GoChannel) Out() chan interface{}

type Interface

type Interface interface{}

type Pico

type Pico struct {
	Mux *httprouter.Router
	// contains filtered or unexported fields
}

func New

func New() *Pico

func (*Pico) After

func (p *Pico) After(m middlewarehandler)

func (*Pico) Before

func (p *Pico) Before(m middlewarehandler)

func (*Pico) BroadcastWS

func (p *Pico) BroadcastWS(data WsData)

func (*Pico) CustomNotFound

func (p *Pico) CustomNotFound()

func (*Pico) Delete

func (p *Pico) Delete(pattern string, fn PicoHandler)

func (*Pico) Get

func (p *Pico) Get(pattern string, fn PicoHandler)

func (*Pico) GetFlash

func (p *Pico) GetFlash(sessionId string) interface{}

func (*Pico) Listen

func (p *Pico) Listen(port int) error

func (*Pico) ListenS

func (p *Pico) ListenS(port string)

func (*Pico) ListenTLS

func (p *Pico) ListenTLS(port, cert, key string)

func (*Pico) MongoURL

func (p *Pico) MongoURL(murl string)

func (*Pico) Must

func (p *Pico) Must(m middlewarehandler)

func (*Pico) Options

func (p *Pico) Options(pattern string, fn PicoHandler)

func (*Pico) Post

func (p *Pico) Post(pattern string, fn PicoHandler)

func (*Pico) Production

func (p *Pico) Production()

func (*Pico) Put

func (p *Pico) Put(pattern string, fn PicoHandler)

func (*Pico) RedisURL

func (p *Pico) RedisURL(rurl string, redispassword ...string)

func (*Pico) SendWS

func (p *Pico) SendWS(id string, data WsData)

func (*Pico) SetAppName

func (p *Pico) SetAppName(appname string)

func (*Pico) SetFlash

func (p *Pico) SetFlash(sessionId string, value interface{})

func (*Pico) SkipAllMiddlewares

func (p *Pico) SkipAllMiddlewares()

func (*Pico) Static

func (p *Pico) Static(urlPath, diskPath string)

func (*Pico) StaticDefault

func (p *Pico) StaticDefault(diskPath string)

func (*Pico) Stop

func (p *Pico) Stop()

func (*Pico) StopOnInt

func (p *Pico) StopOnInt()

func (*Pico) StopOnIntWithFunc

func (p *Pico) StopOnIntWithFunc(fn func())

func (*Pico) Use

func (p *Pico) Use(m middlewarehandler)

func (*Pico) UseUserManager

func (p *Pico) UseUserManager(url, password string)

func (*Pico) Ws

func (p *Pico) Ws(pattern string, mh WsHandler)

type PicoClient

type PicoClient struct {
	Headers     map[string]string
	ContentType string
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *PicoClient

func (*PicoClient) Get

func (pc *PicoClient) Get(url string) ([]byte, error)

func (*PicoClient) Post

func (pc *PicoClient) Post(url string, data []byte) ([]byte, error)

func (*PicoClient) Put

func (pc *PicoClient) Put(url string, data []byte) ([]byte, error)

type PicoHandler

type PicoHandler func(c *Context)

type PicoStat

type PicoStat struct {
	NumGoRoutines     int
	NumWSConns        int
	TotalRequestCount int
	Uptime            time.Duration
	StartedOn         time.Time
}

type Subscribers

type Subscribers map[string]struct{}

type WSArgs

type WSArgs struct {
	ID      string
	Command string
	Body    WsData
	Channel string
	Group   string
	Node    string
	Account string
}

type WsData

type WsData map[string]Interface

func WsDataFromMapString

func WsDataFromMapString(m map[string]string) WsData

func WsDataFromString

func WsDataFromString(v string) *WsData

func (WsData) ArrayString

func (wd WsData) ArrayString(k string) []string

func (WsData) Bool

func (wd WsData) Bool(k string) bool

func (WsData) Clone

func (wd WsData) Clone() WsData

func (WsData) DataAsString

func (wd WsData) DataAsString(k string) string

func (WsData) Get

func (wd WsData) Get(k string) Interface

func (WsData) Int

func (wd WsData) Int(k string) int

func (WsData) Json

func (wd WsData) Json() string

func (WsData) Remove

func (wd WsData) Remove(k string)

func (WsData) Set

func (wd WsData) Set(k string, v Interface)

func (WsData) String

func (wd WsData) String(k string) string

type WsHandler

type WsHandler func(args *WSArgs) WsData

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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