-
Notifications
You must be signed in to change notification settings - Fork 33
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
0 parents
commit 3ae0ee9
Showing
136 changed files
with
8,133 additions
and
0 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,3 @@ | ||
*.js linguist-language=GO | ||
*.css linguist-language=GO | ||
*.html linguist-language=GO |
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,25 @@ | ||
.DS_Store | ||
.buildpath | ||
.hgignore.swp | ||
.project | ||
.orig | ||
.swp | ||
.idea/ | ||
.settings/ | ||
.vscode/ | ||
vender/ | ||
log/ | ||
composer.lock | ||
gitpush.sh | ||
pkg/ | ||
bin/ | ||
cbuild | ||
*/.DS_Store | ||
config/config.toml | ||
main | ||
.vscode | ||
go.sum | ||
buildgf.bat | ||
*.exe | ||
*.exe~ | ||
*.log |
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,5 @@ | ||
module gfhello | ||
|
||
go 1.14 | ||
|
||
require github.com/gogf/gf v1.11.7 |
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 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gogf/gf" | ||
"github.com/gogf/gf/crypto/gmd5" | ||
) | ||
|
||
func main() { | ||
fmt.Println("hello world!") | ||
fmt.Println(gf.VERSION) | ||
fmt.Println(gmd5.EncryptString("123456")) | ||
} |
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,5 @@ | ||
module gfweb | ||
|
||
go 1.14 | ||
|
||
require github.com/gogf/gf v1.11.7 |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gogf/gf/frame/g" | ||
"github.com/gogf/gf/net/ghttp" | ||
) | ||
|
||
func main() { | ||
s := g.Server() | ||
s.BindHandler("/", func(r *ghttp.Request) { | ||
r.Response.Writeln("Welcome GoFrame!!!") | ||
}) | ||
s.BindHandler("/hello", func(r *ghttp.Request) { | ||
r.Response.Writeln("Hello World!") | ||
}) | ||
|
||
s.SetPort(8080) | ||
s.Run() | ||
} |
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,19 @@ | ||
[server] | ||
# 端口号 | ||
Address = ":8199" | ||
# 静态目录 | ||
ServerRoot = "public" | ||
# 入口文件 | ||
IndexFiles = ["index.html", "main.html"] | ||
# 系统访问日志 | ||
AccessLogEnabled = true | ||
# 系统异常日志panic | ||
ErrorLogEnabled = true | ||
# 系统日志目录,启动,访问,异常 | ||
LogPath = "gflogs" | ||
|
||
[logger] | ||
# 标准日志目录 | ||
path = "logs" | ||
# 日志级别 | ||
level = "all" |
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,5 @@ | ||
module gfweb2 | ||
|
||
go 1.14 | ||
|
||
require github.com/gogf/gf v1.11.7 |
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,26 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gogf/gf/frame/g" | ||
"github.com/gogf/gf/net/ghttp" | ||
"github.com/gogf/gf/os/glog" | ||
) | ||
|
||
func main() { | ||
s := g.Server() | ||
// 测试日志 | ||
s.BindHandler("/welcome", func(r *ghttp.Request) { | ||
glog.Info("你来了!") | ||
glog.Error("你异常啦!") | ||
r.Response.Write("哈喽世界!") | ||
}) | ||
// 异常处理 | ||
s.BindHandler("/panic", func(r *ghttp.Request) { | ||
glog.Panic("123") | ||
}) | ||
// post请求 | ||
s.BindHandler("POST:/hello", func(r *ghttp.Request) { | ||
r.Response.Writeln("Hello World!") | ||
}) | ||
s.Run() | ||
} |
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 @@ | ||
welcome hello |
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 @@ | ||
welcome static html |
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,5 @@ | ||
module gf_router | ||
|
||
go 1.14 | ||
|
||
require github.com/gogf/gf v1.11.7 |
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,99 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gogf/gf/container/gtype" | ||
"github.com/gogf/gf/frame/g" | ||
"github.com/gogf/gf/net/ghttp" | ||
) | ||
|
||
func main() { | ||
s := g.Server() | ||
// 常规注册 | ||
// hello方法,post调用 | ||
s.BindHandler("POST:/hello", func(r *ghttp.Request) { | ||
r.Response.Writeln("url" + r.Router.Uri) | ||
}) | ||
// 所有方法,url包含name参数 | ||
s.BindHandler("/:name", func(r *ghttp.Request) { | ||
// 获取URL name参数 | ||
r.Response.Writeln("name:" + r.GetString("name")) | ||
r.Response.Writeln("url" + r.Router.Uri) | ||
}) | ||
// 所有方法,url包含name参数 | ||
s.BindHandler("/:name/update", func(r *ghttp.Request) { | ||
r.Response.Writeln("name:" + r.GetString("name")) | ||
r.Response.Writeln("url" + r.Router.Uri) | ||
}) | ||
// 所有方法,url包含name和action参数 | ||
s.BindHandler("/:name/:action", func(r *ghttp.Request) { | ||
r.Response.Writeln("name:" + r.GetString("name")) | ||
r.Response.Writeln("action:" + r.GetString("action")) | ||
r.Response.Writeln("url" + r.Router.Uri) | ||
}) | ||
// 所有方法,url包含field属性 | ||
s.BindHandler("/user/list/{field}.html", func(r *ghttp.Request) { | ||
// 获取URL field属性 | ||
r.Response.Writeln("field:" + r.GetString("field")) | ||
r.Response.Writeln("url" + r.Router.Uri) | ||
}) | ||
|
||
// 方法注册 | ||
s.BindHandler("/total", Total) | ||
|
||
// 对象注册 | ||
c := new(Controller) | ||
s.BindObject("POST:/object", c) | ||
|
||
// 分组注册及中间件 | ||
group := s.Group("/api") | ||
group.Middleware(MiddlewareTest) | ||
group.ALL("/all", func(r *ghttp.Request) { | ||
r.Response.Writeln("all") | ||
}) | ||
group.GET("/get", func(r *ghttp.Request) { | ||
r.Response.Writeln("get") | ||
}) | ||
group.POST("/post", func(r *ghttp.Request) { | ||
r.Response.Writeln("post") | ||
}) | ||
|
||
// request and response | ||
s.BindHandler("POST:/test", func(r *ghttp.Request) { | ||
r.Response.WriteJson(g.Map{ | ||
"name": r.GetString("name"), | ||
"age": r.GetInt("age"), | ||
"sex": r.Header.Get("sex"), | ||
}) | ||
}) | ||
|
||
s.SetPort(8199) | ||
s.Run() | ||
} | ||
|
||
var ( | ||
total = gtype.NewInt() | ||
) | ||
|
||
func Total(r *ghttp.Request) { | ||
r.Response.Write("total:", total.Add(1)) | ||
} | ||
|
||
// 对象注册 | ||
type Controller struct{} | ||
|
||
func (c *Controller) Index(r *ghttp.Request) { | ||
r.Response.Write("index") | ||
} | ||
|
||
func (c *Controller) Show(r *ghttp.Request) { | ||
r.Response.Write("show") | ||
} | ||
|
||
// 中间件 | ||
func MiddlewareTest(r *ghttp.Request) { | ||
// 前置逻辑 | ||
r.Response.Writeln("###start") | ||
r.Middleware.Next() | ||
// 后置逻辑 | ||
r.Response.Writeln("###end") | ||
} |
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 @@ | ||
### 常规注册 | ||
POST http://localhost:8199/hello | ||
|
||
### | ||
GET http://localhost:8199/abc | ||
|
||
### | ||
GET http://localhost:8199/a/update | ||
|
||
### | ||
GET http://localhost:8199/a/add | ||
|
||
### | ||
GET http://localhost:8199/user/list/11.html | ||
|
||
### 方法注册 | ||
GET http://localhost:8199/total | ||
|
||
### 对象注册,默认访问index | ||
POST http://localhost:8199/object/ | ||
|
||
### 对象注册,直接访问Index | ||
POST http://localhost:8199/object/index | ||
|
||
### 对象注册,访问show方法 | ||
POST http://localhost:8199/object/show | ||
|
||
### 分组,默认访问index | ||
PUT http://localhost:8199/api/all | ||
|
||
### 对象注册,直接访问Index | ||
GET http://localhost:8199/api/get | ||
|
||
### 对象注册,访问show方法 | ||
POST http://localhost:8199/api/post | ||
|
||
### request and response | ||
POST http://localhost:8199/test | ||
sex:man | ||
|
||
name=liubang&age=18 | ||
|
||
### |
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,5 @@ | ||
module gfclient | ||
|
||
go 1.14 | ||
|
||
require github.com/gogf/gf v1.11.7 |
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gogf/gf/frame/g" | ||
"github.com/gogf/gf/net/ghttp" | ||
) | ||
|
||
func main() { | ||
s := g.Server() | ||
group := s.Group("/api") | ||
// 默认路径 | ||
group.ALL("/", func(r *ghttp.Request) { | ||
r.Response.Writeln("Welcome GoFrame!") | ||
}) | ||
// GET带参数 | ||
group.GET("/hello", func(r *ghttp.Request) { | ||
r.Response.Writeln("Hello World!") | ||
r.Response.Writeln("name:", r.GetString("name")) | ||
}) | ||
// POST KV | ||
group.POST("/test", func(r *ghttp.Request) { | ||
r.Response.Writeln("func:test") | ||
r.Response.Writeln("name:", r.GetString("name")) | ||
r.Response.Writeln("age:", r.GetInt("age")) | ||
}) | ||
// POST JSON | ||
group.POST("/test2", func(r *ghttp.Request) { | ||
r.Response.Writeln("func:test2") | ||
r.Response.Writeln("passport:", r.GetString("passport")) | ||
r.Response.Writeln("password:", r.GetString("password")) | ||
}) | ||
// POST Header | ||
group.POST("/test3", func(r *ghttp.Request) { | ||
r.Response.Writeln("func:test3") | ||
r.Response.Writeln("Cookie:", r.Header.Get("Cookie")) | ||
}) | ||
// POST Header | ||
group.POST("/test4", func(r *ghttp.Request) { | ||
r.Response.Writeln("func:test4") | ||
h := r.Header | ||
r.Response.Writeln("accept-encoding:", h.Get("accept-encoding")) | ||
r.Response.Writeln("accept-language:", h.Get("accept-language")) | ||
r.Response.Writeln("referer:", h.Get("referer")) | ||
r.Response.Writeln("cookie:", h.Get("cookie")) | ||
r.Response.Writeln(r.Cookie.Map()) | ||
}) | ||
|
||
s.SetPort(80) | ||
s.Run() | ||
} |
Oops, something went wrong.