You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
765 B
31 lines
765 B
package controller
|
|
|
|
import (
|
|
"api2gpt-mid/service"
|
|
"github.com/gin-gonic/gin"
|
|
"strings"
|
|
)
|
|
|
|
type CreditSummary struct {
|
|
Object string `json:"object"`
|
|
TotalGranted float64 `json:"total_granted"`
|
|
TotalUsed float64 `json:"total_used"`
|
|
TotalRemaining float64 `json:"total_remaining"`
|
|
}
|
|
|
|
// 余额查询
|
|
func Balance(c *gin.Context) {
|
|
auth := c.Request.Header.Get("Authorization")
|
|
key := strings.Trim(auth, "Bearer ")
|
|
balance, err := service.QueryBlance(key)
|
|
if err != nil {
|
|
c.JSON(400, gin.H{"error": err.Error()})
|
|
}
|
|
var creditSummary CreditSummary
|
|
creditSummary.Object = "credit_grant"
|
|
creditSummary.TotalGranted = 999999
|
|
creditSummary.TotalUsed = 999999 - balance
|
|
creditSummary.TotalRemaining = balance
|
|
c.JSON(200, creditSummary)
|
|
}
|