-
Notifications
You must be signed in to change notification settings - Fork 2
/
embed.go
62 lines (47 loc) · 1.37 KB
/
embed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"github.com/cognusion/go-jar"
"github.com/spf13/pflag"
"fmt"
"net/http"
)
func init() {
var err error
// Set up the CLI for your program
// pflag isn't required, but makes integration with
// the Conf structure seamless (see Conf.BindPFlags, below)
pflag.Bool(jar.ConfigDebug, false, "Enable vociferous output")
pflag.Bool(jar.ConfigCheckConfig, false, "Run through the config load and then exit")
config := pflag.String("config", "", "Config file to load")
pflag.Parse()
// Load the config file, maybe
if *config != "" {
err = jar.LoadConfig(*config, jar.Conf)
if err != nil {
jar.ErrorOut.Fatalf("Error loading config '%s': %s\n", *config, err)
}
}
// Bind commandline flags to the global config
jar.Conf.BindPFlags(pflag.CommandLine)
jar.LogInit()
}
func main() {
// Link our LazyLogger as a Handler
jar.Handlers["lazylogger"] = LazyLogger
// Link our AllDone as a Finisher
jar.Finishers["donezo"] = AllDone
// Make. It. So.
jar.Bootstrap()
}
// AllDone is an example Finisher
func AllDone(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Request Received")
}
// LazyLogger is an example Handler that does logging lazily
func LazyLogger(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("LAZY LOGGING: %+v\n", r)
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}