idfm-api/api/api.go

31 lines
546 B
Go

package api
import (
"fmt"
"time"
"github.com/gin-gonic/gin"
)
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,
},
}
}