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