-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
刘洪宝
committed
Nov 23, 2018
1 parent
9e426f7
commit c9ccb02
Showing
7 changed files
with
237 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package bingo_router | ||
|
||
import ( | ||
"net/http" | ||
"github.com/json-iterator/go" | ||
) | ||
|
||
// 上下文结构体 | ||
type Context struct { | ||
Writer http.ResponseWriter // 响应 | ||
Request *http.Request // 请求 | ||
Params Params //参数 | ||
//Session Session // 保存session | ||
} | ||
|
||
// 重定向,传入路径和状态码 | ||
func (c *Context) Redirect(path string) { | ||
url := c.Request.URL.Host + path | ||
http.Redirect(c.Writer, c.Request, url, http.StatusFound) | ||
} | ||
|
||
// 输出字符串 | ||
func (c *Context) String(data string) { | ||
c.Writer.WriteHeader(http.StatusOK) | ||
c.Writer.Write([]byte(data)) | ||
} | ||
|
||
// 输出json | ||
func (c *Context) ResponseJson(data interface{}) { | ||
json := jsoniter.ConfigCompatibleWithStandardLibrary | ||
d, _ := json.Marshal(data) | ||
c.Writer.WriteHeader(http.StatusOK) | ||
c.Writer.Write([]byte(d)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package bingo_router | ||
|
||
// 控制器接口 | ||
type IController interface { | ||
Index(c *Context) // 对应 get : path方法 | ||
Create(c *Context) // 对应 get : path/create 方法 | ||
Store(c *Context) // 对应 post : path 方法 | ||
Update(c *Context) // 对应put/patch : path/:id 方法 | ||
Edit(c *Context) // 对应get : path/:id/edit | ||
Show(c *Context) // 对应 get: route/:id | ||
Destroy(c *Context) // 对应 delete: route/:id | ||
} | ||
|
||
// 默认基本控制器 | ||
type Controller struct { | ||
} | ||
|
||
func (cc *Controller) Index(c *Context) { | ||
|
||
} | ||
|
||
func (cc *Controller) Create(c *Context) { | ||
|
||
} | ||
|
||
func (cc *Controller) Store(c *Context) { | ||
|
||
} | ||
|
||
func (cc *Controller) Update(c *Context) { | ||
|
||
} | ||
|
||
func (cc *Controller) Edit(c *Context) { | ||
|
||
} | ||
func (cc *Controller) Show(c *Context) { | ||
|
||
} | ||
|
||
func (cc *Controller) Destroy(c *Context) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/silsuer/bingo-router | ||
|
||
require ( | ||
github.com/json-iterator/go v1.1.5 // indirect | ||
github.com/julienschmidt/httprouter v1.2.0 | ||
github.com/klauspost/compress v0.0.0-20180801095237-b50017755d44 | ||
github.com/klauspost/cpuid v1.2.0 | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.1 // indirect | ||
github.com/modood/table v0.0.0-20181112072225-499dc7fba710 | ||
github.com/valyala/bytebufferpool v0.0.0-20180905182247-cdfbe9377474 | ||
github.com/valyala/fasthttp v0.0.0-20171207120941-e5f51c11919d | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= | ||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= | ||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= | ||
github.com/klauspost/compress v0.0.0-20180801095237-b50017755d44/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= | ||
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= | ||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= | ||
github.com/modood/table v0.0.0-20181112072225-499dc7fba710 h1:KkTJhLbA/nYDXBQZp9aRiBLAQ6LmcyV7v57vlCuCa94= | ||
github.com/modood/table v0.0.0-20181112072225-499dc7fba710/go.mod h1:41qyXVI5QH9/ObyPj27CGCVau5v/njfc3Gjj7yzr0HQ= | ||
github.com/valyala/bytebufferpool v0.0.0-20180905182247-cdfbe9377474/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
github.com/valyala/fasthttp v0.0.0-20171207120941-e5f51c11919d/go.mod h1:+g/po7GqyG5E+1CNgquiIxJnsXEi5vwFn5weFujbO78= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters