up
This commit is contained in:
@@ -323,6 +323,7 @@ func HandleProy(c *gin.Context) {
|
||||
}
|
||||
if resp.StatusCode == 200 {
|
||||
// todo
|
||||
log.Println(string(bodyRes))
|
||||
}
|
||||
resbody := io.NopCloser(bytes.NewReader(bodyRes))
|
||||
// 返回 API 响应主体
|
||||
@@ -382,41 +383,27 @@ func HandleReverseProxy(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
Cost string `json:"cost"`
|
||||
UserID int `json:"userId"`
|
||||
TotalUnit int `json:"totalUnit"`
|
||||
}
|
||||
|
||||
func HandleUsage(c *gin.Context) {
|
||||
fromStr := c.Query("from")
|
||||
toStr := c.Query("to")
|
||||
|
||||
from, err := time.Parse("2006-01-02", fromStr)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "Invalid from date format"})
|
||||
return
|
||||
}
|
||||
// from, err := time.Parse("2006-01-02", fromStr)
|
||||
// if err != nil {
|
||||
// c.JSON(400, gin.H{"error": "Invalid from date format"})
|
||||
// return
|
||||
// }
|
||||
|
||||
to, err := time.Parse("2006-01-02", toStr)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "Invalid to date format"})
|
||||
return
|
||||
}
|
||||
// to, err := time.Parse("2006-01-02", toStr)
|
||||
// if err != nil {
|
||||
// c.JSON(400, gin.H{"error": "Invalid to date format"})
|
||||
// return
|
||||
// }
|
||||
|
||||
err = store.QueryUsage(from, to)
|
||||
usage, err := store.QueryUsage(fromStr, toStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Mock data for testing
|
||||
usage := Usage{
|
||||
Cost: "0.000076",
|
||||
UserID: 1,
|
||||
TotalUnit: 38,
|
||||
}
|
||||
|
||||
c.JSON(200, []Usage{usage})
|
||||
|
||||
c.JSON(200, usage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user