yao/openapi/hello.go
Max b96a400869 Add OpenAPI support and enhance configuration handling
- Integrated OpenAPI loading functionality into the engine's Load and Reload processes, allowing for better API management.
- Updated the OpenAPI configuration to set a default BaseURL and ensure it does not have a trailing slash.
- Implemented the Attach method to connect the OpenAPI server to the Gin router, facilitating API endpoint management.
- Removed the obsolete hello package to streamline the OpenAPI module.
2025-07-20 18:52:30 +08:00

35 lines
872 B
Go

package openapi
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/yaoapp/yao/share"
)
// attachHelloWorld attaches the hello world handlers to the router
func (openapi *OpenAPI) attachHelloWorld(base *gin.RouterGroup) {
// hello handlers
hello := base.Group("/helloworld")
// Health check
hello.GET("/hello", openapi.helloWorldHello)
hello.POST("/hello", openapi.helloWorldHello)
}
// helloWorldHello is the handler for the hello world endpoint
func (openapi *OpenAPI) helloWorldHello(c *gin.Context) {
serverTime := time.Now().Format(time.RFC3339)
c.JSON(http.StatusOK, gin.H{
"MESSAGE": "HELLO, WORLD",
"SERVER_TIME": serverTime,
"VERSION": share.VERSION,
"PRVERSION": share.PRVERSION,
"CUI": share.CUI,
"PRCUI": share.PRCUI,
"APP": share.App.Name,
"APP_VERSION": share.App.Version,
})
}