Giter Club home page Giter Club logo

grl's Introduction

grl

模仿gin的web框架

实现功能

上下文

封装Request和Response,提供对JSON、HTML等返回类型的支持。

路由

使用Trie树实现动态路由的解析,能够解析的动态路由仅限/url/:name/url/*path

路由分组控制

大部分情况下的路由分组,是以相同的前缀来区分的。因此,实现的分组控制也是以前缀来区分,并且支持分组的嵌套。例如/post是一个分组,/post/a和/post/b可以是该分组下的子分组。作用在/post分组上的中间件(middleware),也都会作用在子分组,子分组还可以应用自己特有的中间件。

中间件

中间件(middlewares),简单说,就是非业务的技术类组件。Web 框架本身不可能去理解所有的业务,因而不可能实现所有的功能。因此,框架需要有一个插口,允许用户自己定义功能,嵌入到框架中,仿佛这个功能是框架原生支持的一样。

中间件可以在handler的前后进行处理,可以对context进行二次加工,然后再让handler处理,或者等待handler处理完后,再做一些额外的操作。

日志、授权等等功能都能作为中间件嵌入到web应用中。

模板

  • 实现静态资源服务
  • 支持HTML模板渲染

错误

实现非常简单,使用 defer 挂载上错误恢复的函数,在这个函数中调用 recover()*,捕获 panic,并且将堆栈信息打印在日志中,向用户返回 *Internal Server Error。 有一个 trace() 函数,这个函数是用来获取触发 panic 的堆栈信息

tips

Shout out to my best friend GRL

原文地址:https://geektutu.com/post/gee.html

grl's People

Contributors

lnback avatar

Watchers

James Cloos avatar  avatar

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.