README update

This commit is contained in:
John
2019-08-30 22:15:54 +08:00
parent 86f9d5c39d
commit c0bb8bef06
3 changed files with 79 additions and 79 deletions

View File

@ -1 +1,40 @@
package middleware
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()
}

103
README.MD
View File

@ -1,6 +1,4 @@
# GoFrame
<div align=center>
<img src="https://goframe.org/logo.png" width="100"/>
[![Go Doc](https://godoc.org/github.com/gogf/gf?status.svg)](https://godoc.org/github.com/gogf/gf/g#pkg-subdirectories)
[![Build Status](https://travis-ci.org/gogf/gf.svg?branch=master)](https://travis-ci.org/gogf/gf)
@ -9,16 +7,16 @@
[![Production Ready](https://img.shields.io/badge/production-ready-blue.svg)](https://github.com/gogf/gf)
[![License](https://img.shields.io/github/license/gogf/gf.svg?style=flat)](https://github.com/gogf/gf)
</div>
English | [简体中文](README_ZH.MD)
`GF(GoFrame)` is a modular, full-featured and production-ready application development framework of golang. Providing a series of core components and dozens of practical modules, such as: memcache, configure, validator, logging, array/queue/set/map containers, timer/timing tasks, file/memory lock, object pool, database ORM, etc. Supporting web server integrated with router, cookie, session, logger, template, https, hooks, rewrites and many more features.
`GF(GoFrame)` is a modular, full-featured and production-ready application development framework of golang. Providing a series of core components and dozens of practical modules, such as: memcache, configure, validator, logging, array/queue/set/map containers, timer/timing tasks, file/memory lock, object pool, database ORM, etc. Supporting web server integrated with router, cookie, session, middleware, logger, template, https, hooks, rewrites and many more features.
# Installation
```
go get -u github.com/gogf/gf
```
or use `go.mod`:
suggested using `go.mod`:
```
require github.com/gogf/gf latest
```
@ -35,7 +33,7 @@ golang version >= 1.10
# Architecture
<div align=center>
<img src="https://goframe.org/images/arch.png"/>
<img src="https://gfcdn.johng.cn/images/arch.png"/>
</div>
# Quick Start
@ -57,28 +55,7 @@ func main() {
s.Run()
}
```
## Rich Router
```go
package main
import (
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/frame/g"
)
func main() {
s := g.Server()
s.BindHandler("/{class}-{course}/:name/*act", func(r *ghttp.Request) {
r.Response.Writeln(r.Get("class"))
r.Response.Writeln(r.Get("course"))
r.Response.Writeln(r.Get("name"))
r.Response.Writeln(r.Get("act"))
})
s.SetPort(8199)
s.Run()
}
```
## Group Routers
## Router & Middleware
```go
package main
@ -87,53 +64,41 @@ import (
"github.com/gogf/gf/net/ghttp"
)
type Object struct {}
func (o *Object) Show(r *ghttp.Request) {
r.Response.Writeln("Object Show")
}
func (o *Object) Delete(r *ghttp.Request) {
r.Response.Writeln("Object REST Delete")
}
func Handler(r *ghttp.Request) {
r.Response.Writeln("Handler")
}
func HookHandler(r *ghttp.Request) {
r.Response.Writeln("Hook Handler")
}
func main() {
s := g.Server()
obj := new(Object)
group := s.Group("/api")
group.ALL ("*", HookHandler, ghttp.HOOK_BEFORE_SERVE)
group.ALL ("/handler", Handler)
group.ALL ("/obj", obj)
group.GET ("/obj/showit", obj, "Show")
group.REST("/obj/rest", obj)
s.SetPort(8199)
s.Run()
}
```
or
```go
func main() {
s := g.Server()
obj := new(Object)
s.Group("/api").Bind([]ghttp.GroupItem{
{"ALL", "*", HookHandler, ghttp.HOOK_BEFORE_SERVE},
{"ALL", "/handler", Handler},
{"ALL", "/obj", obj},
{"GET", "/obj/showit", obj, "Show"},
{"REST", "/obj/rest", obj},
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

View File

@ -1,7 +1,4 @@
# GoFrame
<div align=center>
<img src="https://goframe.org/logo.png" width="100"/>
[![Go Doc](https://godoc.org/github.com/gogf/gf?status.svg)](https://godoc.org/github.com/gogf/gf/g#pkg-subdirectories)
[![Build Status](https://travis-ci.org/gogf/gf.svg?branch=master)](https://travis-ci.org/gogf/gf)
[![Go Report](https://goreportcard.com/badge/github.com/gogf/gf?v=1)](https://goreportcard.com/report/github.com/gogf/gf)
@ -9,10 +6,10 @@
[![Production Ready](https://img.shields.io/badge/production-ready-blue.svg)](https://github.com/gogf/gf)
[![License](https://img.shields.io/github/license/gogf/gf.svg?style=flat)](https://github.com/gogf/gf)
</div>
[English](README.MD) | 简体中文
`GF(Go Frame)`是一款模块化、高性能、生产级Go应用开发框架。提供了常用的核心开发组件缓存、日志、文件、时间、队列、数组、集合、字符串、定时器、命令行、文件锁、内存锁、对象池、连接池、数据校验、数据编码、文件监控、定时任务、数据库ORM、TCP/UDP组件、进程管理/通信、
并发安全容器等等。并提供了Web服务开发的系列核心组件Router、Cookie、Session、服务注册、配置管理、模板引擎等等支持热重启、热更新、多域名、多端口、多服务、HTTPS、Rewrite等特性。
`GF(Go Frame)`是一款模块化、高性能、生产级Go应用开发框架。提供了常用的核心开发组件缓存、日志、文件、时间、队列、数组、集合、字符串、定时器、命令行、文件锁、内存锁、对象池、连接池、资源管理、数据校验、数据编码、文件监控、定时任务、数据库ORM、TCP/UDP组件、进程管理/通信、
并发安全容器等等。并提供了Web服务开发的系列核心组件Router、Cookie、Session、Middleware、服务注册、配置管理、模板引擎等等支持热重启、热更新、多域名、多端口、多服务、HTTPS、Rewrite等特性。
# 特点
@ -28,8 +25,7 @@
```html
go get -u github.com/gogf/gf
```
或者
`go.mod`:
推荐使用 `go.mod`:
```
require github.com/gogf/gf latest
```
@ -41,7 +37,7 @@ golang版本 >= 1.10
# 架构
<div align=center>
<img src="https://goframe.org/images/arch.png"/>
<img src="https://gfcdn.johng.cn/images/arch.png"/>
</div>