Creating a facade in Go?

xuanbao · · 452 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m somewhat of a newbie to Go. I&#39;ve been using Go for probably around 6 months now as a hobby. One of my current projects is a &#39;facade&#39; for the API of a game that I play.</p> <p>I&#39;ve been wondering if there are already any well-known or accepted patterns for facades in Go? A quick google search didn&#39;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&#39;ve heard that using middleware is a nice way to do this, although I don&#39;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 &#34;pattern&#34; 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&#39;t subscribe to the Gang of Four that much, you&#39;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&#39;s RESTful API.</p> <p>I am from an OO background, so I&#39;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

452 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传