<div align=center>
<img src="https://github.com/devfeel/dotweb/blob/master/logo.png" width="200"/>
</div>
# DotWeb
Simple and easy go web micro framework
Important: Now need go1.9+ version support, and support go mod.
Document: https://www.kancloud.cn/devfeel/dotweb/346608
Guide: https://github.com/devfeel/dotweb/blob/master/docs/GUIDE.md
[![Gitter](https://badges.gitter.im/devfeel/dotweb.svg)](https://gitter.im/devfeel-dotweb/wechat)
[![GoDoc](https://godoc.org/github.com/devfeel/dotweb?status.svg)](https://godoc.org/github.com/devfeel/dotweb)
[![Go Report Card](https://goreportcard.com/badge/github.com/devfeel/dotweb)](https://goreportcard.com/report/github.com/devfeel/dotweb)
[![Go Build Card](https://travis-ci.org/devfeel/dotweb.svg?branch=master)](https://travis-ci.org/devfeel/dotweb.svg?branch=master)
<a target="_blank" href="http://shang.qq.com/wpa/qunwpa?idkey=836e11667837ad674462a4a97fb21fba487cd3dff5b2e1ca0d7ea4c2324b4574"><img border="0" src="http://pub.idqqimg.com/wpa/images/group.png" alt="Golang-Devfeel" title="Golang-Devfeel"></a>
## 1. Install
```
go get github.com/devfeel/dotweb
```
## 2. Getting Started
```go
package main
import (
"fmt"
"github.com/devfeel/dotweb"
)
func main() {
//init DotApp
app := dotweb.New()
//set log path
app.SetLogPath("/home/logs/wwwroot/")
//set route
app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
return ctx.WriteString("welcome to my first web!")
})
//begin server
fmt.Println("dotweb.StartServer begin")
err := app.StartServer(80)
fmt.Println("dotweb.StartServer error => ", err)
}
```
#### examples: https://github.com/devfeel/dotweb-example
## 3. Features
* 支持go mod
* 支持静态路由、参数路由、组路由
* 路由支持文件/目录服务,支持设置是否允许目录浏览
* HttpModule支持,支持路由之前全局级别的自定义代码能力
* 中间件支持,支持App、Group、Router级别的设置 - https://github.com/devfeel/middleware
* Feature支持,可绑定HttpServer全局启用
* 支持STRING/JSON/JSONP/HTML格式输出
* 集成Mock能力
* 集成Timeout Hook
* 全局HTTP错误处理
* 全局日志处理
* 支持Hijack与websocket
* 内建Cache支持
* 内建Session支持 - 支持主备redis自动切换
* 内建TLS支持
* 支持接入第三方模板引擎(需实现dotweb.Renderer接口)
* 模块可配置
* 自集成基础统计数据,并支持按分钟为单位的间隔时间统计数据输出
#### Config Example
* [dotweb.conf](https://github.com/devfeel/dotweb/blob/master/example/config/dotweb.conf)
* [dotweb.json](https://github.com/devfeel/dotweb/blob/master/example/config/dotweb.json)
## 4. Performance
DotWeb | 1.9.2 | 16core16G | | | | | | | | | | |
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec
40% | 39M | 15228356 | 19 | 4 | 43 | 72 | 204 | 0 | 2070 | 0.00% | 48703.47 | 7514.79 | 8656.28
40% | 42M | 15485189 | 18 | 4 | 41 | 63 | 230 | 0 | 3250 | 0.00% | 49512.99 | 7639.7 | 8800.16
40% | 44M | 15700385 | 18 | 3 | 41 | 64 | 233 | 0 | 2083 | 0.00% | 50203.32 | 7746.22 | 8922.86
| | | | | | | | | | | | |
ECHO | 1.9.2 | 16core16G | | | | | | | | | | |
cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec
38% | 35M | 15307586 | 19 | 4 | 44 | 76 | 181 | 0 | 1808 | 0.00% | 48951.22 | 6166.71 | 9034.94
36% | 35M | 15239058 | 19 | 4 | 45 | 76 | 178 | 0 | 2003 | 0.00% | 48734.26 | 6139.37 | 8994.9
37% | 37M | 15800585 | 18 | 3 | 41 | 66 | 229 | 0 | 2355 | 0.00% | 50356.09 | 6343.68 | 9294.24
| | | | | | | | | | | | |
Gin | 1.9.2 | 16core16G | | | | | | | | | | |
cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec
36% | 36M | 15109143 | 19 | 6 | 44 | 71 | 175 | 0 | 3250 | 0.00% | 48151.87 | 5877.91 | 8746.33
36% | 40M | 15255749 | 19 | 5 | 43 | 70 | 189 | 0 | 3079 | 0.00% | 48762.53 | 5952.45 | 8857.25
36% | 40M | 15385401 | 18 | 4 | 42 | 66 | 227 | 0 | 2312 | 0.00% | 49181.03 | 6003.54 | 8933.27
## 5. Router
#### 1) 常规路由
* 支持GET\POST\HEAD\OPTIONS\PUT\PATCH\DELETE 这几类请求方法
* 支持HiJack\WebSocket\ServerFile三类特殊应用
* 支持Any注册方式,默认兼容GET\POST\HEAD\OPTIONS\PUT\PATCH\DELETE方式
* 支持通过配置开启默认添加HEAD方式
* 支持注册Handler,以启用配置化
* 支持检查请求与指定路由是否匹配
```go
1、Router.GET(path string, handle HttpHandle)
2、Router.POST(path string, handle HttpHandle)
3、Router.HEAD(path string, handle HttpHandle)
4、Router.OPTIONS(path string, handle HttpHandle)
5、Router.PUT(path string, handle HttpHandle)
6、Router.PATCH(path string, handle HttpHandle)
7、Router.DELETE(path string, handle HttpHandle)
8、Router.HiJack(path string, handle HttpHandle)
9、Router.WebSocket(path string, handle HttpHandle)
10、Router.Any(path string, handle HttpHandle)
11、Router.RegisterRoute(routeMethod string, path string, handle HttpHandle)
12、Router.RegisterHandler(name string, handler HttpHandle)
13、Router.GetHandler(name string) (HttpHandle, bool)
14、Router.MatchPath(ctx Context, routePath string) bool
```
接受两个参数,一个是URI路径,另一个是 HttpHandle 类型,设定匹配到该路径时执行的方法;
#### 2) static router
静态路由语法就是没有任何参数变量,pattern是一个固定的字符串。
```go
package main
import (
"github.com/devfeel/dotweb"
)
func main() {
dotapp := dotweb.New()
dotapp.HttpServer.GET("/hello", func(ctx dotweb.Context) error{
return ctx.WriteString("hello world!")
})
dotapp.StartServer(80)
}
```
test:
curl http://127.0.0.1/hello
#### 3) parameter router
参数路由以冒号 : 后面跟一个字符串作为参数名称,可以通过 HttpContext的 GetRouterName 方法获取路由参数的值。
```go
package main
import (
"github.com/devfeel/dotweb"
)
func main() {
dotapp := dotweb.New()
dotapp.HttpServer.GET("/hello/:name", func(ctx dotweb.Context) error{
return ctx.WriteString("hello " + ctx.GetRouterName("name"))
})
dotapp.HttpServer.GET("/news/:category/:newsid", func(ctx dotweb.Context) error{
category := ctx.GetRouterName("category")
newsid := ctx.GetRouterName("newsid")
return ctx.WriteString("news info: category=" + category + " newsid=" + newsid)
})
dotapp.StartServer(80)
}
```
test:
<br>curl http://127.0.0.1/hello/devfeel
<br>curl http://127.0.0.1/hello/category1/1
#### 4) group router
```go
g := server.Group("/user")
g.GET("/", Index)
g.GET("/profile", Profile)
```
test:
<br>curl http://127.0.0.1/user
<br>curl http://127.0.0.1/user/profile
## 6. Binder
* HttpContext.Bind(interface{})
* Support data from json、xml、Form
```go
type UserInfo struct {
UserName string `form:"user"`
Sex int `form:"sex"`
}
func TestBind(ctx dotweb.HttpContext) error{
user := new(UserInfo)
if err := ctx.Bind(user); err != nil {
return ctx.WriteString("err => " + err.Error())
}else{
return ctx.WriteString("TestBind " + fmt.Sprint(user))
}
}
```
## 7. Middleware
#### Middleware
* 支持粒度:App、Group、RouterNode
* DotWeb.Use(m ...Middleware)
* Group.Use(m ...Middleware)
* RouterNode.Use(m ...Middleware)
* 启用顺序:App -> Group -> RouterNode,同级别下按Use的引入顺序执行
* 更多请参考:https://github.com/devfeel/middleware
* [JWT](https://github.com/devfeel/middleware/tree/master/jwt) - [example](https://github.com/devfeel/middleware/tree/master
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
dotweb开发框架 v1.7.9.zip (123个子文件)
dotweb.conf 2KB
dotweb.conf 2KB
router.go 24KB
dotweb.go 20KB
server.go 19KB
tree.go 19KB
context.go 17KB
redisutil.go 15KB
state.go 12KB
uuid.go 11KB
configs.go 9KB
store_redis.go 6KB
cache_runtime.go 6KB
request.go 5KB
bind_test.go 5KB
session.go 5KB
middleware.go 5KB
store_runtime_test.go 5KB
main.go 5KB
hystrix.go 5KB
cache_runtime_test.go 5KB
htmlx.go 4KB
response.go 4KB
consts.go 4KB
xlog.go 4KB
main.go 4KB
concurrenceMap.go 4KB
group.go 3KB
store_runtime.go 3KB
main.go 3KB
reflects.go 3KB
render.go 3KB
context_test.go 3KB
cache_redis.go 3KB
path.go 3KB
sessionstate.go 3KB
utils_test.go 2KB
des.go 2KB
state_test.go 2KB
logger.go 2KB
plugin.go 2KB
dotweb_sysgroup.go 2KB
mock.go 2KB
uploadfile.go 2KB
convert_test.go 2KB
configset.go 2KB
bind.go 2KB
assert.go 2KB
main.go 2KB
concurrenceMap_test.go 2KB
router_test.go 2KB
main.go 1KB
dotweb_test.go 1KB
server_test.go 1KB
session_test.go 1KB
cache.go 1KB
convert.go 1KB
main.go 1024B
uuid_test.go 1018B
config_yaml.go 1014B
plugin_test.go 968B
stringx.go 966B
counter.go 913B
gobutil.go 884B
des_test.go 868B
file_test.go 815B
hijack.go 813B
jsonutil_test.go 776B
config_xml.go 687B
reflects_test.go 603B
hideReaddirFS.go 596B
cryptos.go 586B
jsonutil.go 585B
config_json.go 580B
configs_test.go 580B
websocket.go 553B
module.go 548B
cache_test.go 528B
base64util.go 433B
stringx_test.go 431B
util.go 414B
uploadfile_test.go 408B
cryptos_test.go 402B
base64util_test.go 396B
file.go 383B
exception.go 383B
redisutil_test.go 292B
errors.go 254B
exception_test.go 238B
validator.go 140B
sysx.go 125B
defaults.go 114B
gobutil_test.go 84B
store_redis_test.go 16B
sessionstate_test.go 16B
websocket_test.go 15B
tree_test.go 15B
hijack_test.go 15B
response_test.go 15B
render_test.go 15B
共 123 条
- 1
- 2
资源评论
芝麻粒儿
- 粉丝: 6w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功