diff options
| author | Shulhan <ms@kilabit.info> | 2019-08-05 22:43:27 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-08-05 22:43:27 +0700 |
| commit | e146ea686fdecee45311eab1285e0e361bf501df (patch) | |
| tree | 8a882e861b23cfd73009c12aca8c87079aaf9067 /server.go | |
| parent | 616712b8a644fc346681d112ce3f866315371c83 (diff) | |
| download | ciigo-e146ea686fdecee45311eab1285e0e361bf501df.tar.xz | |
server: add parameter to change the root directory
Previously the default root directory to be served by ciigo is
"content" directory inside the top directory.
This change allow ciigo to serve any directory pointed by first parameter
in NewServer(), and if its empty default to "content".
Diffstat (limited to 'server.go')
| -rw-r--r-- | server.go | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -31,23 +31,23 @@ type Server struct { // NewServer create an HTTP server to serve HTML files in directory "content". // The address parameter is optional, if not set its default to ":8080". // -func NewServer(address string) (srv *Server) { +func NewServer(root, address string) (srv *Server) { var err error + if len(root) == 0 { + root = dirRoot + } if len(address) == 0 { address = ":8080" } - srv = new(Server) - - srv.opts = &libhttp.ServerOptions{ - Address: address, - Root: dirRoot, - Excludes: []string{ - `.*\.adoc$`, - `.*\.md$`, + srv = &Server{ + opts: &libhttp.ServerOptions{ + Address: address, + Root: root, + Excludes: defExcludes, + Development: debug.Value > 0, }, - Development: debug.Value > 0, } srv.http, err = libhttp.NewServer(srv.opts) @@ -57,7 +57,7 @@ func NewServer(address string) (srv *Server) { if srv.opts.Development { srv.htmlg = newHTMLGenerator() - srv.markupFiles = listMarkupFiles(dirRoot) + srv.markupFiles = listMarkupFiles(root) } return srv @@ -82,7 +82,7 @@ func (srv *Server) Start() { func (srv *Server) autoGenerate() { srv.dw = &libio.DirWatcher{ - Path: dirRoot, + Path: srv.opts.Root, Delay: time.Second, Includes: []string{ `.*\.adoc$`, @@ -91,6 +91,7 @@ func (srv *Server) autoGenerate() { Excludes: []string{ `assets/.*`, `.*\.html$`, + `^\..*`, }, Callback: srv.onChangeMarkupFile, } |
