From 03ff358da811a572b886c776587eeb7b40826c62 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 23 Sep 2019 23:08:58 +0800 Subject: [PATCH] update ci/readme/donator --- .github/FUNDING.yml | 2 +- .travis.yml | 2 +- DONATOR.MD | 1 + README.MD | 191 -------------------------------------------- 4 files changed, 3 insertions(+), 193 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index d00a11ab0..9f2fabadd 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: https://github.com/gogf/gf/blob/master/DONATOR.MD +custom: https://github.com/gogf/gf#donators diff --git a/.travis.yml b/.travis.yml index aa25ec53a..7a891c21e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ before_script: - psql -c 'create database travis_ci_test;' -U postgres script: -- GOARCH=386 go test -v ./... || exit 1 +#- GOARCH=386 go test -v ./... || exit 1 - GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic after_success: diff --git a/DONATOR.MD b/DONATOR.MD index c087556ba..a8c3681c6 100644 --- a/DONATOR.MD +++ b/DONATOR.MD @@ -13,6 +13,7 @@ |[zfan_codes](https://gitee.com/zfan_codes)|gitee|¥10.00 |[arden](https://github.com/arden)|alipay|¥10.00 |[macnie](https://www.macnie.com)|wechat|¥100.00 +|lah|wechat|¥100.00 |x*z|wechat|¥20.00 |潘兄|wechat|¥100.00 |Fly的狐狸|wechat|¥100.00 diff --git a/README.MD b/README.MD index 6b1bd852a..d2bf6b062 100644 --- a/README.MD +++ b/README.MD @@ -38,7 +38,6 @@ golang version >= 1.10 # Quick Start -## Hello World ```go package main @@ -55,196 +54,6 @@ func main() { s.Run() } ``` -## Router & Middleware -```go -package main - -import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" -) - -func main() { - s := g.Server() - s.Group("/api.v2", func(g *ghttp.RouterGroup) { - g.Middleware(func(r *ghttp.Request) { - r.Response.Write("start") - r.Middleware.Next() - r.Response.Write("end") - }) - g.Group("/order", func(g *ghttp.RouterGroup) { - g.GET("/list", func(r *ghttp.Request) { - r.Response.Write("list") - }) - }) - g.Group("/user", func(g *ghttp.RouterGroup) { - g.GET("/info", func(r *ghttp.Request) { - r.Response.Write("info") - }) - g.POST("/edit", func(r *ghttp.Request) { - r.Response.Write("edit") - }) - }) - g.Group("/hook", func(g *ghttp.RouterGroup) { - g.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) { - r.Response.Write("hook any") - }) - g.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) { - r.Response.Write("hook name") - }) - }) - }) - s.SetPort(8199) - s.Run() -} -``` - -## Multi ports & domains -```go -package main - -import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" -) - -func Hello1(r *ghttp.Request) { - r.Response.Write("127.0.0.1: Hello1!") -} - -func Hello2(r *ghttp.Request) { - r.Response.Write("localhost: Hello2!") -} - -func main() { - s := g.Server() - s.Domain("127.0.0.1").BindHandler("/", Hello1) - s.Domain("localhost").BindHandler("/", Hello2) - s.SetPort(8100, 8200, 8300) - s.Run() -} -``` -## Template Engine -```go -package main - -import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" -) - -func main() { - s := g.Server() - s.BindHandler("/template", func(r *ghttp.Request) { - r.Response.WriteTpl("index.tpl", g.Map{ - "id": 123, - "name": "john", - }) - }) - s.SetPort(8199) - s.Run() -} -``` -## File Uploading -```go -func Upload(r *ghttp.Request) { - if f, h, e := r.FormFile("upload-file"); e == nil { - defer f.Close() - name := gfile.Basename(h.Filename) - buffer := make([]byte, h.Size) - f.Read(buffer) - gfile.PutBytes("/tmp/" + name, buffer) - r.Response.Write(name + " uploaded successly") - } else { - r.Response.Write(e.Error()) - } -} -``` - -## ORM Operations - -### 1. Retrieving instance -```go -db := g.DB() -db := g.DB("user-center") -``` -### 2. Chaining Operations - -`Where + string` -```go -// SELECT * FROM user WHERE uid>1 LIMIT 0,10 -r, err := db.Table("user").Where("uid > ?", 1).Limit(0, 10).Select() - -// SELECT uid,name FROM user WHERE uid>1 LIMIT 0,10 -r, err := db.Table("user").Fileds("uid,name").Where("uid > ?", 1).Limit(0, 10).Select() - -// SELECT * FROM user WHERE uid=1 -r, err := db.Table("user").Where("u.uid=1",).One() -r, err := db.Table("user").Where("u.uid", 1).One() -r, err := db.Table("user").Where("u.uid=?", 1).One() -// SELECT * FROM user WHERE (uid=1) AND (name='john') -r, err := db.Table("user").Where("uid", 1).Where("name", "john").One() -r, err := db.Table("user").Where("uid=?", 1).And("name=?", "john").One() -// SELECT * FROM user WHERE (uid=1) OR (name='john') -r, err := db.Table("user").Where("uid=?", 1).Or("name=?", "john").One() -``` -`Where + map` -```go -// SELECT * FROM user WHERE uid=1 AND name='john' -r, err := db.Table("user").Where(g.Map{"uid" : 1, "name" : "john"}).One() -// SELECT * FROM user WHERE uid=1 AND age>18 -r, err := db.Table("user").Where(g.Map{"uid" : 1, "age>" : 18}).One() -``` -`Where + struct/*struct` -```go -type User struct { - Id int `json:"uid"` - UserName string `gconv:"name"` -} -// SELECT * FROM user WHERE uid =1 AND name='john' -r, err := db.Table("user").Where(User{ Id : 1, UserName : "john"}).One() -// SELECT * FROM user WHERE uid =1 -r, err := db.Table("user").Where(&User{ Id : 1}).One() -``` -### 3. Update & Delete -```go -// UPDATE user SET name='john guo' WHERE name='john' -r, err := db.Table("user").Data(gdb.Map{"name" : "john guo"}).Where("name=?", "john").Update() -r, err := db.Table("user").Data("name='john guo'").Where("name=?", "john").Update() -// UPDATE user SET status=1 ORDER BY login_time asc LIMIT 10 -r, err := db.Table("user").Data("status", 1).OrderBy("login_time asc").Limit(10).Update - -// DELETE FROM user WHERE uid=10 -r, err := db.Table("user").Where("uid=?", 10).Delete() -// DELETE FROM user ORDER BY login_time asc LIMIT 10 -r, err := db.Table("user").OrderBy("login_time asc").Limit(10).Delete() -``` -### 4. Insert & Replace & Save -```go -r, err := db.Table("user").Data(g.Map{"name": "john"}).Insert() -r, err := db.Table("user").Data(g.Map{"uid": 10000, "name": "john"}).Replace() -r, err := db.Table("user").Data(g.Map{"uid": 10001, "name": "john"}).Save() -``` -### 5. Transaction -```go -if tx, err := db.Begin(); err == nil { - r, err := tx.Save("user", g.Map{ - "uid" : 1, - "name" : "john", - }) - tx.Commit() -} -``` -### 6. Error Handling -```go -func GetOrderInfo(id int) (order *Order, err error) { - err = g.DB().Table("order").Where("id", id).Struct(&order) - if err != nil && err == sql.ErrNoRows { - err = nil - } - return -} -``` [More Features...](https://goframe.org/start/index)