aboutsummaryrefslogtreecommitdiff
path: root/client_options.go
diff options
context:
space:
mode:
Diffstat (limited to 'client_options.go')
-rw-r--r--client_options.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/client_options.go b/client_options.go
new file mode 100644
index 0000000..477bcb7
--- /dev/null
+++ b/client_options.go
@@ -0,0 +1,42 @@
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-only
+
+package lilin
+
+import (
+ "fmt"
+ "net/url"
+ "time"
+)
+
+const defTimeout = 5 * time.Second
+
+// ClientOptions options for client.
+type ClientOptions struct {
+ serverURL *url.URL
+
+ // ServerURL define the full URL of Lilin server.
+ ServerURL string
+
+ // Timeout for server connection, default to 5 seconds.
+ Timeout time.Duration
+}
+
+// init validate and initialize the options.`
+func (opts *ClientOptions) init() (err error) {
+ var logp = `init`
+
+ if opts.ServerURL == `` {
+ return fmt.Errorf(`%s: missing ServerURL`, logp)
+ }
+
+ opts.serverURL, err = url.Parse(opts.ServerURL)
+ if err != nil {
+ return fmt.Errorf(`%s: %s`, logp, err)
+ }
+
+ if opts.Timeout == 0 {
+ opts.Timeout = defTimeout
+ }
+ return nil
+}