add simple fake api for _ping (#34)

This commit is contained in:
图南 2024-06-04 11:52:57 +08:00 committed by GitHub
parent c9e7d75fec
commit d1c19fc7ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

15
main.go
View File

@ -171,6 +171,7 @@ func AuthMiddleware(authToken string) gin.HandlerFunc {
}
func (s *ProxyService) InitRoutes(e *gin.Engine) {
e.GET("/_ping", s.pong)
authToken := s.cfg.AuthToken // replace with your dynamic value as needed
if authToken != "" {
// 鉴权
@ -185,6 +186,20 @@ func (s *ProxyService) InitRoutes(e *gin.Engine) {
}
}
type Pong struct {
Now int `json:"now"`
Status string `json:"status"`
Ns1 string `json:"ns1"`
}
func (s *ProxyService) pong(c *gin.Context) {
c.JSON(http.StatusOK, Pong{
Now: time.Now().Second(),
Status: "ok",
Ns1: "200 OK",
})
}
func (s *ProxyService) completions(c *gin.Context) {
ctx := c.Request.Context()