Next: , Previous: , Up: godlighty  


Initially godlighty has basic static files handlers (with compression, HTTP preconditions are enabled of course). In the example below there are nearly all default functions. Also look for rc/example.cfg.

Hosts[""] = &godlighty.HostCfg{
    Root: "/www/",
    EdDSATLS: &godlighty.TLSCfg{
        Cert: "/path/to/",
        Key: "/path/to/",
        CACert: "/path/to/ca.pem",
    DirList: true,
    WebDAV: true,
    MIMEs: map[string]string{
        ".special": "text/x-special-type",

If your keys and certificates are in single file and you use common CA certificate, then it is trivial to DRY:

var (
    Etc = "/whatever"
    CACert = path.Join(Etc, "ca.pem")

func newTLSCfg(host string) *godlighty.TLSCfg {
    return &godlighty.TLSCfg{
        Cert:   path.Join(Etc, host+".pem"),
        Key:    path.Join(Etc, host+".pem"),
        CACert: CACert,

But there are hooks that can do anything more. For example if you want to run CGI script or make a redirection (FastCGI handler example is in rc/fcgi.example.cfg):

    Hooks: []godlighty.Hook{
        func(w http.ResponseWriter, r *http.Request) bool {
            if r.URL.Path == "/" {
                http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
                return true
            return false
        func(w http.ResponseWriter, r *http.Request) bool {
                Path: "/usr/local/libexec/git-core/git-http-backend",
                Dir:  "/var/empty",
                Env: []string{
                    "GIT_PROJECT_ROOT=" + root,
            }.ServeHTTP(w, r)
            return true

You can separate your configuration files and add them through init() call:

$ ls rc/

$ cat rc/
package rc

import "path"

func addStaticCfg(host, root string) {
    if !path.IsAbs(root) {
        root = path.Join(WWW, root)
    godlighty.Hosts[host] = &godlighty.HostCfg{
        Root: root,
        TLS:  newTLSCfg(host),

func addStaticListedDir(host, root string) {
    addStaticCfg(host, root)
    godlighty.Hosts[host].DirList = true
    godlighty.Hosts[host].WebDAV = true

func init() {
    addStaticCfg("", "/storage/paster/pastes")
    addStaticCfg("", "")
    addStaticCfg("", "")
    addStaticListedDir("", "/storage/audiobook/mds")

There are some preexisting helpers to deal with:


CGI scripts.


Loggable redirects.

rc/mime.go, rc/mime/*

Predefined Content-Type entries. Each file in rc/mime/* has tab-separated format: file’s extension, media type and optional c mark, meaning that these type can be transparently compressed on-the-fly.

Next: Usage, Previous: godlighty, Up: godlighty