package svr import ( "sync" "github.com/gin-gonic/gin" ) var ( engine *gin.Engine once sync.Once ) // GetEngine returns the gin.Engine singleton instance. // It will initialize the engine on first call func GetEngine() *gin.Engine { once.Do(func() { engine = gin.New() }) return engine } // Use registers global middleware func Use(middleware ...gin.HandlerFunc) { GetEngine().Use(middleware...) } // Group creates a new router group func Group(relativePath string, handlers ...gin.HandlerFunc) *gin.RouterGroup { return GetEngine().Group(relativePath, handlers...) } // GET is a shortcut for router.Handle("GET", path, handlers) func GET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return GetEngine().GET(relativePath, handlers...) } // POST is a shortcut for router.Handle("POST", path, handlers) func POST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return GetEngine().POST(relativePath, handlers...) } // PUT is a shortcut for router.Handle("PUT", path, handlers) func PUT(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return GetEngine().PUT(relativePath, handlers...) } // DELETE is a shortcut for router.Handle("DELETE", path, handlers) func DELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return GetEngine().DELETE(relativePath, handlers...) } // Run starts the server func Run(addr ...string) error { return GetEngine().Run(addr...) }