The chapter4 application code

Let's examine our chapter4 implementation, starting with main.go:

package main

import (
. "github.com/l3x/learn-fp-in-go/chapter4/01_hof"
"log"
"os"
"github.com/julienschmidt/httprouter"
"net/http"
)

The dot (.) in the  . "github.com/l3x/learn-fp-in-go/chapter4/01_hof" import keeps us from having to preface the functions in that directory with hof, which is the package name used by all the Go files in that directory:

func init() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
}

We'll use the log package to log output to stdout. Passing a 0 value to log.SetFlags tells the logger to print without prepending timestamps. We also tell the logger to print to stdout, rather than the default stderr because we want all of the output to be consistently displayed for ease of reading. We'd likely not output any information to stdout for a production application because there isn't anything useful for the program to send on stdout other than command help and usage information.

The log function can easily be configured to prepend timestamps and line numbers. The log.SetFlags(log.Lshortfile | log.Ldate) setting will print the output to stdout:  2017/04/07 utils.go:17: car: Honda Accord.