Creating a facade in Go?

xuanbao · 2017-12-02 00:00:12 · 687 次点击    
这是一个分享于 2017-12-02 00:00:12 的资源,其中的信息可能已经有所发展或是发生改变。

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.

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.

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.

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).

Any tips are appreciated, thanks for your help.


评论:

tv64738:

Do you mean a client library, that makes calls to a remote service? Plenty of those around, not much of a "pattern" there.

Rate limiting is pretty simple, https://godoc.org/golang.org/x/time/rate and call Wait before you make a remote call.

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.

RoastedB:

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.

I am from an OO background, so I'm probably still thinking about things in more of an OO way.

I will do some searching for client libraries, thanks for the pointer.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

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