<p>I'm somewhat of a newbie to Go. I've been using Go for probably around 6 months now as a hobby. One of my current projects is a 'facade' for the API of a game that I play.</p>
<p>I've been wondering if there are already any well-known or accepted patterns for facades in Go? A quick google search didn't really find me much.</p>
<p>My idea is basically to define a type to represent the API, and this type has methods on it which represent the endpoints. I want to implement things such as rate limiting, and I've heard that using middleware is a nice way to do this, although I don't fully understand it yet.</p>
<p>Also, are there any topics I should read up on before attempting this? (e.g. I think the context package is going to be important but I am not sure yet).</p>
<p>Any tips are appreciated, thanks for your help.</p>
<hr/>**评论:**<br/><br/>tv64738: <pre><p>Do you mean a client library, that makes calls to a remote service? Plenty of those around, not much of a "pattern" there.</p>
<p>Rate limiting is pretty simple, <a href="https://godoc.org/golang.org/x/time/rate" rel="nofollow">https://godoc.org/golang.org/x/time/rate</a> and call Wait before you make a remote call.</p>
<p>We don't subscribe to the Gang of Four that much, you're probably better off asking about the concrete things you want, not about how to apply some Java Pattern in Go.</p></pre>RoastedB: <pre><p>Sorry if my terminology is not quite right, I believe that you are correct. My aim is basically to create a package that I can use to easily call someone else's RESTful API.</p>
<p>I am from an OO background, so I'm probably still thinking about things in more of an OO way.</p>
<p>I will do some searching for client libraries, thanks for the pointer.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传