mirror of
https://github.com/pikami/cosmium.git
synced 2025-02-19 02:37:33 +00:00
Shared library stability improvements
This commit is contained in:
parent
5d99b653cc
commit
1cf5ae92f4
@ -3,6 +3,7 @@ package main
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||||
)
|
)
|
||||||
@ -20,7 +21,7 @@ func CreateCollection(serverName *C.char, databaseId *C.char, collectionJson *C.
|
|||||||
}
|
}
|
||||||
|
|
||||||
var collection repositorymodels.Collection
|
var collection repositorymodels.Collection
|
||||||
err := json.Unmarshal([]byte(collectionStr), &collection)
|
err := json.NewDecoder(strings.NewReader(collectionStr)).Decode(&collection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResponseFailedToParseRequest
|
return ResponseFailedToParseRequest
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||||
)
|
)
|
||||||
@ -19,7 +20,7 @@ func CreateDatabase(serverName *C.char, databaseJson *C.char) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var database repositorymodels.Database
|
var database repositorymodels.Database
|
||||||
err := json.Unmarshal([]byte(databaseStr), &database)
|
err := json.NewDecoder(strings.NewReader(databaseStr)).Decode(&database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResponseFailedToParseRequest
|
return ResponseFailedToParseRequest
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||||
)
|
)
|
||||||
@ -21,7 +22,7 @@ func CreateDocument(serverName *C.char, databaseId *C.char, collectionId *C.char
|
|||||||
}
|
}
|
||||||
|
|
||||||
var document repositorymodels.Document
|
var document repositorymodels.Document
|
||||||
err := json.Unmarshal([]byte(documentStr), &document)
|
err := json.NewDecoder(strings.NewReader(documentStr)).Decode(&document)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResponseFailedToParseRequest
|
return ResponseFailedToParseRequest
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,10 @@ type ServerInstance struct {
|
|||||||
repository *repositories.DataRepository
|
repository *repositories.DataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverInstances map[string]*ServerInstance
|
var (
|
||||||
var mutex sync.Mutex
|
serverInstances = make(map[string]*ServerInstance)
|
||||||
|
mutex = sync.Mutex{}
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ResponseSuccess = 0
|
ResponseSuccess = 0
|
||||||
@ -36,10 +38,6 @@ func getInstance(serverName string) (*ServerInstance, bool) {
|
|||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|
||||||
if serverInstances == nil {
|
|
||||||
serverInstances = make(map[string]*ServerInstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
var serverInstance *ServerInstance
|
var serverInstance *ServerInstance
|
||||||
if serverInstance, ok = serverInstances[serverName]; !ok {
|
if serverInstance, ok = serverInstances[serverName]; !ok {
|
||||||
@ -53,10 +51,6 @@ func addInstance(serverName string, serverInstance *ServerInstance) {
|
|||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|
||||||
if serverInstances == nil {
|
|
||||||
serverInstances = make(map[string]*ServerInstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
serverInstances[serverName] = serverInstance
|
serverInstances[serverName] = serverInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +58,6 @@ func removeInstance(serverName string) {
|
|||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|
||||||
if serverInstances == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(serverInstances, serverName)
|
delete(serverInstances, serverName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ package main
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/pikami/cosmium/api"
|
"github.com/pikami/cosmium/api"
|
||||||
@ -15,21 +16,21 @@ import (
|
|||||||
|
|
||||||
//export CreateServerInstance
|
//export CreateServerInstance
|
||||||
func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
|
func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
|
||||||
configStr := C.GoString(configurationJSON)
|
|
||||||
serverNameStr := C.GoString(serverName)
|
serverNameStr := C.GoString(serverName)
|
||||||
|
configStr := C.GoString(configurationJSON)
|
||||||
|
|
||||||
if _, ok := getInstance(serverNameStr); ok {
|
if _, ok := getInstance(serverNameStr); ok {
|
||||||
return ResponseServerInstanceAlreadyExists
|
return ResponseServerInstanceAlreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
var configuration config.ServerConfig
|
var configuration config.ServerConfig
|
||||||
err := json.Unmarshal([]byte(configStr), &configuration)
|
err := json.NewDecoder(strings.NewReader(configStr)).Decode(&configuration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResponseFailedToParseConfiguration
|
return ResponseFailedToParseConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration.PopulateCalculatedFields()
|
|
||||||
configuration.ApplyDefaultsToEmptyFields()
|
configuration.ApplyDefaultsToEmptyFields()
|
||||||
|
configuration.PopulateCalculatedFields()
|
||||||
|
|
||||||
repository := repositories.NewDataRepository(repositories.RepositoryOptions{
|
repository := repositories.NewDataRepository(repositories.RepositoryOptions{
|
||||||
InitialDataFilePath: configuration.InitialDataFilePath,
|
InitialDataFilePath: configuration.InitialDataFilePath,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user