aboutsummaryrefslogtreecommitdiff

Go Website

Designed to be a basic website written in Go, primarliy targeted at blogs but can easily be used for landing pages and other basic information sites.

Entirely driven by the filesystem there's a special markdown format that lets you set some variables in yaml at the top and the rest of the page body in markdown for the rest.

It's designed to be somewhat easy to use by an intelligent lay person, once the website is setup most pages can be edited from the dashboard once the user is logged in.

Multiple users can be specified in the auth.json file. No auth.json file is required, the program will create and save one automatically when it first runs. Just be aware that the username/password defaults to admin admin.

You can generate password hashes with the -genhash flag, it will prompt you to input your password and it will spit out a hash.

If you set a password clear text in auth.json it will be rewritten as the hash alone when the program is run. It's not recommended, but offered as a convenience.

If you wish to use a file other than auth.json you can specify one from the command line flags.

There's an example website in example-site

Additionally it's designed to handle a large amount of requests by caching the output of the templates in redis rather than rendering them dynamically on each page load. This is an optional feature, easily disabled.

Internally page rendering is split into its own library with most of the site functionality being handled in the cmd, this allows you to build full custom applications with a somewhat familiar markdown rendering paradigm if you wish to edit the go.

Building

If you're on Windows:

Then from the "Git Bash" prompt cd to the directory in which you checked out this repostiroy and simply run sh ./build.sh You should now have a server.exe file that you can call to run the website.

If you're on Linux:

  • Install Go
  • run sh ./build.sh

MacOS is very similar, if Go is in your path the build script should produce a server.

Starting the example website

After running the build script:

$ ./server -d ./example-site -l 127.0.0.1:8001 -r ""

The simply load up http://localhost:8001 in your web browser

Feel free to edit anything in example-site to your heart's content.

The only runtime requirements for the website are the website directory and the server executable.

Example git hook for automatically updating a production website

Say you're like me and like editing your website from a command line editor and committing each change. Well, it's easy enough to deploy your changes to your production website with a simple git push, simply clone the repository on your remote server and add this post-receive hook:

#!/bin/sh
# .git/hooks/post-receive
set -e
# Requires `git config  receive.denyCurrentBranch "ignore"` in order to be useful
unset GIT_DIR
unset GIT_WORK_TREE
cd ..
git config receive.denyCurrentBranch "ignore"
set -x
git reset --hard HEAD
redis-cli del 'cache:example.com'

Then on your local copy:

$ git remote add production myProductionServer.example.com:/path/to/checkout/on/disk

Now, when you run git push production master the myProductionServer.example.com machine will automatically update the git repository and clear the redis cache, in this case for example.com

Help output from server

The options most people will be interested in are -l, -d, -r, -c and -ac

$ ./server -h
Usage of Website:
  -T string
        Override the default format used to parse page time. Be careful. (Environ: 'TIME_FORMAT') (default "01.02.2006 15:04:05 MST")
  -V    Be more verbose, dump config and such (Environ: 'VERBOSE')
  -ac string
        location for the authorization config (Environ: 'AUTH_CONFIG') (default "auth.json")
  -c string
        Location for configuration file (Environ: 'CONFIG_FILE') (default "conf.yml")
  -cache-index
        If set to false, do not cache the page index (Environ: 'CACHE_INDEX') (default true)
  -d string
        Website directory to serve (Environ: 'SITE_DIR') (default ".")
  -genhash
        If set to true, interactively generate a password hash (Environ: 'INTERACTIVE_HASH_GEN')
  -i string
        Path in which, when called will rebuild the index and clear the cache (Environ: 'INDEX_PATH') (default "/reIndex")
  -l string
        listening address (Environ: 'LISTEN_ADDR') (default ":8001")
  -r string
        Redis server set to "" to disable (Environ: 'REDIS_ADDR') (default "127.0.0.1:6379")
  -rk string
        Redis key to use for storing cached pages (Environ: 'REDIS_KEY') (default "go-website")
  -timeout int
        Seconds until page timeout for read and write (Environ: 'HTTP_TIMEOUT') (default 15)
  -v    print version and exit (Environ: 'PRINT_VERSION_AND_EXIT')
$

Environment variables listed above can be used in lieu of the flags.