diff options
| author | Shulhan <ms@kilabit.info> | 2024-09-29 13:46:08 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-10-06 21:26:45 +0700 |
| commit | 28d36afe90804221e474406d6d04998ec926543c (patch) | |
| tree | a24b7ba331e9ec58e41c55e9343be533ebd6b42a | |
| parent | ef126797ffd6e3ea873bcad18b90a03c4c9071b8 (diff) | |
| download | ciigo-28d36afe90804221e474406d6d04998ec926543c.tar.xz | |
all: refactoring functions to accept non pointer struct option
The function that accept struct XxxOptions should only received
the copy of struct, not pointer.
| -rw-r--r-- | ciigo.go | 28 | ||||
| -rw-r--r-- | ciigo_test.go | 2 | ||||
| -rw-r--r-- | cmd/ciigo-example/main.go | 4 | ||||
| -rw-r--r-- | cmd/ciigo/main.go | 6 |
4 files changed, 14 insertions, 26 deletions
@@ -52,12 +52,9 @@ type Ciigo struct { // files using ConvertOptions HTMLTemplate file as base template. // If HTMLTemplate is empty it will default to use embedded HTML template. // See template_index_html.go for template format. -func Convert(opts *ConvertOptions) (err error) { - if opts == nil { - opts = &ConvertOptions{} - } +func Convert(opts ConvertOptions) (err error) { var ciigo = &Ciigo{} - return ciigo.Convert(*opts) + return ciigo.Convert(opts) } // GoEmbed generate a static Go file that embed all files inside Root except @@ -70,22 +67,16 @@ func Convert(opts *ConvertOptions) (err error) { // If HTMLTemplate option is empty it default to use embedded HTML // template. // See template_index_html.go for template format. -func GoEmbed(opts *EmbedOptions) (err error) { - if opts == nil { - opts = &EmbedOptions{} - } +func GoEmbed(opts EmbedOptions) (err error) { var ciigo = &Ciigo{} - return ciigo.GoEmbed(*opts) + return ciigo.GoEmbed(opts) } // Serve the content under directory "[ServeOptions].ConvertOptions.Root" // using HTTP server at specific "[ServeOptions].Address". -func Serve(opts *ServeOptions) (err error) { - if opts == nil { - opts = &ServeOptions{} - } +func Serve(opts ServeOptions) (err error) { var ciigo = &Ciigo{} - err = ciigo.InitHTTPServer(*opts) + err = ciigo.InitHTTPServer(opts) if err != nil { return err } @@ -100,12 +91,9 @@ func Serve(opts *ServeOptions) (err error) { // If the HTML template file modified, it will re-convert all markup files. // If the HTML template file deleted, it will replace them with internal, // default HTML template. -func Watch(opts *ConvertOptions) (err error) { - if opts == nil { - opts = &ConvertOptions{} - } +func Watch(opts ConvertOptions) (err error) { var ciigo = &Ciigo{} - return ciigo.Watch(*opts) + return ciigo.Watch(opts) } // isHTMLTemplateNewer will return true if HTMLTemplate is not defined or diff --git a/ciigo_test.go b/ciigo_test.go index 1484ce2..3b3f5de 100644 --- a/ciigo_test.go +++ b/ciigo_test.go @@ -123,7 +123,7 @@ func TestGoEmbed(t *testing.T) { fpath = filepath.Join(outDir, fname) tcase.opts.EmbedOptions.GoFileName = filepath.Join(outDir, fname) - err = GoEmbed(&tcase.opts) + err = GoEmbed(tcase.opts) if err != nil { t.Fatal(err) } diff --git a/cmd/ciigo-example/main.go b/cmd/ciigo-example/main.go index 5c563aa..a96a53d 100644 --- a/cmd/ciigo-example/main.go +++ b/cmd/ciigo-example/main.go @@ -23,7 +23,7 @@ var ciigoFS *memfs.MemFS func main() { var ( - opts = &ciigo.ServeOptions{ + opts = ciigo.ServeOptions{ ConvertOptions: ciigo.ConvertOptions{ Root: "_example", HTMLTemplate: "_example/html.tmpl", @@ -71,7 +71,7 @@ func doEmbed() { err error ) - err = ciigo.GoEmbed(&opts) + err = ciigo.GoEmbed(opts) if err != nil { log.Fatal(err) } diff --git a/cmd/ciigo/main.go b/cmd/ciigo/main.go index d4d4fc9..a4b734c 100644 --- a/cmd/ciigo/main.go +++ b/cmd/ciigo/main.go @@ -67,7 +67,7 @@ func main() { switch command { case cmdConvert: - err = ciigo.Convert(&convertOpts) + err = ciigo.Convert(convertOpts) case cmdEmbed: var embedOpts = ciigo.EmbedOptions{ @@ -79,7 +79,7 @@ func main() { }, } - err = ciigo.GoEmbed(&embedOpts) + err = ciigo.GoEmbed(embedOpts) case cmdHelp: usage() @@ -91,7 +91,7 @@ func main() { EnableIndexHTML: true, IsDevelopment: true, } - err = ciigo.Serve(&serveOpts) + err = ciigo.Serve(serveOpts) case cmdVersion: fmt.Println(ciigo.Version) |
