forked from coaidev/coai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelay.go
46 lines (38 loc) · 919 Bytes
/
relay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package manager
import (
"chat/admin"
"chat/channel"
"chat/globals"
"github.com/gin-gonic/gin"
"net/http"
)
func ModelAPI(c *gin.Context) {
c.JSON(http.StatusOK, globals.V1ListModels)
}
func MarketAPI(c *gin.Context) {
c.JSON(http.StatusOK, admin.MarketInstance.GetModels())
}
func ChargeAPI(c *gin.Context) {
c.JSON(http.StatusOK, channel.ChargeInstance.ListRules())
}
func PlanAPI(c *gin.Context) {
c.JSON(http.StatusOK, channel.PlanInstance.GetPlans())
}
func sendErrorResponse(c *gin.Context, err error, types ...string) {
var errType string
if len(types) > 0 {
errType = types[0]
} else {
errType = "chatnio_api_error"
}
c.JSON(http.StatusServiceUnavailable, RelayErrorResponse{
Error: TranshipmentError{
Message: err.Error(),
Type: errType,
},
})
}
func abortWithErrorResponse(c *gin.Context, err error, types ...string) {
sendErrorResponse(c, err, types...)
c.Abort()
}