Code Monkey home page Code Monkey logo

twig's People

Contributors

it512 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

Watchers

 avatar  avatar  avatar  avatar  avatar

twig's Issues

希望实现Flask框架的一些特性

希望实现类似于 Flask 的 Blueprint 和 url_for 特性,可以考虑使用 NamedRoute 实现出来,可以选择给路由添加名称,使用 url_for 这样的功能可以直接返回对应的路由 URL 或者 handler

v0.8.9的示例用不了, 还有就是使用golint时有一堆报错

  1. v0.8.9的示例用不了
    web := twig.TODO()
    web.Config()返回的是Assembler类型,是需要在外面加twig.Config转成*Conf类型吗

  2. ide有使用golint时有76个警告,主页是这些警告:
    1)可导出函数没注释;
    2)注释不规范;
    3)英文缩写没使用全大写;

ServeHTTP内存分配优化

根据 go test -bench=.测试出的结果,注释四行将多157 allocs/op的内存分配,优化成两行独立的Merge。

// ServeHTTP 实现`http.Handler`接口
func (t *Twig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    method, path := r.Method, GetReqPath(r)
    c := t.muxes.Lookup(method, path, r)

    mc := c.(muxerCtx)
    mc.reset(w, r, t)

//  h := Merge(func(ctx Ctx) error { //闭包,处理Twig级中间件,结束后处理Pre中间件
//      handler := Merge(mc.Handler(), t.mid) // 处理Twig级中间件
//      return handler(ctx)
//  }, t.pre) // 处理Pre中间件

    h := Merge(mc.Handler(), t.mid)
    h = Merge(h, t.pre)

    if err := h(c); err != nil { // 链式调用,如果出错,交给Twig的HttpErrorHandler处理
        t.HttpErrorHandler(err, c)
    }   
    
    mc.Release()
} 

使用静态资源目录报错

我想用下面的代码加载assets目录下的资源

web := twig.TODO()
	web.AddServer(twig.NewServer(":4321"))

	web.Config().
		Static("/static/*", "/Users/xxx/go/src/xxx/assets/*").

结果报错:

Refused to apply style from 'http://localhost:4321/static/docute.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

GET http://localhost:4321/static/docute.js net::ERR_ABORTED 404 (Not Found)

Mr. Wang

Mr. Wang, why are you so NB?

几个小疑问

1, server.go第22行:
func DefaultServnat() *Servant {
函数名是不是应该叫DefaultServant?

2, const.go第134行注释:
defaultHeaderBytes = 1 << 20 // 512k
1 << 20 是1M

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.