Code Monkey home page Code Monkey logo

routingtree's Introduction

🌳路由树

  • v1:极简路由树设计
  • v2:支持 * 匹配路由
  • v3:支持复杂匹配
  • v4: 优化

v1:极简路由树设计

  • 不考虑路径参数问题:例如/user/:id 等,只支持静态路由
  • 不考虑 http method: 例如暂时区分 GET /user 还是 POST /user
  • 不考虑性能问题:这是为了排除干扰,减少代码的复杂度
  • 不支持路由冲突

v2:支持 * 匹配路由

  • 匹配原则
  • 校验 *

匹配原则

  1. 用户注册了一个路由 /order/*
  2. 用户又注册了一个路由 /order/order_sn

请求 /order/order_sn 该命中哪一个?

答案:我们遵循最“详细”原则

按照一般的说法,应该是最左最长匹配,所以应该命中 /order/order_sn,而不是 /order/*

校验 *

如果存在,必须在最后一个,并且它前面必须是/

即我们只接受 /* 的存在,abc*这种是非法

v3:支持复杂匹配

  • 支持路径参数 /order/:id
  • 根据节点类型的优先级,对应不同的匹配方法

v4: 优化

  • 将 children 进一步抽象,快速定位可能匹配的子节点
  • 扩展接口,允许用户无侵入式扩展自己的路由规则

routingtree's People

Contributors

mingsonzheng avatar

Watchers

 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.