diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-07 23:19:25 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-07 23:19:25 +0700 |
| commit | 9a03cfb3c4289b9af54246950c957265ee83ecc5 (patch) | |
| tree | 1db026642f3d9d10cda2124cb7935ade3d2d1f2e /internal/cmd/ciigo-example/main.go | |
| parent | 028580508facc0924cab1666e8aeacdc72e280a1 (diff) | |
| download | ciigo-9a03cfb3c4289b9af54246950c957265ee83ecc5.tar.xz | |
all: move example for ciigo as library to internal/cmd/ciigo-example
While at it, update the example index by removing unnecessary
external image, and update links to open in new tab/window.
Diffstat (limited to 'internal/cmd/ciigo-example/main.go')
| -rw-r--r-- | internal/cmd/ciigo-example/main.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/cmd/ciigo-example/main.go b/internal/cmd/ciigo-example/main.go new file mode 100644 index 0000000..e1b8c58 --- /dev/null +++ b/internal/cmd/ciigo-example/main.go @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2019 Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +// Program ciigo-example provide an example on how to build a binary that +// include the static, generated .go file. +package main + +import ( + "flag" + "log" + "strings" + + "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" + + "git.sr.ht/~shulhan/ciigo" +) + +const ( + cmdEmbed = `embed` +) + +var ciigoFS *memfs.MemFS + +func main() { + var ( + opts = ciigo.ServeOptions{ + ConvertOptions: ciigo.ConvertOptions{ + Root: `_example`, + HTMLTemplate: `_example/html.tmpl`, + }, + Mfs: ciigoFS, + Address: `127.0.0.1:8080`, + IsDevelopment: true, + } + + cmd string + err error + ) + + flag.Parse() + + cmd = strings.ToLower(flag.Arg(0)) + if cmd == cmdEmbed { + doEmbed() + return + } + + err = ciigo.Serve(opts) + if err != nil { + log.Fatal(err) + } +} + +func doEmbed() { + var opts = ciigo.EmbedOptions{ + ConvertOptions: ciigo.ConvertOptions{ + Root: `_example`, + HTMLTemplate: `_example/html.tmpl`, + Exclude: []string{ + `.*/\..*$`, + }, + }, + EmbedOptions: memfs.EmbedOptions{ + CommentHeader: `// SPDX-FileCopyrightText: 2019 Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later +`, + PackageName: `main`, + VarName: `ciigoFS`, + GoFileName: `internal/cmd/ciigo-example/static.go`, + WithoutModTime: true, + }, + } + + var err = ciigo.GoEmbed(opts) + if err != nil { + log.Fatal(err) + } +} |
