func main() { cfg := jsoncfgo.Load("/Users/lex/dev/go/data/jsoncfgo/simple-config.json") host := cfg.String("host") fmt.Printf("host: %v\n", host) bogusHost := cfg.String("bogusHost", "default_host_name") fmt.Printf("host: %v\n\n", bogusHost) port := cfg.Int("port") fmt.Printf("port: %v\n", port) bogusPort := cfg.Int("bogusPort", 9000) fmt.Printf("bogusPort: %v\n\n", bogusPort) bigNumber := cfg.Int64("bignNumber") fmt.Printf("bigNumber: %v\n", bigNumber) bogusBigNumber := cfg.Int64("bogusBigNumber", 9000000000000000000) fmt.Printf("bogusBigNumber: %v\n\n", bogusBigNumber) active := cfg.Bool("active") fmt.Printf("active: %v\n", active) bogusFalseActive := cfg.Bool("bogusFalseActive", false) fmt.Printf("bogusFalseActive: %v\n", bogusFalseActive) bogusTrueActive := cfg.Bool("bogusTrueActive", true) fmt.Printf("bogusTrueActive: %v\n\n", bogusTrueActive) appList := cfg.List("appList") fmt.Printf("appList: %v\n", appList) bogusAppList := cfg.List("bogusAppList", []string{"app1", "app2", "app3"}) fmt.Printf("bogusAppList: %v\n\n", bogusAppList) numbers := cfg.IntList("numbers") fmt.Printf("numbers: %v\n", numbers) bogusSettings := cfg.IntList("bogusSettings", []int64{1, 2, 3}) fmt.Printf("bogusAppList: %v\n\n", bogusSettings) if err := cfg.Validate(); err != nil { time.Sleep(100 * time.Millisecond) defer log.Fatalf("ERROR - Invalid config file...\n%v", err) return } }
func main() { cfg := jsoncfgo.Load("/Users/lex/dev/go/data/webserver/webserver-config.json") host := cfg.OptionalString("host", "localhost") fmt.Printf("host: %v\n", host) port := cfg.OptionalInt("port", 8080) fmt.Printf("port: %v\n", port) Dir = cfg.OptionalString("dir", "www/") fmt.Printf("web_dir: %v\n", Dir) redirect_code := cfg.OptionalInt("redirect_code", 307) fmt.Printf("redirect_code: %v\n\n", redirect_code) mux := http.NewServeMux() fileServer := http.Dir(Dir) fileHandler := http.FileServer(fileServer) mux.Handle("/", fileHandler) rdh := http.RedirectHandler("http://example.org", redirect_code) mux.Handle("/redirect", rdh) mux.Handle("/notFound", http.NotFoundHandler()) mux.Handle("/help", http.HandlerFunc(HelpHandler)) mux.Handle("/debugForm", http.HandlerFunc(DebugFormHandler)) mux.Handle("/debugQuery", http.HandlerFunc(DebugQueryHandler)) mux.Handle("/user/", http.HandlerFunc(UserHandler)) mux.Handle("/ajax", http.HandlerFunc(AjaxHandler)) mux.Handle("/adapter", errorHandler(wrappedHandler)) log.Printf("Running on port %d\n", port) addr := fmt.Sprintf("%s:%d", host, port) Users := jsoncfgo.Load("/Users/lex/dev/go/data/webserver/users.json") joesample := Users.OptionalObject("joesample") fmt.Printf("joesample: %v\n", joesample) fmt.Printf("joesample['firstname']: %v\n", joesample["firstname"]) fmt.Printf("joesample['lastname']: %v\n\n", joesample["lastname"]) alicesmith := Users.OptionalObject("alicesmith") fmt.Printf("alicesmith: %v\n", alicesmith) fmt.Printf("alicesmith['firstname']: %v\n", alicesmith["firstname"]) fmt.Printf("alicesmith['lastname']: %v\n\n", alicesmith["lastname"]) bobbrown := Users.OptionalObject("bobbrown") fmt.Printf("bobbrown: %v\n", bobbrown) fmt.Printf("bobbrown['firstname']: %v\n", bobbrown["firstname"]) fmt.Printf("bobbrown['lastname']: %v\n\n", bobbrown["lastname"]) AppContext = go_oops.NewSingleton() AppContext.Data["CookieNameForUsername"] = "******" AppContext.Data["joesample"] = joesample AppContext.Data["alicesmith"] = alicesmith AppContext.Data["bobbrown"] = bobbrown fmt.Printf("AppContext: %v\n", AppContext) fmt.Printf("AppContext.Data[\"joesample\"]: %v\n", AppContext.Data["joesample"]) fmt.Printf("AppContext.Data[\"alicesmith\"]: %v\n", AppContext.Data["alicesmith"]) fmt.Printf("AppContext.Data[\"bobbrown\"]: %v\n\n", AppContext.Data["bobbrown"]) err := http.ListenAndServe(addr, mux) fmt.Println(err.Error()) }