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:
RoastedB: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.
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.
