aboutsummaryrefslogtreecommitdiff
path: root/serve_options.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-04-03 04:05:01 +0700
committerShulhan <ms@kilabit.info>2021-04-03 04:40:27 +0700
commit2c1ec60015ed4a29134be4d8ddd1c71d38bf52fa (patch)
tree37f30fa6cbe8f3287597808153aa78500b928e7d /serve_options.go
parent298eb4dff25b4e97b66d49f005c896a88b0df5c6 (diff)
downloadciigo-2c1ec60015ed4a29134be4d8ddd1c71d38bf52fa.tar.xz
all: change the Serve signature to ServeOptions
Previously, we pass four parameters to Serve function: the instance to memfs.MemFS, the root directory, the address to listen, and path to HTML template. In case we need to add new parameter in the future, the Serve function signature will changes and this is not good for consumer of API. This commit changes the Serve function parameters to ServeOptions so we can add optional parameter in the future without changes to its signature.
Diffstat (limited to 'serve_options.go')
-rw-r--r--serve_options.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/serve_options.go b/serve_options.go
new file mode 100644
index 0000000..953bb1f
--- /dev/null
+++ b/serve_options.go
@@ -0,0 +1,33 @@
+// Copyright 2021, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package ciigo
+
+import "github.com/shuLhan/share/lib/memfs"
+
+const (
+ defAddress = ":8080"
+)
+
+//
+// ServeOptions contains the options to use on Serve function.
+//
+type ServeOptions struct {
+ ConvertOptions
+
+ // Mfs contains pointer to variable generated from Generate.
+ // This option is used to use embedded files for serving on HTTP.
+ Mfs *memfs.MemFS
+
+ // Address to listen and serve for HTTP request.
+ Address string
+}
+
+func (opts *ServeOptions) init() {
+ opts.ConvertOptions.init()
+
+ if len(opts.Address) == 0 {
+ opts.Address = defAddress
+ }
+}