From c114a91bb66872fa72f9ebb3df46bdd8c8cea8a1 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 9 Sep 2016 15:39:45 -0400 Subject: [PATCH] Added debug mode, Fix #55 Former-commit-id: f5d1d9dcc70c95c00f2a7d242a3f982e78539e57 [formerly def6a11c20d8c01fd87265d630007117ef4f02f2] [formerly 0015e78ce5c1aea4eb095391ae4e1398f9d5f353 [formerly f6ee202630bbaae1d47adeee8f30151ba8267580]] Former-commit-id: 81f38e3a512c6d8ed92350610964fc91b4cb4aa2 [formerly f7bf932204209270ed361f5a42706489be2cc8cb] Former-commit-id: 07c9fee1d5b192b213f1d25e524ac01740ea58e5 --- main.go | 11 +++++++++++ routes.go | 6 +----- utils.go | 6 +++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 480816c..ef0e113 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,7 @@ var RuntimeArgs struct { ForceWss bool DumpDataset string RestoreDataset string + Debug bool } var VersionNum string @@ -56,6 +57,7 @@ func main() { flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key") flag.StringVar(&RuntimeArgs.WikiName, "w", "cowyo", "custom name for wiki") flag.BoolVar(&RuntimeArgs.ForceWss, "e", false, "force encrypted sockets (use if using Caddy auto HTTPS)") + flag.BoolVar(&RuntimeArgs.Debug, "d", false, "debugging mode") flag.StringVar(&RuntimeArgs.DumpDataset, "dump", "", "directory to dump all data to") flag.StringVar(&RuntimeArgs.RestoreDataset, "restore", "", "directory to restore all data from") flag.CommandLine.Usage = func() { @@ -76,6 +78,13 @@ Options:`) } flag.Parse() + // Set the log level + if RuntimeArgs.Debug == false { + logger.Level(2) + } else { + logger.Level(0) + } + if len(RuntimeArgs.DumpDataset) > 0 { fmt.Println("Dumping data to '" + RuntimeArgs.DumpDataset + "' folder...") dumpEverything(RuntimeArgs.DumpDataset) @@ -84,7 +93,9 @@ Options:`) RuntimeArgs.ExternalIP = flag.Arg(0) if RuntimeArgs.ExternalIP == "" { + logger.Debug("Getting external ip...") RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port + logger.Debug("Using ip: %s and port %s", GetLocalIP(), RuntimeArgs.Port) } RuntimeArgs.SourcePath = cwd diff --git a/routes.go b/routes.go index dde8a32..0047bf0 100644 --- a/routes.go +++ b/routes.go @@ -235,9 +235,6 @@ func getRecentlyEdited(title string, c *gin.Context) []string { recentlyEdited = title } else { editedThings = strings.Split(v.(string), "|||") - fmt.Println(editedThings) - fmt.Println(v.(string)) - fmt.Println(title) if !stringInSlice(title, editedThings) { recentlyEdited = v.(string) + "|||" + title } else { @@ -618,7 +615,7 @@ func dumpEverything(folderpath string) { defer Close() err := os.MkdirAll(folderpath, 0777) if err != nil { - fmt.Println("Already exists") + fmt.Printf("%s folder already exists.", folderpath) } db.View(func(tx *bolt.Tx) error { // Assume bucket exists and has keys @@ -627,7 +624,6 @@ func dumpEverything(folderpath string) { for k, _ := c.First(); k != nil; k, _ = c.Next() { var p WikiData p.load(string(k)) - fmt.Println(string(k), len(p.CurrentText)) if len(p.CurrentText) > 0 { ioutil.WriteFile(path.Join(folderpath, string(k)), []byte(p.CurrentText), 0644) } diff --git a/utils.go b/utils.go index b48a74f..b921119 100644 --- a/utils.go +++ b/utils.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/jcelliott/lumber" "github.com/sergi/go-diff/diffmatchpatch" ) @@ -23,12 +24,15 @@ type versionsInfo struct { VersionNum int } +var logger *lumber.ConsoleLogger + func init() { rand.Seed(time.Now().Unix()) animalsText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/animals")) animals = strings.Split(string(animalsText), ",") adjectivesText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/adjectives")) adjectives = strings.Split(string(adjectivesText), "\n") + logger = lumber.NewConsoleLogger(lumber.INFO) } func randomAnimal() string { @@ -225,7 +229,7 @@ func GetLocalIP() string { for _, address := range addrs { // check the address type and if it is not a loopback the display it if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { - if ipnet.IP.To4() != nil && (strings.Contains(ipnet.IP.String(), "192.168.1") || strings.Contains(ipnet.IP.String(), "192.168")) { + if ipnet.IP.To4() != nil { return ipnet.IP.String() } }