GithubHelp home page GithubHelp logo

devfeel / dotweb Goto Github PK

View Code? Open in Web Editor NEW
1.4K 87.0 179.0 7.64 MB

Simple and easy go web micro framework

License: MIT License

Go 99.85% Shell 0.15%
httpcontext dotweb handler cache golang goweb go httpserver web webframework

dotweb's People

Contributors

abirdcfly avatar chacha923 avatar cnphpbb avatar devfeel avatar hsluoyz avatar imroc avatar testwill avatar yangbor avatar zouyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dotweb's Issues

关于Module中间件的疑问

您好,我用Module来过滤未登录的用户,如果用户未登录则返回提示需要登录信息,End()表示提前中断请求,但是它会使我的OnEndRequest失效,它会在End()时就结束了Request,但是我在OnEndRequest里的一些操作就不会执行到,请问有什么方法可以让OnEndRequest也可以执行到呢?

session存储方式为redis时能否指定key?

redis://:[email protected]:6379/0已经可以具体到db,能否具体到redis中的key?这样redis的db中只需要一层key就可以,不像默认的dotweb:session:be708d8c00....这么多层,有点复杂了。
而且自定义key还有个好处,在redis的同一个db中我可以存储多个网站的session,这个db就专门用来存放不同网站的session。

CORS设置,对ServerFile无效

想用dotweb搭建通用文件服务器,发现
app.Use(cors.DefaultMiddleware())
这一句对
app.HttpServer.ServerFile无效,有时间请领导测试一下。谢谢。

app := dotweb.New()
app.Use(cors.DefaultMiddleware())
rootPath ,_ := util.RootPath()
app.HttpServer.ServerFile("/*filepath", rootPath)

tls

我说,tls,能不能实现,直接用,certFile, 和,keyFile ,的,内容,不用通过读路径,获取,文件内容

建议给context增加文件返回方法

ctx.File(filepath) error

解析指定路径文件并返回,可参考Echo的实现

ctx.Attachment(filepath, filename) error

解析指定路径文件并返回(绑定文件名),可参考Echo的实现

老哥,能否考虑增加context支持

目前框架的超时需要自己在handle中处理,go1.7中加入的context包可以很好的处理超时后结束任务队列,
理想中的方式
func(ctx dotweb.Context){
ctx.glob["x"]//全局容器
ctx.settimeout=超时时间/time.after/超时chan
ctx.settimeoutfunc
.....do ....

}

文件上传

增加一个 contenct 字段 来获取上传的文件内容

UPDATE default http port 80 to 8080

Linux & Mac下80端口开启需要ROOT权限,诸如下面错误。
listen tcp :80: bind: permission denied
一般部署服务器也会使用Nginx做代理。

dotweb没有打出 access log

我在 main 函数中设置了

app.SetEnabledLog(true)
app.SetDevelopmentMode()

但是,启动之后虽然是debug模式,用浏览器访问了 web 地址之后,却没有打出访问日志。

关于启动时出现undefined: BindMap错误

在今天晚上获取最新的代码后,启动dotweb时出现了undefined: BindMap错误。我查看了dotweb/framework/reflects.go文件里使用了BindMap函数,但是该函数不存在。所以是否是忘记提交了该函数?

redis连接池工具

目前框架的redis工具,将redisgo的连接池功能进行封装,但是没有实现同一个address对于不同db开启不同的连接池,导致同一个address的连接默认指向0库

复杂路由 跨域中间件 未生效问题

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

建议Group可以直接创建

目前Group 只能通过HttpServer创建, 但是在实际使用中,希望直接创建Group, 完成设置后, 在add到Server中, 请考虑这个需求

关于路由解析问题

如下三个路由:
app.HttpServer.GET("/v1/machines/list", ListMachines)
app.HttpServer.GET("/v1/machines/:machineId", GetOneMachine)
会提示冲突,但是这种方法用的场景非常多,而且非常简洁,希望能够支持。

建议集成lua 模块式开发

web程序经常会遇到一些经常变动的模块,每次修改go代码,编译部署太麻烦了。
希望作者能够增加这个功能,可实现插件/模块化开发。
golua这个包,测试性能不错,接近python3
github.com/yuin/gopher-lua

能不能为静态目录专门增加一个设置路径的方法?

1、app.HttpServer.ServerFile("/static/filepath", "static")能不能把星号后面的filepath去掉?因为星号就代表全部了。
2、最好能增加一个设置静态目录的方法,参数里面直接填写静态目录的路径即可(要支持相对路径),然后一个可选参数是数组形式,比如{"
.css","*.png"},用于指定允许的静态文件类型。

Bind方法问题

在使用过程中发现bind 方法不支持url传参,希望能完善补充

【BUG】app.HttpServer.SetEnabledGzip(true)设置gzip压缩后,访问页面返回空压缩包直接下载

测试代码:

`
// 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
}
`

关于路由配置

您好,在使用dotweb时我感到路由配置有些不方便。是否可以通过配置文件来配置路由呢?可以通过不修改源代码只修改配置文件的情况下,修改url或者启用停用一个handler呢?

session问题

建议增加以cookie作为存储介质的session

i cann't get RemoteIP and RemoteAddr

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

《以下是文言文》
在下, 日思夜寐,终不得果,望君解惑

自定义处理异常的时候设置返回数据的content-type 但是没有生效

自定义处理异常的时候设置返回数据的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)

can you create some type in ctx.Query...()

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!

关于Bind的问题

Bind如果客户端传入了与字段不匹配的值则会引发panic,目前的Bind函数内没有对panic的拦截,可否加上panic拦截呢?

建议增加exuse方法用来实现exclude uri功能

比如我对"/"下的所有路径都使用middleware的use,但是"/login"我并不想过滤,可能还有一些别的uri也不想被过滤,希望增加exuse这个方法在实现“包括但除了”这个功能。

Use filepath.Ext to replace file.GetFileExt

//get filename extensions
func GetFileExt(fileName string) string {
if fileName == "" {
return ""
} else {
index := strings.LastIndex(fileName, ".")
if index < 0 {
return ""
} else {
return string(fileName[index:])
}
}
}

可以使用 Golang 自带的 func filepath.Ext(name string) string 代替框架中的获取文件扩展名方法 func GetFileExt(fileName string) string

Is dotweb supported https

WeixinPay needs https server,is dotweb supported?
We know some Internet service provider will hijacking dns,so we need https too.

Exclude不生效

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代码不生效,有的好用有的不好用,我这里马上要发车了,求大佬速速搞定,感激涕零,跪谢不已……

dotweb & beego 不完全压力测试对比

➜ 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()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.