Skip to content

Commit 69ef879

Browse files
author
pzrr@qq.com
committed
Version 0.3.9
* 增强静态文件处理,增加设置目录浏览开关,通过Router.ServerFile使用 * Router增加Any路由方式,如果设置为Any,则自动匹配:GET\HEAD\POST\PUT\PATCH\OPTIONS\DELETE * ServerConfig增加EnabledListDir选项,仅对Router.ServerFile有效,若设置该项,则可以浏览目录文件,默认不开启 * ServerConfig增加EnabledAutoHEAD选项,如果设置该选项,则会为除Websocket\HEAD外所有路由方式默认添加HEAD路由,默认不开启 * 优化部分代码,增加example\static、example\router * 2017-03-26 19:30
1 parent 59ceaf3 commit 69ef879

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

example/router/main.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/devfeel/dotweb"
6+
"github.com/devfeel/dotweb/framework/file"
7+
"strconv"
8+
)
9+
10+
func main() {
11+
//初始化DotServer
12+
app := dotweb.New()
13+
14+
//设置dotserver日志目录
15+
app.SetLogPath(file.GetCurrentDirectory())
16+
17+
//设置Debug开关
18+
app.SetEnabledDebug(true)
19+
20+
app.HttpServer.SetEnabledAutoHEAD(true)
21+
22+
//设置路由
23+
InitRoute(app.HttpServer)
24+
25+
//启动 监控服务
26+
//pprofport := 8081
27+
//go app.StartPProfServer(pprofport)
28+
29+
// 开始服务
30+
port := 8080
31+
fmt.Println("dotweb.StartServer => " + strconv.Itoa(port))
32+
err := app.StartServer(port)
33+
fmt.Println("dotweb.StartServer error => ", err)
34+
}
35+
36+
func Index(ctx *dotweb.HttpContext) {
37+
ctx.Response.Header().Set("Content-Type", "text/html; charset=utf-8")
38+
ctx.WriteString("index - " + ctx.Request.Method)
39+
}
40+
41+
func Any(ctx *dotweb.HttpContext) {
42+
ctx.Response.Header().Set("Content-Type", "text/html; charset=utf-8")
43+
ctx.WriteString("any - " + ctx.Request.Method)
44+
}
45+
46+
func InitRoute(server *dotweb.HttpServer) {
47+
server.Router().GET("/", Index)
48+
server.Router().Any("/any", Any)
49+
}

0 commit comments

Comments
 (0)