1 Commits

Author SHA1 Message Date
Pijus Kamandulis
c3ba4ebedf intermediary patch 2025-08-22 18:22:27 +03:00
45 changed files with 2255 additions and 2492 deletions

View File

@@ -7,18 +7,15 @@ jobs:
build:
runs-on: ubuntu-latest
outputs:
artifact: shared-libraries
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cross-Compile with xgo
uses: crazy-max/ghaction-xgo@acf46aa99b919eb9ef6bba89dfd13bafa680667f # v3.2.0
uses: crazy-max/ghaction-xgo@e22d3c8b089adba750d5a74738b8e95d96f0c991 # v3.1.0
with:
xgo_version: latest
go_version: 1.25.1
go_version: 1.24.0
dest: dist
pkg: sharedlibrary
prefix: cosmium
@@ -32,58 +29,3 @@ jobs:
with:
name: shared-libraries
path: dist/*
test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
lib_ext: amd64.so
- os: windows-latest
lib_ext: amd64.dll
- os: macos-latest
lib_ext: arm64.dylib
steps:
- uses: actions/checkout@v3
- name: Download shared libraries
uses: actions/download-artifact@v4
with:
name: shared-libraries
path: libs
- name: Install MinGW (GCC) on Windows
if: runner.os == 'Windows'
run: choco install mingw --no-progress
- name: Build test loader (Windows)
if: runner.os == 'Windows'
run: |
mkdir build
gcc -Wall -o build/test_loader.exe sharedlibrary/tests/*.c
- name: Build test loader (Unix)
if: runner.os != 'Windows'
run: |
mkdir build
gcc -Wall -ldl -o build/test_loader sharedlibrary/tests/*.c
- name: Run test (Unix)
if: runner.os != 'Windows'
run: |
LIB=$(ls libs/*${{ matrix.lib_ext }} | head -n 1)
echo "Testing library: $LIB"
chmod +x build/test_loader
./build/test_loader "$LIB"
- name: Run test (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$lib = Get-ChildItem "libs/*${{ matrix.lib_ext }}" | Select-Object -First 1
Write-Host "Testing library: $($lib.FullName)"
.\build\test_loader.exe $lib.FullName

View File

@@ -21,13 +21,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.25.1
go-version: 1.24.0
- name: Cross-Compile with xgo
uses: crazy-max/ghaction-xgo@acf46aa99b919eb9ef6bba89dfd13bafa680667f # v3.2.0
uses: crazy-max/ghaction-xgo@e22d3c8b089adba750d5a74738b8e95d96f0c991 # v3.1.0
with:
xgo_version: latest
go_version: 1.25.1
go_version: 1.24.0
dest: sharedlibrary_dist
pkg: sharedlibrary
prefix: cosmium

View File

@@ -9,7 +9,7 @@ SERVER_LOCATION=./cmd/server
SHARED_LIB_LOCATION=./sharedlibrary
SHARED_LIB_OPT=-buildmode=c-shared
XGO_TARGETS=linux/amd64,linux/arm64,windows/amd64,windows/arm64,darwin/amd64,darwin/arm64
GOVERSION=1.25.1
GOVERSION=1.24.0
DIST_DIR=dist

View File

@@ -105,10 +105,10 @@ All mentioned arguments can also be set using environment variables:
Cosmium supports multiple storage backends for saving, loading, and managing data at runtime.
| Backend | Storage Location | Write Behavior | Memory Usage |
|----------|--------------------------|--------------------------|----------------------|
| `json` (default) | JSON file on disk 📄 | On application exit ⏳ | 🛑 More than Badger |
| `badger` | BadgerDB database on disk ⚡ | Immediately on write 🚀 | ✅ Less than JSON |
| Backend | Storage Location | Write Behavior | Memory Usage | Supports Initial JSON Load |
|----------|--------------------------|--------------------------|----------------------|----------------------------|
| `json` (default) | JSON file on disk 📄 | On application exit ⏳ | 🛑 More than Badger | ✅ Yes |
| `badger` | BadgerDB database on disk ⚡ | Immediately on write 🚀 | ✅ Less than JSON | ❌ No |
The `badger` backend is generally recommended as it uses less memory and writes data to disk immediately. However, if you need to load initial data from a JSON file, use the `json` backend.

View File

@@ -94,6 +94,11 @@ func (c *ServerConfig) PopulateCalculatedFields() {
os.Exit(1)
}
}
if c.DataStore == DataStoreBadger && c.InitialDataFilePath != "" {
logger.ErrorLn("InitialData option is currently not supported with Badger data store")
os.Exit(1)
}
}
func (c *ServerConfig) ApplyDefaultsToEmptyFields() {

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
)
@@ -17,7 +16,7 @@ func (h *Handlers) GetAllCollections(c *gin.Context) {
if status == datastore.StatusOk {
database, _ := h.dataStore.GetDatabase(databaseId)
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(collections)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(collections)))
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": database.ResourceID,
"DocumentCollections": collections,

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
)
@@ -13,7 +12,7 @@ import (
func (h *Handlers) GetAllDatabases(c *gin.Context) {
databases, status := h.dataStore.GetAllDatabases()
if status == datastore.StatusOk {
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(databases)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(databases)))
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": "",
"Databases": databases,

View File

@@ -9,7 +9,6 @@ import (
jsonpatch "github.com/cosmiumdev/json-patch/v5"
"github.com/gin-gonic/gin"
apimodels "github.com/pikami/cosmium/api/api_models"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/converters"
"github.com/pikami/cosmium/internal/datastore"
@@ -27,7 +26,7 @@ func (h *Handlers) GetAllDocuments(c *gin.Context) {
if status == datastore.StatusOk {
collection, _ := h.dataStore.GetCollection(databaseId, collectionId)
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(documents)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(documents)))
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": collection.ID,
"Documents": documents,
@@ -190,7 +189,7 @@ func (h *Handlers) DocumentsPost(c *gin.Context) {
collectionId := c.Param("collId")
// Handle batch requests
isBatchRequest, _ := strconv.ParseBool(c.GetHeader(headers.IsBatchRequest))
isBatchRequest, _ := strconv.ParseBool(c.GetHeader("x-ms-cosmos-is-batch-request"))
if isBatchRequest {
h.handleBatchRequest(c)
return
@@ -202,17 +201,8 @@ func (h *Handlers) DocumentsPost(c *gin.Context) {
return
}
// Handle query plan requests
isQueryPlanRequest, _ := strconv.ParseBool(c.GetHeader(headers.IsQueryPlanRequest))
if isQueryPlanRequest {
c.IndentedJSON(http.StatusOK, constants.QueryPlanResponse)
return
}
// Handle query requests
isQueryRequest, _ := strconv.ParseBool(c.GetHeader(headers.IsQuery))
isQueryRequestAltHeader, _ := strconv.ParseBool(c.GetHeader(headers.Query))
if isQueryRequest || isQueryRequestAltHeader {
query := requestBody["query"]
if query != nil {
h.handleDocumentQuery(c, requestBody)
return
}
@@ -222,7 +212,7 @@ func (h *Handlers) DocumentsPost(c *gin.Context) {
return
}
isUpsert, _ := strconv.ParseBool(c.GetHeader(headers.IsUpsert))
isUpsert, _ := strconv.ParseBool(c.GetHeader("x-ms-documentdb-is-upsert"))
if isUpsert {
h.dataStore.DeleteDocument(databaseId, collectionId, requestBody["id"].(string))
}
@@ -257,6 +247,11 @@ func (h *Handlers) handleDocumentQuery(c *gin.Context, requestBody map[string]in
databaseId := c.Param("databaseId")
collectionId := c.Param("collId")
if c.GetHeader("x-ms-cosmos-is-query-plan-request") != "" {
c.IndentedJSON(http.StatusOK, constants.QueryPlanResponse)
return
}
var queryParameters map[string]interface{}
if paramsArray, ok := requestBody["parameters"].([]interface{}); ok {
queryParameters = parametersToMap(paramsArray)
@@ -271,7 +266,7 @@ func (h *Handlers) handleDocumentQuery(c *gin.Context, requestBody map[string]in
}
collection, _ := h.dataStore.GetCollection(databaseId, collectionId)
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(docs)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(docs)))
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": collection.ResourceID,
"Documents": docs,

View File

@@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/config"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/authentication"
"github.com/pikami/cosmium/internal/logger"
)
@@ -23,8 +22,8 @@ func Authentication(config *config.ServerConfig) gin.HandlerFunc {
resourceType := urlToResourceType(requestUrl)
resourceId := requestToResourceId(c)
authHeader := c.Request.Header.Get(headers.Authorization)
date := c.Request.Header.Get(headers.XDate)
authHeader := c.Request.Header.Get("authorization")
date := c.Request.Header.Get("x-ms-date")
expectedSignature := authentication.GenerateSignature(
c.Request.Method, resourceType, resourceId, date, config.AccountKey)
@@ -86,7 +85,7 @@ func requestToResourceId(c *gin.Context) string {
resourceId += "/udfs/" + udfId
}
isFeed := c.Request.Header.Get(headers.AIM) == "Incremental Feed"
isFeed := c.Request.Header.Get("A-Im") == "Incremental Feed"
if resourceType == "pkranges" && isFeed {
resourceId = collId
}

View File

@@ -4,11 +4,10 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
)
func GetOffers(c *gin.Context) {
c.Header(headers.ItemCount, "0")
c.Header("x-ms-item-count", "0")
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": "",
"_count": 0,

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
"github.com/pikami/cosmium/internal/resourceid"
@@ -15,18 +14,18 @@ func (h *Handlers) GetPartitionKeyRanges(c *gin.Context) {
databaseId := c.Param("databaseId")
collectionId := c.Param("collId")
if c.Request.Header.Get(headers.IfNoneMatch) != "" {
if c.Request.Header.Get("if-none-match") != "" {
c.AbortWithStatus(http.StatusNotModified)
return
}
partitionKeyRanges, status := h.dataStore.GetPartitionKeyRanges(databaseId, collectionId)
if status == datastore.StatusOk {
c.Header(headers.ETag, "\"420\"")
c.Header(headers.LSN, "420")
c.Header(headers.CosmosLsn, "420")
c.Header(headers.GlobalCommittedLsn, "420")
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(partitionKeyRanges)))
c.Header("etag", "\"420\"")
c.Header("lsn", "420")
c.Header("x-ms-cosmos-llsn", "420")
c.Header("x-ms-global-committed-lsn", "420")
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(partitionKeyRanges)))
collectionRid := collectionId
collection, _ := h.dataStore.GetCollection(databaseId, collectionId)

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
)
@@ -17,7 +16,7 @@ func (h *Handlers) GetAllStoredProcedures(c *gin.Context) {
sps, status := h.dataStore.GetAllStoredProcedures(databaseId, collectionId)
if status == datastore.StatusOk {
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(sps)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(sps)))
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "StoredProcedures": sps, "_count": len(sps)})
return
}

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
)
@@ -17,7 +16,7 @@ func (h *Handlers) GetAllTriggers(c *gin.Context) {
triggers, status := h.dataStore.GetAllTriggers(databaseId, collectionId)
if status == datastore.StatusOk {
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(triggers)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(triggers)))
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "Triggers": triggers, "_count": len(triggers)})
return
}

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/constants"
"github.com/pikami/cosmium/internal/datastore"
)
@@ -17,7 +16,7 @@ func (h *Handlers) GetAllUserDefinedFunctions(c *gin.Context) {
udfs, status := h.dataStore.GetAllUserDefinedFunctions(databaseId, collectionId)
if status == datastore.StatusOk {
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(udfs)))
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(udfs)))
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "UserDefinedFunctions": udfs, "_count": len(udfs)})
return
}

View File

@@ -1,20 +0,0 @@
package headers
const (
AIM = "A-Im"
Authorization = "authorization"
CosmosLsn = "x-ms-cosmos-llsn"
ETag = "etag"
GlobalCommittedLsn = "x-ms-global-committed-lsn"
IfNoneMatch = "if-none-match"
IsBatchRequest = "x-ms-cosmos-is-batch-request"
IsQueryPlanRequest = "x-ms-cosmos-is-query-plan-request"
IsUpsert = "x-ms-documentdb-is-upsert"
ItemCount = "x-ms-item-count"
LSN = "lsn"
XDate = "x-ms-date"
// Kinda retarded, but what can I do ¯\_(ツ)_/¯
IsQuery = "x-ms-documentdb-isquery" // Sent from python sdk and web explorer
Query = "x-ms-documentdb-query" // Sent from Go sdk
)

View File

@@ -121,26 +121,5 @@ func Test_Collections(t *testing.T) {
panic(err)
}
})
t.Run("Should delete collection with exactly matching name", func(t *testing.T) {
ts.DataStore.CreateCollection(testDatabaseName, datastore.Collection{
ID: testCollectionName + "extra",
})
ts.DataStore.CreateCollection(testDatabaseName, datastore.Collection{
ID: testCollectionName,
})
collectionResponse, err := databaseClient.NewContainer(testCollectionName)
assert.Nil(t, err)
readResponse, err := collectionResponse.Delete(context.TODO(), &azcosmos.DeleteContainerOptions{})
assert.Nil(t, err)
assert.Equal(t, readResponse.RawResponse.StatusCode, http.StatusNoContent)
collections, status := ts.DataStore.GetAllCollections(testDatabaseName)
assert.Equal(t, status, datastore.StatusOk)
assert.Len(t, collections, 1)
assert.Equal(t, collections[0].ID, testCollectionName+"extra")
})
})
}

View File

@@ -109,26 +109,5 @@ func Test_Databases(t *testing.T) {
panic(err)
}
})
t.Run("Should delete database with exactly matching name", func(t *testing.T) {
ts.DataStore.CreateDatabase(datastore.Database{
ID: testDatabaseName + "extra",
})
ts.DataStore.CreateDatabase(datastore.Database{
ID: testDatabaseName,
})
databaseResponse, err := client.NewDatabase(testDatabaseName)
assert.Nil(t, err)
readResponse, err := databaseResponse.Delete(context.TODO(), &azcosmos.DeleteDatabaseOptions{})
assert.Nil(t, err)
assert.Equal(t, readResponse.RawResponse.StatusCode, http.StatusNoContent)
dbs, status := ts.DataStore.GetAllDatabases()
assert.Equal(t, status, datastore.StatusOk)
assert.Len(t, dbs, 1)
assert.Equal(t, dbs[0].ID, testDatabaseName+"extra")
})
})
}

View File

@@ -425,7 +425,7 @@ func Test_Documents(t *testing.T) {
assert.Equal(t, int32(http.StatusNoContent), operationResponse.StatusCode)
_, status := ts.DataStore.GetDocument(testDatabaseName, testCollectionName, "12345")
assert.Equal(t, datastore.StatusNotFound, status)
assert.Equal(t, datastore.StatusNotFound, int(status))
})
t.Run("Should execute REPLACE transactional batch", func(t *testing.T) {

View File

@@ -8,7 +8,6 @@ import (
"time"
"github.com/pikami/cosmium/api/config"
"github.com/pikami/cosmium/api/headers"
"github.com/pikami/cosmium/internal/authentication"
"github.com/stretchr/testify/assert"
)
@@ -27,8 +26,8 @@ func Test_Documents_Read_Trailing_Slash(t *testing.T) {
signature := authentication.GenerateSignature("GET", "docs", path, date, config.DefaultAccountKey)
httpClient := &http.Client{}
req, _ := http.NewRequest("GET", testUrl, nil)
req.Header.Add(headers.XDate, date)
req.Header.Add(headers.Authorization, "sig="+url.QueryEscape(signature))
req.Header.Add("x-ms-date", date)
req.Header.Add("authorization", "sig="+url.QueryEscape(signature))
res, err := httpClient.Do(req)
assert.Nil(t, err)

View File

@@ -20,7 +20,6 @@ func main() {
switch configuration.DataStore {
case config.DataStoreBadger:
dataStore = badgerdatastore.NewBadgerDataStore(badgerdatastore.BadgerDataStoreOptions{
InitialDataFilePath: configuration.InitialDataFilePath,
PersistDataFilePath: configuration.PersistDataFilePath,
})
logger.InfoLn("Using Badger data store")

51
go.mod
View File

@@ -1,42 +1,40 @@
module github.com/pikami/cosmium
go 1.25.1
go 1.24.0
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.2
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.0
github.com/cosmiumdev/json-patch/v5 v5.9.11
github.com/dgraph-io/badger/v4 v4.8.0
github.com/gin-gonic/gin v1.11.0
github.com/gin-gonic/gin v1.10.1
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.11.1
github.com/stretchr/testify v1.10.0
github.com/vmihailenco/msgpack/v5 v5.4.1
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b
)
require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.14.2 // indirect
github.com/bytedance/sonic/loader v0.4.0 // indirect
github.com/bytedance/sonic v1.14.0 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.11 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.28.0 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/google/flatbuffers v25.9.23+incompatible // indirect
github.com/google/flatbuffers v25.2.10+incompatible // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.1 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -44,21 +42,18 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.57.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.38.0 // indirect
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
go.uber.org/mock v0.6.0 // indirect
golang.org/x/arch v0.23.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
golang.org/x/arch v0.20.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

106
go.sum
View File

@@ -1,21 +1,19 @@
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 h1:JXg2dwJUmPB9JmtVmdEB16APJ7jurfbY5jnfXpJoRMc=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0/go.mod h1:YD5h/ldMsG0XiIw7PdyNhLxaM317eFh5yNLccNfGdyw=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.2 h1:Hr5FTipp7SL07o2FvoVOX9HRiRH3CR3Mj8pxqCcdD5A=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.2/go.mod h1:QyVsSSN64v5TGltphKLQ2sQxe4OBQg0J1eKRcVBnfgE=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 h1:B+blDbyVIG3WaikNxPnhPiJ1MThR03b3vKGtER95TP4=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1/go.mod h1:JdM5psgjfBf5fo2uWOZhflPWyDBZ/O/CNAH9CtsuZE4=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.1 h1:ToPLhnXvatKVN4ZkcxLOwcXOJhdu4iQl8w0efeuDz9Y=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.1/go.mod h1:Krtog/7tz27z75TwM5cIS8bxEH4dcBUezcq+kGVeZEo=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.0 h1:TSaH6Lj0m8bDr4vX1+LC1KLQTnLzZb3tOxrx/PLqw+c=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.0/go.mod h1:Krtog/7tz27z75TwM5cIS8bxEH4dcBUezcq+kGVeZEo=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 h1:9iefClla7iYpfYWdzPCRDozdmndjTm8DXdpCzPajMgA=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2/go.mod h1:XtLgD3ZD34DAaVIIAyG3objl5DynM3CQ/vMcbBNJZGI=
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 h1:oygO0locgZJe7PpYPXT5A29ZkwJaPqcva7BVeemZOZs=
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
github.com/bytedance/sonic v1.14.2 h1:k1twIoe97C1DtYUo+fZQy865IuHia4PR5RPiuGPPIIE=
github.com/bytedance/sonic v1.14.2/go.mod h1:T80iDELeHiHKSc0C9tubFygiuXoGzrkjKzX2quAx980=
github.com/bytedance/sonic/loader v0.4.0 h1:olZ7lEqcxtZygCK9EKYKADnpQoYkRQxaeY2NYzevs+o=
github.com/bytedance/sonic/loader v0.4.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
@@ -33,12 +31,12 @@ github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa5
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gabriel-vasile/mimetype v1.4.11 h1:AQvxbp830wPhHTqc1u7nzoLT+ZFxGY7emj5DR5DYFik=
github.com/gabriel-vasile/mimetype v1.4.11/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -50,16 +48,14 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/flatbuffers v25.9.23+incompatible h1:rGZKv+wOb6QPzIdkM2KxhBZCDrA0DeN6DNmRDrqIsQU=
github.com/google/flatbuffers v25.9.23+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q=
github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -67,8 +63,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -92,58 +88,48 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmd
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.57.1 h1:25KAAR9QR8KZrCZRThWMKVAwGoiHIrNbT72ULHTuI10=
github.com/quic-go/quic-go v0.57.1/go.mod h1:ly4QBAjHA2VhdnxhojRsCUOeJwKYg+taDlos92xb1+s=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg=
golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 h1:DHNhtq3sNNzrvduZZIiFyXWOL9IWaDPHqTnLJp+rCBY=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0=
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

View File

@@ -1,13 +1,9 @@
package badgerdatastore
import (
"encoding/json"
"log"
"os"
"time"
"github.com/dgraph-io/badger/v4"
"github.com/pikami/cosmium/internal/datastore"
"github.com/pikami/cosmium/internal/logger"
)
@@ -17,7 +13,6 @@ type BadgerDataStore struct {
}
type BadgerDataStoreOptions struct {
InitialDataFilePath string
PersistDataFilePath string
}
@@ -40,8 +35,6 @@ func NewBadgerDataStore(options BadgerDataStoreOptions) *BadgerDataStore {
gcTicker: gcTicker,
}
ds.initializeDataStore(options.InitialDataFilePath)
go ds.runGarbageCollector()
return ds
@@ -71,53 +64,3 @@ func (r *BadgerDataStore) runGarbageCollector() {
}
}
}
func (r *BadgerDataStore) initializeDataStore(initialDataFilePath string) {
if initialDataFilePath == "" {
return
}
stat, err := os.Stat(initialDataFilePath)
if err != nil {
panic(err)
}
if stat.IsDir() {
logger.ErrorLn("Argument '-Persist' must be a path to file, not a directory.")
os.Exit(1)
}
jsonData, err := os.ReadFile(initialDataFilePath)
if err != nil {
log.Fatalf("Error reading state JSON file: %v", err)
return
}
var state datastore.InitialDataModel
if err := json.Unmarshal([]byte(jsonData), &state); err != nil {
log.Fatalf("Error parsing state JSON file: %v", err)
return
}
for dbName, dbModel := range state.Databases {
r.CreateDatabase(dbModel)
for colName, colModel := range state.Collections[dbName] {
r.CreateCollection(dbName, colModel)
for _, docModel := range state.Documents[dbName][colName] {
r.CreateDocument(dbName, colName, docModel)
}
for _, triggerModel := range state.Triggers[dbName][colName] {
r.CreateTrigger(dbName, colName, triggerModel)
}
for _, spModel := range state.StoredProcedures[dbName][colName] {
r.CreateStoredProcedure(dbName, colName, spModel)
}
for _, udfModel := range state.UserDefinedFunctions[dbName][colName] {
r.CreateUserDefinedFunction(dbName, colName, udfModel)
}
}
}
}

View File

@@ -22,8 +22,7 @@ func (r *BadgerDataStore) GetAllCollections(databaseId string) ([]datastore.Coll
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeCollection, databaseId, "", "") + "/"
colls, status := listByPrefix[datastore.Collection](r.db, prefix)
colls, status := listByPrefix[datastore.Collection](r.db, generateKey(resourceid.ResourceTypeCollection, databaseId, "", ""))
if status == datastore.StatusOk {
return colls, datastore.StatusOk
}
@@ -50,10 +49,11 @@ func (r *BadgerDataStore) DeleteCollection(databaseId string, collectionId strin
defer txn.Discard()
prefixes := []string{
generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, "") + "/",
generateKey(resourceid.ResourceTypeTrigger, databaseId, collectionId, "") + "/",
generateKey(resourceid.ResourceTypeStoredProcedure, databaseId, collectionId, "") + "/",
generateKey(resourceid.ResourceTypeUserDefinedFunction, databaseId, collectionId, "") + "/",
generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, ""),
generateKey(resourceid.ResourceTypeTrigger, databaseId, collectionId, ""),
generateKey(resourceid.ResourceTypeStoredProcedure, databaseId, collectionId, ""),
generateKey(resourceid.ResourceTypeUserDefinedFunction, databaseId, collectionId, ""),
collectionKey,
}
for _, prefix := range prefixes {
if err := deleteKeysByPrefix(txn, prefix); err != nil {
@@ -61,8 +61,6 @@ func (r *BadgerDataStore) DeleteCollection(databaseId string, collectionId strin
}
}
deleteKey(txn, collectionKey)
err := txn.Commit()
if err != nil {
logger.ErrorLn("Error while committing transaction:", err)

View File

@@ -38,11 +38,12 @@ func (r *BadgerDataStore) DeleteDatabase(id string) datastore.DataStoreStatus {
defer txn.Discard()
prefixes := []string{
generateKey(resourceid.ResourceTypeCollection, id, "", "") + "/",
generateKey(resourceid.ResourceTypeDocument, id, "", "") + "/",
generateKey(resourceid.ResourceTypeTrigger, id, "", "") + "/",
generateKey(resourceid.ResourceTypeStoredProcedure, id, "", "") + "/",
generateKey(resourceid.ResourceTypeUserDefinedFunction, id, "", "") + "/",
generateKey(resourceid.ResourceTypeCollection, id, "", ""),
generateKey(resourceid.ResourceTypeDocument, id, "", ""),
generateKey(resourceid.ResourceTypeTrigger, id, "", ""),
generateKey(resourceid.ResourceTypeStoredProcedure, id, "", ""),
generateKey(resourceid.ResourceTypeUserDefinedFunction, id, "", ""),
databaseKey,
}
for _, prefix := range prefixes {
if err := deleteKeysByPrefix(txn, prefix); err != nil {
@@ -50,8 +51,6 @@ func (r *BadgerDataStore) DeleteDatabase(id string) datastore.DataStoreStatus {
}
}
deleteKey(txn, databaseKey)
err := txn.Commit()
if err != nil {
logger.ErrorLn("Error while committing transaction:", err)

View File

@@ -202,22 +202,3 @@ func deleteKeysByPrefix(txn *badger.Txn, prefix string) error {
return nil
}
func deleteKey(txn *badger.Txn, key string) error {
_, err := txn.Get([]byte(key))
if err == badger.ErrKeyNotFound {
return nil
}
if err != nil {
logger.ErrorLn("Error while checking if key exists:", err)
return err
}
err = txn.Delete([]byte(key))
if err != nil {
logger.ErrorLn("Error while deleting key:", err)
return err
}
return nil
}

View File

@@ -24,8 +24,7 @@ func (r *BadgerDataStore) GetAllDocuments(databaseId string, collectionId string
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, "") + "/"
docs, status := listByPrefix[datastore.Document](r.db, prefix)
docs, status := listByPrefix[datastore.Document](r.db, generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, ""))
if status == datastore.StatusOk {
return docs, datastore.StatusOk
}
@@ -46,8 +45,7 @@ func (r *BadgerDataStore) GetDocumentIterator(databaseId string, collectionId st
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, "") + "/"
iter := NewBadgerDocumentIterator(txn, prefix)
iter := NewBadgerDocumentIterator(txn, generateKey(resourceid.ResourceTypeDocument, databaseId, collectionId, ""))
return iter, datastore.StatusOk
}

View File

@@ -24,8 +24,7 @@ func (r *BadgerDataStore) GetAllStoredProcedures(databaseId string, collectionId
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeStoredProcedure, databaseId, collectionId, "") + "/"
storedProcedures, status := listByPrefix[datastore.StoredProcedure](r.db, prefix)
storedProcedures, status := listByPrefix[datastore.StoredProcedure](r.db, generateKey(resourceid.ResourceTypeStoredProcedure, databaseId, collectionId, ""))
if status == datastore.StatusOk {
return storedProcedures, datastore.StatusOk
}

View File

@@ -24,8 +24,7 @@ func (r *BadgerDataStore) GetAllTriggers(databaseId string, collectionId string)
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeTrigger, databaseId, collectionId, "") + "/"
triggers, status := listByPrefix[datastore.Trigger](r.db, prefix)
triggers, status := listByPrefix[datastore.Trigger](r.db, generateKey(resourceid.ResourceTypeTrigger, databaseId, collectionId, ""))
if status == datastore.StatusOk {
return triggers, datastore.StatusOk
}

View File

@@ -24,8 +24,7 @@ func (r *BadgerDataStore) GetAllUserDefinedFunctions(databaseId string, collecti
return nil, datastore.StatusNotFound
}
prefix := generateKey(resourceid.ResourceTypeUserDefinedFunction, databaseId, collectionId, "") + "/"
udfs, status := listByPrefix[datastore.UserDefinedFunction](r.db, prefix)
udfs, status := listByPrefix[datastore.UserDefinedFunction](r.db, generateKey(resourceid.ResourceTypeUserDefinedFunction, databaseId, collectionId, ""))
if status == datastore.StatusOk {
return udfs, datastore.StatusOk
}

View File

@@ -1,21 +0,0 @@
package datastore
type InitialDataModel struct {
// Map databaseId -> Database
Databases map[string]Database `json:"databases"`
// Map databaseId -> collectionId -> Collection
Collections map[string]map[string]Collection `json:"collections"`
// Map databaseId -> collectionId -> documentId -> Documents
Documents map[string]map[string]map[string]Document `json:"documents"`
// Map databaseId -> collectionId -> triggerId -> Trigger
Triggers map[string]map[string]map[string]Trigger `json:"triggers"`
// Map databaseId -> collectionId -> spId -> StoredProcedure
StoredProcedures map[string]map[string]map[string]StoredProcedure `json:"sprocs"`
// Map databaseId -> collectionId -> udfId -> UserDefinedFunction
UserDefinedFunctions map[string]map[string]map[string]UserDefinedFunction `json:"udfs"`
}

View File

@@ -11,12 +11,12 @@ type Database struct {
type DataStoreStatus int
const (
StatusOk DataStoreStatus = 1
StatusNotFound DataStoreStatus = 2
Conflict DataStoreStatus = 3
BadRequest DataStoreStatus = 4
IterEOF DataStoreStatus = 5
Unknown DataStoreStatus = 6
StatusOk = 1
StatusNotFound = 2
Conflict = 3
BadRequest = 4
IterEOF = 5
Unknown = 6
)
type TriggerOperation string

View File

@@ -142,8 +142,6 @@ const (
FunctionCallSetIntersect FunctionCallType = "SetIntersect"
FunctionCallSetUnion FunctionCallType = "SetUnion"
FunctionCallIif FunctionCallType = "Iif"
FunctionCallMathAbs FunctionCallType = "MathAbs"
FunctionCallMathAcos FunctionCallType = "MathAcos"
FunctionCallMathAsin FunctionCallType = "MathAsin"
@@ -187,7 +185,9 @@ const (
FunctionCallAggregateMin FunctionCallType = "AggregateMin"
FunctionCallAggregateSum FunctionCallType = "AggregateSum"
FunctionCallIn FunctionCallType = "In"
FunctionCallIif FunctionCallType = "Iif"
FunctionCallIn FunctionCallType = "In"
FunctionCallUDF FunctionCallType = "UDF"
)
var AggregateFunctions = []FunctionCallType{
@@ -200,5 +200,6 @@ var AggregateFunctions = []FunctionCallType{
type FunctionCall struct {
Arguments []interface{}
UdfName string
Type FunctionCallType
}

View File

@@ -112,37 +112,6 @@ func Test_Parse(t *testing.T) {
)
})
t.Run("Should parse NOT IN function", func(t *testing.T) {
testQueryParse(
t,
`SELECT c.id FROM c WHERE c.id NOT IN ("123", "456")`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Invert: true,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallIn,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
testutils.SelectItem_Constant_String("123"),
testutils.SelectItem_Constant_String("456"),
},
},
},
},
)
})
t.Run("Should parse IN function with function call", func(t *testing.T) {
testQueryParse(
t,
@@ -217,4 +186,55 @@ func Test_Parse(t *testing.T) {
},
)
})
t.Run("Should parse SELECT with UDF function", func(t *testing.T) {
testQueryParse(
t,
`SELECT t.name, udf.CalculateTax(t.income, t.category) FROM t`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
testutils.SelectItem_Path("t", "name"),
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallUDF,
UdfName: "CalculateTax",
Arguments: []interface{}{
testutils.SelectItem_Path("t", "income"),
testutils.SelectItem_Path("t", "category"),
},
},
},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("t")},
},
)
})
t.Run("Should parse WHERE with UDF function", func(t *testing.T) {
testQueryParse(
t,
`SELECT c.id FROM c WHERE udf.IsEligible(c.status) = true`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
testutils.SelectItem_Path("c", "id"),
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.ComparisonExpression{
Left: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallUDF,
UdfName: "IsEligible",
Arguments: []interface{}{
testutils.SelectItem_Path("c", "status"),
},
},
},
Operation: "=",
Right: testutils.SelectItem_Constant_Bool(true),
},
},
)
})
}

File diff suppressed because it is too large Load Diff

View File

@@ -154,6 +154,14 @@ func createFunctionCall(functionType parsers.FunctionCallType, arguments []inter
return parsers.FunctionCall{Type: functionType, Arguments: arguments}, nil
}
func createUDFCall(functionName interface{}, arguments []interface{}) (parsers.FunctionCall, error) {
return parsers.FunctionCall{
Type: parsers.FunctionCallUDF,
UdfName: functionName.(string),
Arguments: arguments,
}, nil
}
func joinStrings(array []interface{}) string {
var stringsArray []string
for _, elem := range array {
@@ -511,7 +519,8 @@ BooleanLiteral <- ("true"i / "false"i) {
return parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: boolValue}, nil
}
FunctionCall <- StringFunctions
FunctionCall <- UDFFunction
/ StringFunctions
/ TypeCheckingFunctions
/ ArrayFunctions
/ ConditionalFunctions
@@ -519,6 +528,20 @@ FunctionCall <- StringFunctions
/ AggregateFunctions
/ MathFunctions
UDFFunction <- "udf"i ws "." ws functionName:Identifier ws "(" ws arguments:UDFArgumentList? ws ")" {
if arguments == nil {
return createUDFCall(functionName, []interface{}{})
}
return createUDFCall(functionName, arguments.([]interface{}))
}
UDFArgumentList <- arg1:SelectItem others:(ws "," ws arg:SelectItem { return arg, nil })* {
if others == nil {
return []interface{}{arg1}, nil
}
return append([]interface{}{arg1}, others.([]interface{})...), nil
}
StringFunctions <- StringEqualsExpression
/ ToStringExpression
/ ConcatExpression
@@ -803,33 +826,10 @@ MathNumberBinExpression <- "NumberBin"i ws "(" ws ex1:SelectItem others:(ws ","
MathPiExpression <- "PI"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathPi, []interface{}{}) }
MathRandExpression <- "RAND"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathRand, []interface{}{}) }
InFunction <- ex1:SelectProperty ws notIn:("NOT"i ws)? In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
arguments := append([]interface{}{ex1, ex2}, others.([]interface{})...)
functionCall, _ := createFunctionCall(parsers.FunctionCallIn, arguments)
if notIn != nil {
return parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: functionCall,
Invert: true,
}, nil
}
return functionCall, nil
}
/ "(" ws ex1:SelectItem ws notIn:("NOT"i ws)? In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" ws ")" {
arguments := append([]interface{}{ex1, ex2}, others.([]interface{})...)
functionCall, _ := createFunctionCall(parsers.FunctionCallIn, arguments)
if notIn != nil {
return parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: functionCall,
Invert: true,
}, nil
}
return functionCall, nil
InFunction <- ex1:SelectProperty ws In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
} / "(" ws ex1:SelectItem ws In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" ws ")" {
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
}
AvgAggregateExpression <- "AVG"i "(" ws ex:SelectItem ws ")" {

View File

@@ -231,9 +231,6 @@ func (r rowContext) selectItem_SelectItemTypeFunctionCall(functionCall parsers.F
case parsers.FunctionCallSetUnion:
return r.set_Union(functionCall.Arguments)
case parsers.FunctionCallIif:
return r.misc_Iif(functionCall.Arguments)
case parsers.FunctionCallMathAbs:
return r.math_Abs(functionCall.Arguments)
case parsers.FunctionCallMathAcos:
@@ -320,6 +317,10 @@ func (r rowContext) selectItem_SelectItemTypeFunctionCall(functionCall parsers.F
case parsers.FunctionCallIn:
return r.misc_In(functionCall.Arguments)
case parsers.FunctionCallIif:
return r.misc_Iif(functionCall.Arguments)
case parsers.FunctionCallUDF:
return r.misc_UDF(functionCall.Arguments)
}
logger.Errorf("Unknown function call type: %v", functionCall.Type)

View File

@@ -29,3 +29,7 @@ func (r rowContext) misc_Iif(arguments []interface{}) interface{} {
return r.resolveSelectItem(arguments[2].(parsers.SelectItem))
}
func (r rowContext) misc_UDF(arguments []interface{}) interface{} {
return "TODO"
}

View File

@@ -149,41 +149,6 @@ func Test_Execute(t *testing.T) {
)
})
t.Run("Should execute NOT IN function", func(t *testing.T) {
testQueryExecute(
t,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Invert: true,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallIn,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
testutils.SelectItem_Constant_String("123"),
testutils.SelectItem_Constant_String("456"),
},
},
},
},
mockData,
[]memoryexecutor.RowType{
map[string]interface{}{"id": "12345"},
map[string]interface{}{"id": "67890"},
},
)
})
t.Run("Should execute IN function with function call", func(t *testing.T) {
testQueryExecute(
t,

View File

@@ -38,7 +38,6 @@ func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
switch configuration.DataStore {
case config.DataStoreBadger:
dataStore = badgerdatastore.NewBadgerDataStore(badgerdatastore.BadgerDataStoreOptions{
InitialDataFilePath: configuration.InitialDataFilePath,
PersistDataFilePath: configuration.PersistDataFilePath,
})
default:

View File

@@ -7,9 +7,6 @@ int test_Databases();
int main(int argc, char *argv[])
{
/* Disable stdout buffering for CI environments without a real terminal */
setvbuf(stdout, NULL, _IONBF, 0);
if (argc < 2)
{
fprintf(stderr, "Usage: %s <path_to_shared_library>\n", argv[0]);
@@ -17,20 +14,13 @@ int main(int argc, char *argv[])
}
const char *libPath = argv[1];
handle = load_library(libPath);
handle = dlopen(libPath, RTLD_LAZY);
if (!handle)
{
fprintf(stderr, "Failed to load shared library: %s\n", get_load_error());
fprintf(stderr, "Failed to load shared library: %s\n", dlerror());
return EXIT_FAILURE;
}
/* give the loaded library a short time to initialize */
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
printf("Running tests for library: %s\n", libPath);
int results[] = {
test_CreateServerInstance(),
@@ -51,15 +41,6 @@ int main(int argc, char *argv[])
printf("Tests passed: %d/%d\n", numPassed, numTests);
/* Exit explicitly before unloading the library.
Go runtime cleanup during FreeLibrary can set a non-zero exit code on Windows. */
int exitCode = (numPassed == numTests) ? EXIT_SUCCESS : EXIT_FAILURE;
#ifdef _WIN32
ExitProcess(exitCode);
#else
close_library(handle);
#endif
return exitCode;
dlclose(handle);
return EXIT_SUCCESS;
}

