go语言web框架挺多的,所谓琳琅满目,里面也有不少优秀的,好比echo、beego等,但体验下来,老是以为哪里有点小疙瘩,后来才明白过来,echo太简单,不少平常使用的基础模块不具有,须要额外实现,而beego又是太完善,虽然可定制化,但须要熟悉的过程,因而,二话不说,准备了一款"中间态"go-web框架 - dotweb,听说,在几个go比较活跃的群里仍是很"非著名"的:)git
也但愿更多的人能了解到dotweb,可以提出一些建议和思路,感激涕零!github
二话不说,github地址:https://github.com/devfeel/dotwebweb
下面贴一下用dotweb搭建一个简易的应用服务的代码片断,很是的简单,看一下代码注释也很容易理解。session
1 import "github.com/devfeel/dotweb" 2 3 func main() { 4 //init DotApp 5 app := dotweb.New() 6 //set route 7 app.HttpServer.Router().GET("/index", func(ctx dotweb.Context) error{ 8 return ctx.WriteString("welcome to my dot web!") 10 }) 11 //begin server 12 fmt.Println(app.StartServer(80)) 13 }
以上是一个很是简单的Web服务,下面来看一个稍微复杂点的:app
func main() { //初始化DotServer app := dotweb.New() //设置dotserver日志目录 //若是不设置,默认不启用,且默认为当前目录 app.SetEnabledLog(true) //开启development模式 app.SetDevelopmentMode() //设置gzip开关 app.HttpServer.SetEnabledGzip(true) //设置Session开关 app.HttpServer.SetEnabledSession(true) //设置Session配置 app.HttpServer.SetSessionConfig(session.NewDefaultRuntimeConfig()) //设置路由 InitRoute(app.HttpServer) //自定义404输出 app.SetNotFoundHandle(func(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusNotFound) w.Write([]byte("is't app's not found!")) }) // 开始服务 port := 8080 fmt.Println("dotweb.StartServer => " + strconv.Itoa(port)) err := app.StartServer(port) fmt.Println("dotweb.StartServer error => ", err) } func Hello(ctx dotweb.Context) error { ctx.WriteString("hello world!") return nil } func InitRoute(server *dotweb.HttpServer) { server.Router().GET("/hello", Hello) }
这样让你们有一个基本的印象。框架
这里只是快速上手的一些方法,做为一个web服务框架,功能仍是会比较多的,后续陆续整理,提供给你们。spa
另外,欢迎各位加入咱们的go语言QQ群:193409346日志