From da1566875b4bc4814812a688a53d071800b03950 Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Mon, 3 Feb 2025 22:21:54 +0200 Subject: [PATCH] Wait for server shutdown when stopping server --- api/api_server.go | 16 ++++++++++------ api/router.go | 1 + docs/COMPATIBILITY.md | 9 +++++++++ sharedlibrary/sharedlibrary.go | 9 +++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/api/api_server.go b/api/api_server.go index a22158b..7c6a046 100644 --- a/api/api_server.go +++ b/api/api_server.go @@ -7,18 +7,21 @@ import ( ) type ApiServer struct { - stopServer chan interface{} - isActive bool - router *gin.Engine - config config.ServerConfig + stopServer chan interface{} + onServerShutdown chan interface{} + isActive bool + router *gin.Engine + config config.ServerConfig } func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer { stopChan := make(chan interface{}) + onServerShutdownChan := make(chan interface{}) apiServer := &ApiServer{ - stopServer: stopChan, - config: config, + stopServer: stopChan, + onServerShutdown: onServerShutdownChan, + config: config, } apiServer.CreateRouter(dataRepository) @@ -32,4 +35,5 @@ func (s *ApiServer) GetRouter() *gin.Engine { func (s *ApiServer) Stop() { s.stopServer <- true + <-s.onServerShutdown } diff --git a/api/router.go b/api/router.go index 3588c94..d776ded 100644 --- a/api/router.go +++ b/api/router.go @@ -102,6 +102,7 @@ func (s *ApiServer) Start() { if err != nil { logger.ErrorLn("Failed to shutdown server:", err) } + s.onServerShutdown <- true }() go func() { diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 4e12e3c..4721da6 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -204,6 +204,15 @@ Cosmium strives to support the core features of Cosmos DB, including: | IS_PRIMITIVE | Yes | | IS_STRING | Yes | +### Document Batch Requests + +| Operation | Implemented | +| --------- | ----------- | +| Create | No | +| Update | No | +| Delete | No | +| Read | No | + ## Known Differences While Cosmium aims to replicate the behavior of Cosmos DB as closely as possible, there are certain differences and limitations to be aware of: diff --git a/sharedlibrary/sharedlibrary.go b/sharedlibrary/sharedlibrary.go index 418e3ae..2791346 100644 --- a/sharedlibrary/sharedlibrary.go +++ b/sharedlibrary/sharedlibrary.go @@ -1,8 +1,12 @@ package main +/* +#include +*/ import "C" import ( "encoding/json" + "unsafe" "github.com/pikami/cosmium/api" "github.com/pikami/cosmium/api/config" @@ -87,4 +91,9 @@ func LoadServerInstanceState(serverName *C.char, stateJSON *C.char) int { return ResponseServerInstanceNotFound } +//export FreeMemory +func FreeMemory(ptr *C.char) { + C.free(unsafe.Pointer(ptr)) +} + func main() {}