View File

@@ -1,50 +1,13 @@
#include "shared.h"
lib_handle_t handle = NULL;
char *get_load_error(void)
{
#ifdef _WIN32
DWORD error = GetLastError();
static char buf[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, sizeof(buf), NULL);
return buf;
#else
return dlerror();
#endif
}
lib_handle_t load_library(const char *path)
{
#ifdef _WIN32
return LoadLibraryA(path);
#else
return dlopen(path, RTLD_LAZY);
#endif
}
void close_library(lib_handle_t handle)
{
#ifdef _WIN32
FreeLibrary(handle);
#else
dlclose(handle);
#endif
}
void *handle = NULL;
void *load_function(const char *func_name)
{
#ifdef _WIN32
void *func = (void *)GetProcAddress(handle, func_name);
#else
void *func = dlsym(handle, func_name);
#endif
if (!func)
{
fprintf(stderr, "Failed to load function %s: %s\n", func_name, get_load_error());
fprintf(stderr, "Failed to load function %s: %s\n", func_name, dlerror());
}
return func;
}

View File

@@ -3,24 +3,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
#include <ctype.h>
#ifdef _WIN32
#include <unistd.h>
#include <windows.h>
typedef HMODULE lib_handle_t;
#else
#include <dlfcn.h>
typedef void* lib_handle_t;
#endif
extern lib_handle_t handle;
extern void *handle;
void *load_function(const char *func_name);
char *compact_json(const char *json);
char *get_load_error(void);
lib_handle_t load_library(const char *path);
void close_library(lib_handle_t handle);
#endif

