devfeel / dotweb Goto Github PK
View Code? Open in Web Editor NEWSimple and easy go web micro framework
License: MIT License
Simple and easy go web micro framework
License: MIT License
我说,tls,能不能实现,直接用,certFile, 和,keyFile ,的,内容,不用通过读路径,获取,文件内容
GET方式请求,根据传参执行bind方法,字段tag目前只支持form,可以考虑兼容json标签
env:windows 10
code one:fmt.Println(" ctx.RemoteIP():", ctx.RemoteIP())
result two: ctx.RemoteIP(): [
code two:fmt.Println("ctx.Request().RemoteAddr :",ctx.Request().RemoteAddr)
result two:ctx.Request().RemoteAddr : [::1]:59521
I thought for a long time, but I can't think why
《以下是文言文》
在下, 日思夜寐,终不得果,望君解惑
增加MethodNotAllowed自定义处理能力
app.HttpServer.SetSessionConfig(session.NewDefaultRedisConfig("redis url"))
当redis有连接密码时,这里加个可选参数:redis连接密码,以支持带密码的redis连接。
建议新增服务端301跳转
建议程序自动添加设置的Log文件夹,不要需手动去创建log文件夹
func InitAuthN(app dotweb.DotWeb) {
au := NewAuthN()
au.Exclude("/")
au.Exclude("/index")
au.Exclude("/list")
au.Exclude("/login")
au.Exclude("/logout")
au.Exclude("/view/")
au.Exclude("/v1/machines/queryall")
au.Exclude("/v1/machines/queryIP/:IP")
app.Use(au)
}
type AuthN struct {
dotweb.BaseMiddlware
}
func (a *AuthN) Handle(ctx dotweb.Context) error {
golog.Info("authN middleware handle...")
golog.Info("URI is ", ctx.Request().RequestURI)
//check authN cookie
golog.Info("authN middleware handle want auth...")
cookie, _ := ctx.ReadCookie("skymachid")
golog.Info("cookie is ", cookie)
if cookie == nil {
golog.Error("cookie not present!")
return ctx.Redirect(http.StatusFound, "/login")
}
if (cookie.Expires.Unix() - time.Now().Unix()) >= 0 {
golog.Error("cookie out of date!")
delete(cookies, cookie.Value)
return ctx.Redirect(http.StatusFound, "/login")
}
user := cookies[cookie.Value]
golog.Info("user is ", user)
a.Next(ctx)
golog.Info("authN middleware handle auth pass...")
return nil
}
func NewAuthN() *AuthN {
return &AuthN{}
}
以上Exclude代码不生效,有的好用有的不好用,我这里马上要发车了,求大佬速速搞定,感激涕零,跪谢不已……
➜ src git:(master) ✗ wrk -c100 -t100 -d10s http://localhost:8081/dotweb
Running 10s test @ http://localhost:8081/dotweb
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 3.46ms 2.85ms 52.47ms 72.87%
Req/Sec 314.86 68.44 820.00 73.04%
315407 requests in 10.11s, 43.62MB read
Requests/sec: 31211.64
Transfer/sec: 4.32MB
➜ src git:(master) ✗ wrk -c100 -t100 -d10s http://localhost:8080/beego
Running 10s test @ http://localhost:8080/beego
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.18ms 6.09ms 90.41ms 89.80%
Req/Sec 261.17 90.74 3.06k 80.98%
261108 requests in 10.10s, 38.85MB read
Requests/sec: 25862.00
Transfer/sec: 3.85MB
dotweb code:
package main
import (
"fmt"
"github.com/devfeel/dotweb"
)
func main() {
//初始化DotServer
app := dotweb.New()
//开启debug模式
app.SetDevelopmentMode()
//设置路由
InitRoute(app.HttpServer)
//开始服务
port := 8081
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)
server.Router().GET("/hello", Hello)
server.Router().GET("/dotweb", Hello)
}
beego code:
package main
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (c *MainController) Get() {
c.Ctx.WriteString("Hello World!")
}
func main() {
beego.Router("/", &MainController{})
beego.Router("/beego", &MainController{})
beego.Run()
}
在使用过程中发现bind 方法不支持url传参,希望能完善补充
这里的示例地址还是旧版
详细示例 - https://github.com/devfeel/dotweb-example
新版的示例要到这里看
https://github.com/devfeel/dotweb/tree/master/example
解析指定路径文件并返回,可参考Echo的实现
解析指定路径文件并返回(绑定文件名),可参考Echo的实现
Lines 19 to 31 in 129df76
可以使用 Golang 自带的 func filepath.Ext(name string) string
代替框架中的获取文件扩展名方法 func GetFileExt(fileName string) string
目前框架的redis工具,将redisgo的连接池功能进行封装,但是没有实现同一个address对于不同db开启不同的连接池,导致同一个address的连接默认指向0库
辛苦.
状态数据,当url较多时,导致内存占用过大,增加启用开关控制,默认关闭DetailRequestUrlData数据统计,通过ServerConfig.EnabledDetailRequestData配置项控制,默认为不启用。
1、app.HttpServer.ServerFile("/static/filepath", "static")能不能把星号后面的filepath去掉?因为星号就代表全部了。
2、最好能增加一个设置静态目录的方法,参数里面直接填写静态目录的路径即可(要支持相对路径),然后一个可选参数是数组形式,比如{".css","*.png"},用于指定允许的静态文件类型。
web程序经常会遇到一些经常变动的模块,每次修改go代码,编译部署太麻烦了。
希望作者能够增加这个功能,可实现插件/模块化开发。
golua这个包,测试性能不错,接近python3
github.com/yuin/gopher-lua
使用场景,一组路由不需要进行身份验证时可以通过设置一个匿名访问group,来请求数据,但此组路由前缀不一定统一
比如我对"/"下的所有路径都使用middleware的use,但是"/login"我并不想过滤,可能还有一些别的uri也不想被过滤,希望增加exuse这个方法在实现“包括但除了”这个功能。
您好,我用Module来过滤未登录的用户,如果用户未登录则返回提示需要登录信息,End()表示提前中断请求,但是它会使我的OnEndRequest失效,它会在End()时就结束了Request,但是我在OnEndRequest里的一些操作就不会执行到,请问有什么方法可以让OnEndRequest也可以执行到呢?
app上传多张图片,后台不知道怎么一次获取多个文件。
建议实现进程内共享
设置app.SetEnabledLog(true)后,未记录任何日志
自定义处理异常的时候设置返回数据的content-type 但是没有生效 一直是Content-Type: text/plain; charset=utf-8,
// 异常处理
type M map[string]interface{}
func ExceptionHandle(ctx dotweb.Context, err error) {
ctx.Response().SetContentType(dotweb.MIMEApplicationJSONCharsetUTF8)
ctx.WriteJsonC(http.StatusInternalServerError, M{"error": err.Error()})
}
app := dotweb.New()
// 处理错误响应
app.SetExceptionHandle(ExceptionHandle)
增加一个 contenct 字段 来获取上传的文件内容
想用dotweb搭建通用文件服务器,发现
app.Use(cors.DefaultMiddleware())
这一句对
app.HttpServer.ServerFile无效,有时间请领导测试一下。谢谢。
app := dotweb.New()
app.Use(cors.DefaultMiddleware())
rootPath ,_ := util.RootPath()
app.HttpServer.ServerFile("/*filepath", rootPath)
hi,
The author of the handsome,I am usering dotweb,it is beautiful,but i have some tips:
i hope have ctx.QueryInt64()、ctx.QueryInt() and so on... but now I find ctx,QueryString() only.
Happy working!
6月份开始?
https://github.com/gorilla/mux 实现了一个强大的URL router,我觉得最有用的是URL 模式匹配。
比如可以绑定这样的路径模式 "/stockusers/{stockid:[0-9]{7}}/number"。希望dotweb也能集成这样的功能。
建议添加一个不转义html标签的函数
您好,在使用dotweb时我感到路由配置有些不方便。是否可以通过配置文件来配置路由呢?可以通过不修改源代码只修改配置文件的情况下,修改url或者启用停用一个handler呢?
Bind如果客户端传入了与字段不匹配的值则会引发panic,目前的Bind函数内没有对panic的拦截,可否加上panic拦截呢?
WeixinPay needs https server,is dotweb supported?
We know some Internet service provider will hijacking dns,so we need https too.
func InitRouter(app *dotweb.DotWeb) {
app.HttpServer.GET("/login/name/:name/password/:password", user.LoginHandler).Use(NewSimpleCROS())
}
func NewSimpleCROS() dotweb.Middleware {
option := cors.NewConfig().UseDefault()
return cors.Middleware(option)
}
结果中间件未生效
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
go版本
go version go1.8.3 darwin/amd64
如下三个路由:
app.HttpServer.GET("/v1/machines/list", ListMachines)
app.HttpServer.GET("/v1/machines/:machineId", GetOneMachine)
会提示冲突,但是这种方法用的场景非常多,而且非常简洁,希望能够支持。
=-=
Linux & Mac下80端口开启需要ROOT权限,诸如下面错误。
listen tcp :80: bind: permission denied
一般部署服务器也会使用Nginx做代理。
redis://:[email protected]:6379/0已经可以具体到db,能否具体到redis中的key?这样redis的db中只需要一层key就可以,不像默认的dotweb:session:be708d8c00....这么多层,有点复杂了。
而且自定义key还有个好处,在redis的同一个db中我可以存储多个网站的session,这个db就专门用来存放不同网站的session。
我在 main 函数中设置了
app.SetEnabledLog(true)
app.SetDevelopmentMode()
但是,启动之后虽然是debug模式,用浏览器访问了 web 地址之后,却没有打出访问日志。
建议增加以cookie作为存储介质的session
目前框架的超时需要自己在handle中处理,go1.7中加入的context包可以很好的处理超时后结束任务队列,
理想中的方式
func(ctx dotweb.Context){
ctx.glob["x"]//全局容器
ctx.settimeout=超时时间/time.after/超时chan
ctx.settimeoutfunc
.....do ....
}
在今天晚上获取最新的代码后,启动dotweb时出现了undefined: BindMap错误。我查看了dotweb/framework/reflects.go文件里使用了BindMap函数,但是该函数不存在。所以是否是忘记提交了该函数?
目前Group 只能通过HttpServer创建, 但是在实际使用中,希望直接创建Group, 完成设置后, 在add到Server中, 请考虑这个需求
测试代码:
`
// FILENAME: dotweb-hello.go
// DATE: 23/10/2017
// AUTHOR: [email protected]
// Github: https://github.com/forging2012
// Description: dotweb-hello.go
package main
import (
"fmt"
"github.com/devfeel/dotweb"
)
func main() {
app := dotweb.New()
app.SetDevelopmentMode()
//app.Start()
app.HttpServer.SetEnabledGzip(true)
//InitRoute(app.HttpServer)
app.HttpServer.Router().GET("/", Hello)
port := 8080
//app.StartServer(port)
err := app.StartServer(port)
if err != nil {
fmt.Println(err)
}
}
func Hello(ctx dotweb.Context) error {
ctx.WriteString("Hello world!")
return nil
}
`
建议:将读取配置文件绝对路径方式修改为项目的相对路径。谢谢
port:=8080 这能建议修改成这样的 app.port:=8080,保持风格统一。
建议改善自定配置文件节点
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.