dotweb属于一个Web框架,但愿经过框架行为,帮助开发人员快速构建Web应用,提高开发效率,减小没必要要的代码臃肿。git
框架地址:https://github.com/devfeel/dotwebgithub
dotweb包含如下几个经常使用对象:web
本章主要对HttpServer对象展开介绍。服务器
HttpServer对象,在框架中,主要承担用于真正处理Web请求的服务模块,好比处理Web监听、设置路由、设置Module、管理Session、设置Render、设置Binder等,同时也承担一系列特性设置。session
主要属性:app
属性 | 描述 | 默认值 |
Router |
当前HttpServer路由,经过Router()访问 | NewRouter(server) |
Modules |
全局HttpModule,用于路由前的集中处理 | make([]*HttpModule, 0) |
DotApp |
所属的App容器指针 | - |
SessionManager |
当前HttpServer的Session管理单元 | InitSessionManager() |
Binder |
请求参数绑定器 | newBinder() |
Features |
当前HttpServer特性集合 | Feature{} |
主要方法:框架
方法 | 描述 |
ListenAndServe()\ListenAndServeTLS() |
指定host:port,根据配置启动Web端口监听 |
ServeHTTP(w http.ResponseWriter, req *http.Request) |
http请求处理入口 |
InitSessionManager() |
初始化Session单元 |
Router()\GET()\POST()....WebSocket() |
路由访问入口及快捷操做入口 |
Binder() |
提供HttpServer对象绑定器入口 |
Renderer() |
提供HttpServer对象模板处理入口 |
SetEnabledAutoHEAD() |
设置是否自动支持Head(默认为false) |
SetEnabledListDir() |
设置是否容许目录浏览(默认为false) |
SetEnabledSession() |
设置是否容许启用Session(默认为false) |
SetEnabledGzip() |
设置是否容许启用GZip压缩(默认为false) |
SetEnabledIgnoreFavicon() |
设置是否忽略Favicon请求(默认为false) |
SetEnabledTLS() |
设置是否支持TLS(默认为false) |
SetEnabledDetailRequestData() |
设置是否启用详细请求数据统计(默认为false) |
RegisterModule() |
添加处理模块 |
常规使用代码:分布式
func main() { //初始化DotServer app := dotweb.New() //设置gzip开关 app.HttpServer.SetEnabledGzip(true) //设置Session开关 app.HttpServer.SetEnabledSession(true) //设置Session配置 //runtime mode app.HttpServer.SetSessionConfig(session.NewDefaultRuntimeConfig()) //设置启用详细请求数据统计 app.HttpServer.SetEnabledDetailRequestData(true) //设置启用GZIP压缩,默认压缩级别 app.HttpServer.SetEnabledGzip(true) //设置启用自动忽略Favicon请求 app.HttpServer.SetEnabledIgnoreFavicon(true) //设置启用目录浏览 app.HttpServer.SetEnabledListDir(true) //设置路由 InitRoute(app.HttpServer) // 开始服务 port := 8080 fmt.Println("dotweb.StartServer => " + strconv.Itoa(port)) err := app.StartServer(port) fmt.Println("dotweb.StartServer error => ", err) }
如代码所示,经过在启动Server正式监听前设置一系列参数,能够启用所支持的特性。spa
更多代码可参考 https://github.com/devfeel/dotweb-example指针
欢迎各位加入咱们的go语言QQ群:193409346