aboutsummaryrefslogtreecommitdiff
path: root/server.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 /server.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 'server.go')
-rw-r--r--server.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/server.go b/server.go
index e787b30..d225836 100644
--- a/server.go
+++ b/server.go
@@ -32,18 +32,18 @@ type server struct {
// The htmlTemplate parameter is optional, if not set its default to
// embedded HTML template.
//
-func newServer(mfs *memfs.MemFS, root, address, htmlTemplate string) (srv *server, err error) {
+func newServer(opts *ServeOptions) (srv *server, err error) {
logp := "newServer"
srv = &server{
opts: &libhttp.ServerOptions{
Options: memfs.Options{
- Root: root,
+ Root: opts.Root,
Excludes: defExcludes,
Development: debug.Value > 0,
},
- Memfs: mfs,
- Address: address,
+ Memfs: opts.Mfs,
+ Address: opts.Address,
},
}
@@ -65,18 +65,18 @@ func newServer(mfs *memfs.MemFS, root, address, htmlTemplate string) (srv *serve
return nil, fmt.Errorf("%s: %w", logp, err)
}
- srv.htmlg, err = newHTMLGenerator(mfs, htmlTemplate, srv.opts.Development)
+ srv.htmlg, err = newHTMLGenerator(opts.Mfs, opts.HtmlTemplate, srv.opts.Development)
if err != nil {
return nil, fmt.Errorf("%s: %w", logp, err)
}
if srv.opts.Development {
- srv.watcher, err = newWatcher(srv.htmlg, root)
+ srv.watcher, err = newWatcher(srv.htmlg, opts.Root)
if err != nil {
return nil, fmt.Errorf("%s: %w", logp, err)
}
- srv.watcher.fileMarkups, err = listFileMarkups(root)
+ srv.watcher.fileMarkups, err = listFileMarkups(opts.Root)
if err != nil {
return nil, fmt.Errorf("%s: %w", logp, err)
}