cat

package module
v0.0.0-...-0c7bb58 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

CAT

service webframework

use

go get github.com/pi-pi-miao/cat

How to use

first
package main

import (
    "time"

	"github.com/pi-pi-miao/cat"
)

func main(){
    cats := cat.NewCats() 
    cats.Get("/",do)
    cats.Post("/",do)
    cats.Delete("/",do)
    cats.Patch("/",do)
    cats.Put("/",do)
    go cats.Run(":8080")
    time.Sleep(5*time.Second)
    cats.ShutDown()   //server closed gracefully
}

func do(r *cat.Request,w cat.Response){
	w.Result("200","hello world")
}
second
package main

import (
	"github.com/pi-pi-miao/cat"
)

func main(){
         cats := cat.NewCats()
	 g1 := cats.Group("/")
	 g1.Get("/v1", Do)
	 g1.Post("/v1", Do)
	 g1.Delete("/v1", Do)
	 g1.Patch("/v1", Do)
	 g1.Put("/v1", Do)
	 cat2 := cats.Group("/app")
	 cat2.Get("/v2",Do)
	 cats.Run(":8080")
}

func do(r *cat.Request,w cat.Response){
	w.Result("200","hello world")
}

注意此项目后续会不断维护,如果使用中有什么问题欢迎主动联系Email: pyrene@yeah.net

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cats

type Cats struct {
	*GroupRoute
	GroupMap     map[string]Fn
	Middleware   map[string][]middleFn
	MaxGoroutine int
	// contains filtered or unexported fields
}

func NewCats

func NewCats() *Cats

func (*Cats) Group

func (c *Cats) Group(route string) *GroupRoute

func (*Cats) Metric

func (c *Cats) Metric()

func (*Cats) Miao

func (c *Cats) Miao(r *Request, w Response)

func (*Cats) NotMethod

func (c *Cats) NotMethod(w Response)

func (*Cats) Run

func (c *Cats) Run(addr string) error

func (*Cats) ShutDown

func (c *Cats) ShutDown()

type Fn

type Fn func(*Request, Response)

type GroupRoute

type GroupRoute struct {
	*Cats
	F          Fn
	GroupRoute *strings.Builder
}

func (*GroupRoute) Delete

func (c *GroupRoute) Delete(route string, f Fn) *GroupRoute

func (*GroupRoute) Get

func (c *GroupRoute) Get(route string, f Fn) *GroupRoute

func (*GroupRoute) Patch

func (c *GroupRoute) Patch(route string, f Fn) *GroupRoute

func (*GroupRoute) Post

func (c *GroupRoute) Post(route string, f Fn) *GroupRoute

func (*GroupRoute) Put

func (c *GroupRoute) Put(route string, f Fn) *GroupRoute

type Handlers

type Handlers interface {
	Miao(request *Request, response Response)
}

type Request

type Request struct {
	Method string
	Header map[string][]string
	Body   interface{}
	Uri    string

	AllHeader string
	// contains filtered or unexported fields
}

func NewRequst

func NewRequst() *Request

func (*Request) GetCookie

func (r *Request) GetCookie() ([]string, error)

func (*Request) GetHost

func (r *Request) GetHost() ([]string, error)

func (*Request) GetMethod

func (r *Request) GetMethod() string

func (*Request) GetUserAgent

func (r *Request) GetUserAgent() ([]string, error)

func (*Request) SetUserAgent

func (r *Request) SetUserAgent(v []string)

type Response

type Response struct {
	Header map[string][]string
	Body   interface{}
	Uri    string
	// contains filtered or unexported fields
}

func NewResonse

func NewResonse() Response

func (*Response) Result

func (w *Response) Result(status string, v interface{})

func (*Response) SetCookie

func (w *Response) SetCookie(v []string)

func (Response) Write

func (w Response) Write(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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