https://github.com/jimxl/gream
Gream is a Dream Web Framework written in Go(Golang)
https://github.com/jimxl/gream
dream go golang web webframework
Last synced: 5 months ago
JSON representation
Gream is a Dream Web Framework written in Go(Golang)
- Host: GitHub
- URL: https://github.com/jimxl/gream
- Owner: jimxl
- Created: 2018-11-10T13:14:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-16T16:56:50.000Z (over 7 years ago)
- Last Synced: 2023-10-20T20:46:17.857Z (over 2 years ago)
- Topics: dream, go, golang, web, webframework
- Language: Go
- Homepage:
- Size: 150 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gream
Gream is a Dream Web Framework written in Go(Golang)
## Router
```go
GET("/home/{name}", "home#index")
GET("/home_json/{name}", "home#index_json")
GET("/admin_home/{name}", "admin/home#index")
scope := Scope("scope")
{
scope.GET("/home1/{name}", "home#index")
scope.GET("/home2/{name}", "home#index")
}
scope = Scope(H{"module": "admin"})
{
scope.GET("/home1/{name}", "home#index")
scope.GET("/home2/{name}", "home#index")
}
GET("/home_path/{name}", "home#index", H{"path": "ttt"})
GET("/home_module/{name}", "home#index", H{"module": "admin"})
namespace := Namespace("admin")
{
namespace.GET("/homea/{name}", "home#index")
namespace.GET("/homeb/{name}", "home#index")
}
//Resources("users", H{"except": "index"})
Resources("users", H{"only": "index,new"})
```
## Controller and Action
```go
package controllers
import (
"fmt"
. "github.com/jimxl/gream/web"
)
func init() {
Controller("home")
BeforeAll(allFilter)
BeforeAction("index", indexFilter)
Action("index", func(ctx Context) {
ctx.Writef("hello, %s", ctx.Params().GetString("name"))
})
}
func indexFilter(ctx Context) bool {
fmt.Printf("index filter, controller %s, action: %s\n", ctx.Values().Get("controller"), ctx.Values().Get("action"))
return true
}
func allFilter(ctx Context) bool {
fmt.Printf("all filter, controller %s, action: %s\n", ctx.Values().Get("controller"), ctx.Values().Get("action"))
return true
}
```