From 0dea23ff24966e79b5c9424799e1d73d345a9711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Yasir=20Na=C3=A7?= <76746351+aliyasirnac@users.noreply.github.com> Date: Sat, 26 Apr 2025 11:22:31 +0300 Subject: [PATCH] removed Config.Mode until supported in official sdk and added connection url validation --- surrealdb/config.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/surrealdb/config.go b/surrealdb/config.go index 07bd974b..7fcf1224 100644 --- a/surrealdb/config.go +++ b/surrealdb/config.go @@ -1,5 +1,10 @@ package surrealdb +import ( + "log" + "strings" +) + // Config holds the configuration required to initialize and connect to a SurrealDB instance. // It includes authentication credentials, namespace/database selection, and default storage settings. // @@ -13,7 +18,7 @@ package surrealdb // - Scope: optional scope name for scoped authentication (e.g., user login scopes). // - DefaultTable: the default table name where key-value records will be stored. type Config struct { - // The connection URL to connect to SurrealDB + // WebSocket connections (ws:// or wss://) are recommended over HTTP for better reliability ConnectionString string // The namespace to be used in SurrealDB @@ -36,13 +41,6 @@ type Config struct { // The default table used to store key-value records DefaultTable string - - //// Mode determines the operational mode of SurrealDB. - //// Accepted values: - //// - "default" (requires authentication) - //// - "memory" (in-memory mode, no authentication required) - not supported - //// - "kv" (file-based key-value store, no authentication required) - not supported - //Mode string } var ConfigDefault = Config{ @@ -97,9 +95,10 @@ func configDefault(config ...Config) Config { cfg.DefaultTable = ConfigDefault.DefaultTable } - //if cfg.Mode == "" { - // cfg.Mode = ConfigDefault.Mode - //} + if !strings.HasPrefix(cfg.ConnectionString, "ws://") && !strings.HasPrefix(cfg.ConnectionString, "wss://") && + !strings.HasPrefix(cfg.ConnectionString, "http://") && !strings.HasPrefix(cfg.ConnectionString, "https://") { + log.Printf("Warning: ConnectionString %s doesn't start with ws://, wss://, http:// or https://", cfg.ConnectionString) + } return cfg }