mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-20 01:10:44 +00:00
Refactor to support multiple server instances in shared library
This commit is contained in:
35
api/api_server.go
Normal file
35
api/api_server.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pikami/cosmium/api/config"
|
||||
"github.com/pikami/cosmium/internal/repositories"
|
||||
)
|
||||
|
||||
type ApiServer struct {
|
||||
stopServer chan interface{}
|
||||
isActive bool
|
||||
router *gin.Engine
|
||||
config config.ServerConfig
|
||||
}
|
||||
|
||||
func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer {
|
||||
stopChan := make(chan interface{})
|
||||
|
||||
apiServer := &ApiServer{
|
||||
stopServer: stopChan,
|
||||
config: config,
|
||||
}
|
||||
|
||||
apiServer.CreateRouter(dataRepository)
|
||||
|
||||
return apiServer
|
||||
}
|
||||
|
||||
func (s *ApiServer) GetRouter() *gin.Engine {
|
||||
return s.router
|
||||
}
|
||||
|
||||
func (s *ApiServer) Stop() {
|
||||
s.stopServer <- true
|
||||
}
|
||||
Reference in New Issue
Block a user