All of these example Go programs are complete. You can run most or all of them on the Go Playground.
- flagbool.go Illustrates output of the simplest possible command-line boolean flag using the flag package
- cmdline shows how to parse the command line, with optional subcommands like "init" or "init sitename=test", and also how to retrieve those values later
- dl.go - dl lists all directories in the specified path (defaults to current directory). Gist at https://gist.github.com/tomcam/db640cfc7b846e083f4f7dec19cf345d
- dirtree.go - Show directory tree as string slice. Allow files & dirs to be excluded
- lastmodified.go - Reusable code (and demo) showing how to retrieve the last modified date of a file by filename
- genfiletree.go - Generate small tree of text files, e.g. for a website. Gist at https://gist.github.com/tomcam/9766ca1ea4d63eff804335c5f391ab09
- filewatch1.go - Short demo of radovskyb's recursive file watching package. Gist at https://gist.github.com/tomcam/32760a5049a00ec6ba82bcb42b6759fc
- filewatch2.go - Short demo of radovskyb's recursive file watching package with different order of execution. Gist at https://gist.github.com/tomcam/32760a5049a00ec6ba82bcb42b6759fc
- embedlistdir.go creates an executable that embeds a directory, then displays the filenames in that directory at runtime
- lastmodified.go - Reusable code (and demo) showing how to retrieve the last modified date of a file by filename
- genfiletree.go - Generate small tree of text files, e.g. for a website. Gist at https://gist.github.com/tomcam/9766ca1ea4d63eff804335c5f391ab09
- fieldisstringtype.go determines at runtime whether the struct passed in the argument has a field named in the second argument of type string. Playground version at https://play.golang.org/p/yAEXeeCvJMH
- structfieldbynamestrmust.go takes any struct and field name (as a string) at runtime and returns the string value of that field. It returns an empty string if the object passed in isn't a struct, or if the named field isn't a struct. Playground version at https://play.golang.org/p/MiCn6NtEp5-
- structinfo.go:
structInfo()
takes any struct at runtime and displays its type name, field names and types, and contents of each field.structHasField()
returns true if a struct passed to it at runtime contains a field name passed as a string. Playground version at https://play.golang.org/p/zeOTNfHEQlH
- jsonstruct.go - Initialize nested struct in Golang. Read and write nested structs to a JSON file in Go. See also jconstruct on Go playground
- md2htmltemplates.go Demonstrates using progressive, self-contained functions the goldmark Markdown to HTML converter using an App object, code highlighting. extracting YAML front matter, executing a template to interpolate front matter metadata with its evaluated result, and adding a custom template function. Go Playground version, Gist
- Gist with simplest Goldmark demo Gist with simplest Goldmark demo.)
- microcms A one-file Markdown to HTML converter. No front matter support.
- goldmark converter using an App object. See playground version or https://go.dev/play/p/XNsZD6bqIXJ
- Goldmark demo with with App object, Markdown to HTML conversion, code highlighting, YAML front matter support, and template support with custom template functions, gist here, go Playground version here
- md2rawhtml Smallest general-purpose micro CMS that converts a Markdown to a raw HTML file with no head, html tags, etc.
- Goldmark demo with App object Markdown to HTML conversion, code highlighting, YAML support, simple template support, playground version here
- goldmark1.go Simplest example showing how to convert Markdown file to HTML using Goldmark
- burntsushitest.go - Use burntsushi to read a TOML file
- blackfriday - Simple command line programs shoing how to use the Blackfriday parser convert Markdown in to HTML. cli2 also shows how to append file extensions and parse flags
- regexreplace.go - Replaces a Go template identifier like {{.Name}} with an arbitrary string.
- Extracting HTML headers using go regexp
- dirtree.go - Show directory tree as string slice. Allow files & dirs to be excluded
- dirtree.go - Show directory tree as string slice. Allow files & dirs to be excluded
- tmplfunction.go shows how to add a custom function to a Go HTML template. Followup to cfgfile.go.
- funcmap1.go Shows how to add multiple custom template functions (Playground version here
- cfgfile.go - Store config in TOML file, then show its value in an HTML go HTML template. tmplfunction.go builds on it by adding a custom function.
- tomlperplatform.go creates a TOML config file that sniffs out the host OS so you can write values specific to it
- tomlgen.go creates a general purpose TOML file that lets you define sections/kv pairs at will
- General purpose TOML read/write using BurntSushi (gist): https://play.golang.org/p/LgZwOT363sZ
- Simple example of reading a TOML file using BurntSushi (playground): https://play.golang.org/p/klLI41DiwqC
- yamlreadwritestruct.go, playground version here
- structtomap1.go (gist) Go/Golang, playground version here: Writes a struct to a YAML file, then reads it back from the YAML as a map using the gopkg.in/yaml package