View File

@@ -2,16 +2,6 @@
int test_Databases()
{
/* Load FreeMemory function - must use this to free memory allocated by the DLL
because the DLL may use a different C runtime heap than the test loader */
typedef void (*FreeMemoryFn)(char *);
FreeMemoryFn FreeMemory = (FreeMemoryFn)load_function("FreeMemory");
if (!FreeMemory)
{
fprintf(stderr, "Failed to find FreeMemory function\n");
return 0;
}
typedef int (*CreateDatabaseFn)(char *, char *);
CreateDatabaseFn CreateDatabase = (CreateDatabaseFn)load_function("CreateDatabase");
if (!CreateDatabase)
@@ -46,7 +36,6 @@ int test_Databases()
if (database)
{
printf("GetDatabase: SUCCESS (database = %s)\n", database);
FreeMemory(database);
}
else
{

View File

@@ -2,16 +2,6 @@
int test_ServerInstanceStateMethods()
{
/* Load FreeMemory function - must use this to free memory allocated by the DLL
because the DLL may use a different C runtime heap than the test loader */
typedef void (*FreeMemoryFn)(char *);
FreeMemoryFn FreeMemory = (FreeMemoryFn)load_function("FreeMemory");
if (!FreeMemory)
{
fprintf(stderr, "Failed to find FreeMemory function\n");
return 0;
}
typedef int (*LoadServerInstanceStateFn)(char *, char *);
LoadServerInstanceStateFn LoadServerInstanceState = (LoadServerInstanceStateFn)load_function("LoadServerInstanceState");
if (!LoadServerInstanceState)
@@ -56,7 +46,7 @@ int test_ServerInstanceStateMethods()
char *compact_state = compact_json(state);
if (!compact_state)
{
FreeMemory(state);
free(state);
return 0;
}
@@ -69,12 +59,10 @@ int test_ServerInstanceStateMethods()
printf("GetServerInstanceState: State does not match expected value.\n");
printf("Expected: %s\n", expected_state);
printf("Actual: %s\n", compact_state);
FreeMemory(state);
free(compact_state);
return 0;
}
FreeMemory(state);
free(state);
free(compact_state);
return 1;
}