restful

package module
v0.0.0-...-213f798 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 9 Imported by: 0

README

go-resrful

够浪 koa 风格的路由控制

usage

go-example

package main

import (
	"os"

	"github.com/CARVIN94/hello/controller"

	"github.com/CARVIN94/go-restful"
)

 func init() {
	restful.Start(&restful.Config{
		Route: setRoute(),
		Port:  3000,
		// ReadTimeout:  time.Second * 10,
		// WriteTimeout: time.Second * 4,
	})
}

func setRoute() (route restful.Route) {
	route.Get("/111", controller.Pipe, controller.Midd)
	route.Post("/111", controller.IndexHandler)
	return route
}

func main() {
	quit := make(chan os.Signal)
	<-quit
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(ctx *Context)

JSON 解析

func Multipart

func Multipart(ctx *Context)

Multipart 解析

func Start

func Start(config *Config)

Start 启动服务

func Urlencoded

func Urlencoded(ctx *Context)

Urlencoded 解析

Types

type Config

type Config struct {
	Route
	Port         int
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Config Http服务器基础配置

type Context

type Context struct {
	Res    http.ResponseWriter
	Req    *http.Request
	Pipe   Pipe
	Finish bool // 控制中间件流程
}

Context 上下文

func (*Context) Check

func (ctx *Context) Check()

Check 检测运行时

func (*Context) ErrorHandler

func (ctx *Context) ErrorHandler()

ErrorHandler 错误处理

func (*Context) Param

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

Param 检查参数

func (*Context) ReplyJSON

func (ctx *Context) ReplyJSON(something interface{})

ReplyJSON 以 json 方式返回数据

func (*Context) SetFormData

func (ctx *Context) SetFormData(key string, value string)

SetFormData 改变 form 内参数的值

type Param

type Param struct {
	Ctx   *Context
	Key   string
	Value string
}

Param 参数

func (*Param) Array

func (p *Param) Array() (arr []string)

Array 参数输出数组类型

func (*Param) Exist

func (p *Param) Exist() *Param

Exist 参数必须存在

func (*Param) Int

func (p *Param) Int() (number int)

Int 参数输出数字类型

func (*Param) Required

func (p *Param) Required() *Param

Required 参数必须存在

func (*Param) String

func (p *Param) String() string

String 参数输出字符串类型

type Pipe

type Pipe map[string]interface{}

Pipe 传递数据

type Route

type Route struct {
	Addr       routeMap
	BeforeFunc []middleware
}

Route 定义路由

func (*Route) Before

func (r *Route) Before(args ...middleware)

Before 把事件放进 Route

func (*Route) Delete

func (r *Route) Delete(address string, args ...middleware)

Delete 把事件放进 Route

func (*Route) Gateway

func (r *Route) Gateway(address string, args ...middleware)

Gateway 把事件放进 Route

func (*Route) Get

func (r *Route) Get(address string, args ...middleware)

Get 把事件放进 Route

func (*Route) Post

func (r *Route) Post(address string, args ...middleware)

Post 把事件放进 Route

func (*Route) Put

func (r *Route) Put(address string, args ...middleware)

Put 把事件放进 Route

Jump to

Keyboard shortcuts

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