<p>I needed a tiny/fast router for static and dynamic routes with the capability of choosing what method to allow/reject.</p>
<p>I start creating this: <a href="https://github.com/nbari/violetear" rel="nofollow">https://github.com/nbari/violetear</a> implementing a "hybrid trie" it tries to dispatch directly and only loops when a regex is declared.</p>
<p>Could some one help me to check it, benchmark it and help me improve it.</p>
<p>any feedback is appreciated</p>
<p>thanks in advance.</p>
<hr/>**评论:**<br/><br/>barsonme: <pre><p>I'm confused why you use a trie that's made of maps. Isn't that counterproductive?</p>
<p>Most tries I'm aware of use a linked-list (ish) structure where each node has a small slice of children.</p>
<p>See: <a href="https://github.com/julienschmidt/httprouter/blob/master/tree.go#L321" rel="nofollow">https://github.com/julienschmidt/httprouter/blob/master/tree.go#L321</a> or <a href="https://github.com/tchap/go-patricia/blob/master/patricia/patricia.go#L439" rel="nofollow">https://github.com/tchap/go-patricia/blob/master/patricia/patricia.go#L439</a> for an example.</p></pre>nbari: <pre><p>Hi, thank for the feedback, I used a map to be available to support dynamic routes, for example to handle something like: </p>
<pre><code>/foo/:ip
/foo/:uuid
</code></pre>
<p>On the map, :ip and :uuid are the keys and the values are the compiled regex. So to handle a request like /foo/127.0.0.1 the find path matches /foo first and then interacts over the map to see what regex in case of any matches.</p>
<p>Maybe this can be implemented not using maps, but because of this "hybrid" to handle static/dynamic I think is not posible and the benefits could be few, I haven't do any benchmark but any help on that would be appreciated.</p></pre>barsonme: <pre><p>The reason I'm bringing it up is because it seems like you're iterating over the url path one character at a time, looking up the value of that character in a map. </p>
<p>That's the exact same thing as outright using a map, except now you have additional branches.</p>
<p>Tries usually afford a smaller memory footprint plus the ability to stop searching partway through the length of the key.</p></pre>nbari: <pre><p>Hi, I am iterating per resource not per character so for a request like:</p>
<pre><code>/foo/bar/view
</code></pre>
<p>There is a structure something like map[foo][bar][view], must of the docs I found iterate one character at a time, but since this is going to be an http router I though that using the full resource as a key could be more efficient. like I said I still to do some benchmark it, any help with it be appreciated.</p></pre>nbari: <pre><p>Hi, I changed the map to use a slice and in some benchmarks I notice a that read/writes are now approximately 40% faster, haven't measure the memory consumption but I think is consuming less than with the maps. please give a look <a href="https://github.com/nbari/violetear/blob/master/trie.go#L20" rel="nofollow">https://github.com/nbari/violetear/blob/master/trie.go#L20</a></p></pre>syf81: <pre><p>Looks neat, but do you just like badges a lot of is there a point behind using 3 build tools and 3 coverage tools?</p></pre>nbari: <pre><p>Hi, unfortunately where I am working they don't use any CI & CD tools, therefore In a small talk I tried to encourage the use of them, so has an example I used some providers in order to show how they work and tried to explain the simplicity and benefits of using such tools.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传