fipple

package module
v0.0.0-...-4487d49 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 16 Imported by: 0

README

fipple

fipple is a RESTful web service framework in Go.

Usage

To set up a RESTful web service with fipple, you just need following 2 steps.

  1. Register services
fipple.Get("/:id",function(ctx fipple.Context) {
    //a GET service
    id := ctx.GetStringParam("id")
})

fipple.Post("/create",function(ctx fipple.Context) {
    //a POST service
})
  1. Start
fipple.Start(port)

Context Context is your friend. It provides approach to both Request and Response.

For example, to get parameters:

ctx.GetStringParam("id")

To get posted data:

user := new(User)
err := ctx.GetEntity(user)

Or, to send response:

  • Status
ctx.ServeStatus( http.StatusOK)
  • JSON data
ctx.ServeJson(user)
  • HTML

  • XML

  • Plain text

  • HTML file

  • Static file

  • By template

For detailed usage, please refer to the project page

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxUploadSize int64 = 1024 * 1024

const DefaultMaxUploadSize = 1024*1024

View Source
var SupportedUploadFileTypes = []string{"jpg", "jpeg", "gif", "png"}

Functions

func AddRoute

func AddRoute(route *route)

func AddRoutes

func AddRoutes(route ...*route)

func AddTemplGlob

func AddTemplGlob(pattern string)

func Delete

func Delete(path string, action action)

func DeleteRoute

func DeleteRoute(path string, action action) *route

func Get

func Get(path string, action action)

func GetRoute

func GetRoute(path string, action action) *route

func Post

func Post(path string, action action)

func PostRoute

func PostRoute(path string, action action) *route

func PutRoute

func PutRoute(path string, action action) *route

func ServeHTTP

func ServeHTTP(rw http.ResponseWriter, req *http.Request)

func SetLogger

func SetLogger(log fiplog.Logger)

func Start

func Start(port string) error

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext(rw http.ResponseWriter, req *http.Request) *Context

func (*Context) BadRequest

func (ctx *Context) BadRequest()

func (*Context) Conflict

func (ctx *Context) Conflict()

func (*Context) GetEntity

func (ctx *Context) GetEntity(v interface{}) (err error)

func (*Context) GetFields

func (ctx *Context) GetFields() (fields *Fields, err error)

func (*Context) GetIntParam

func (ctx *Context) GetIntParam(key string) (i int)

func (*Context) GetIntParamWithDefault

func (ctx *Context) GetIntParamWithDefault(key string, defaultVal int) int

func (*Context) GetIntQuery

func (ctx *Context) GetIntQuery(key string, dflt int) int

func (*Context) GetParam

func (ctx *Context) GetParam(key string) interface{}

func (*Context) GetPlainReq

func (ctx *Context) GetPlainReq() (body []byte)

func (*Context) GetQuery

func (ctx *Context) GetQuery(key string) string

func (*Context) GetReqHeader

func (ctx *Context) GetReqHeader(key string) (val string)

func (*Context) GetStringParam

func (ctx *Context) GetStringParam(key string) (s string)

func (*Context) GetUploadedFile

func (ctx *Context) GetUploadedFile() *UploadedFile

var UploadPath = "."

func (*Context) InternalError

func (ctx *Context) InternalError()

func (*Context) MethodNotAllowed

func (ctx *Context) MethodNotAllowed()

func (*Context) Ok

func (ctx *Context) Ok()

func (*Context) OkOrError

func (ctx *Context) OkOrError(ok bool)

func (*Context) PageNotFound

func (ctx *Context) PageNotFound()

func (*Context) Request

func (ctx *Context) Request() *http.Request

func (*Context) ResponseWriter

func (ctx *Context) ResponseWriter() http.ResponseWriter

func (*Context) ServeBody

func (ctx *Context) ServeBody(content []byte)

func (*Context) ServeByTemplate

func (ctx *Context) ServeByTemplate(templ *template.Template, data interface{})

func (*Context) ServeFile

func (ctx *Context) ServeFile(path string)

func (*Context) ServeHtml

func (ctx *Context) ServeHtml(content []byte)

func (*Context) ServeHtmlFile

func (ctx *Context) ServeHtmlFile(path string)

func (*Context) ServeJson

func (ctx *Context) ServeJson(o interface{})

func (*Context) ServeStatic

func (ctx *Context) ServeStatic(name string, content []byte)

func (*Context) ServeStatus

func (ctx *Context) ServeStatus(code int)

func (*Context) ServeString

func (ctx *Context) ServeString(o ...interface{})

func (*Context) ServeXML

func (ctx *Context) ServeXML(content []byte)

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, val string)

func (*Context) Unauthorized

func (ctx *Context) Unauthorized()

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

type Encoder

type Encoder interface {
	Encode(v interface{}) error
}

type Encoding

type Encoding int
const (
	None Encoding = iota
	Gzip
	Deflate
)

type Fields

type Fields struct {
	// contains filtered or unexported fields
}

func (Fields) GetIntField

func (f Fields) GetIntField(name string) int

func (Fields) GetStringField

func (f Fields) GetStringField(name string) string

type HttpMethod

type HttpMethod string
const (
	NotSupported HttpMethod = "" //not http
	GET          HttpMethod = "GET"
	PUT          HttpMethod = "PUT"
	POST         HttpMethod = "POST"
	DELETE       HttpMethod = "DELETE"
	HEAD                    = "HEAD"
)

type Router

type Router interface {
	// contains filtered or unexported methods
}

type RouterType

type RouterType int
const (
	Regex RouterType = iota
	Trie
)

type RpcRequest

type RpcRequest struct {
	// contains filtered or unexported fields
}

type RpcResponse

type RpcResponse struct {
	// contains filtered or unexported fields
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func DefaultService

func DefaultService() *Service

func NewService

func NewService() *Service

func NewServiceWithRouterType

func NewServiceWithRouterType(rType RouterType) *Service

func (*Service) AddRoute

func (svc *Service) AddRoute(route *route)

func (*Service) AddRoutes

func (svc *Service) AddRoutes(route ...*route)

func (*Service) Delete

func (svc *Service) Delete(path string, action action)

func (*Service) FileServer

func (svc *Service) FileServer()

func (*Service) Get

func (svc *Service) Get(path string, action action)

func (*Service) Post

func (svc *Service) Post(path string, action action)

func (*Service) ServeHTTP

func (svc *Service) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*Service) Start

func (svc *Service) Start(port string) error

type UploadedFile

type UploadedFile struct {
	Name  string
	Type  string
	Bytes []byte
}

Jump to

Keyboard shortcuts

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