Simple go API that uses gin-gonic to make async requests to the TMB API.
Few things to notice:
- The
TMB_ID
andTMB_KEY
correspond to the app id and app key given by the TMB developer console. - The
GIN_MODE
variable can bedebug
orrelease
, depending on wheter you are developing or deploying to production. - The
PORT
variable is the port used by gin to run the server. This should be8080
(hardcoded in theDockerfile
). YOu can change it but make sure that it makes sense overall.
The file should be in the root directory and look like this
TMB_ID=${TMB_API_ID}
TMB_KEY=${TMB_API_KEY}
GIN_MODE=${debug|release}
PORT=${PORT}
go build -o tmb .
and then ./tmb
.
or just
go run .
docker build -t tmb .
docker run -p 8080:8080 --env-file .env tmb:latest
Then you can begin making requests to localhost:${PORT}
.
There are two options:
-
/pool
Creates a pool of async requests using requests. -
/routines
Create a goroutine for every pair and makes an individual async or sync request (using the same library requests) for each one, in their own routine.
Both take the same query params and the responses are identical.
String of comma separated integers. The format of a pair is bus_line,stop_id
.
Boolean (true
or false
). Default false
.
Defines if every request to the TMB api is made via requests.GetAsync
or requests.Get
.
GET /routines?data=D40,1554,H8,1554,27,1554 HTTP/1.1
{
"data": [
{
"time": 427,
"meta": {
"line": "D40",
"stop": "1554"
},
"elapsed": 88
},
{
"time": 10,
"meta": {
"line": "H8",
"stop": "1554"
},
"elapsed": 447
},
{
"time": 30,
"meta": {
"line": "27",
"stop": "1554"
},
"elapsed": 80
}
],
"elapsed": 447,
"message": "OK"
}
The time (data.*.time
) parameter of the response JSON is given in seconds.
The elapsed times (data.*.elapsed
and data.elapsed
) parametere of the response JSON is given in miliseconds.
- Docker
- Automatic deployment
- Tests
- CI/CD
Note: Now is being manually deployed to Google Cloud Run via the Google container registry.
Suerte en la vida, xd