2022-10-21 21:54:17 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-07-14 10:23:51 +00:00
|
|
|
"flag"
|
2022-10-21 21:54:17 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2024-07-26 10:47:08 +00:00
|
|
|
const IDFM_BASEURL = "https://prim.iledefrance-mobilites.fr/marketplace"
|
2023-07-14 10:23:51 +00:00
|
|
|
|
|
|
|
var IDFM_TOKEN = ""
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&IDFM_TOKEN, "token-idfm", IDFM_TOKEN, "Token to access IDFM API")
|
|
|
|
}
|
|
|
|
|
2022-10-21 21:54:17 +00:00
|
|
|
type apiMetadata struct {
|
|
|
|
Call string `json:"call"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
Version int `json:"version"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type apiResult struct {
|
|
|
|
Result interface{} `json:"result"`
|
|
|
|
Metadata apiMetadata `json:"_metadata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func APIResult(c *gin.Context, res interface{}) apiResult {
|
|
|
|
return apiResult{
|
|
|
|
Result: res,
|
|
|
|
Metadata: apiMetadata{
|
|
|
|
Call: fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.Path),
|
|
|
|
Date: time.Now(),
|
|
|
|
Version: 4,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|