1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Added debug mode, Fix #55

Former-commit-id: f5d1d9dcc70c95c00f2a7d242a3f982e78539e57 [formerly def6a11c20d8c01fd87265d630007117ef4f02f2] [formerly 0015e78ce5c1aea4eb095391ae4e1398f9d5f353 [formerly f6ee202630]]
Former-commit-id: 81f38e3a512c6d8ed92350610964fc91b4cb4aa2 [formerly f7bf932204209270ed361f5a42706489be2cc8cb]
Former-commit-id: 07c9fee1d5b192b213f1d25e524ac01740ea58e5
This commit is contained in:
Zack Scholl 2016-09-09 15:39:45 -04:00
parent 14b820f0e4
commit c114a91bb6
3 changed files with 17 additions and 6 deletions

11
main.go
View File

@ -38,6 +38,7 @@ var RuntimeArgs struct {
ForceWss bool ForceWss bool
DumpDataset string DumpDataset string
RestoreDataset string RestoreDataset string
Debug bool
} }
var VersionNum string var VersionNum string
@ -56,6 +57,7 @@ func main() {
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key") flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key")
flag.StringVar(&RuntimeArgs.WikiName, "w", "cowyo", "custom name for wiki") 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.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.DumpDataset, "dump", "", "directory to dump all data to")
flag.StringVar(&RuntimeArgs.RestoreDataset, "restore", "", "directory to restore all data from") flag.StringVar(&RuntimeArgs.RestoreDataset, "restore", "", "directory to restore all data from")
flag.CommandLine.Usage = func() { flag.CommandLine.Usage = func() {
@ -76,6 +78,13 @@ Options:`)
} }
flag.Parse() flag.Parse()
// Set the log level
if RuntimeArgs.Debug == false {
logger.Level(2)
} else {
logger.Level(0)
}
if len(RuntimeArgs.DumpDataset) > 0 { if len(RuntimeArgs.DumpDataset) > 0 {
fmt.Println("Dumping data to '" + RuntimeArgs.DumpDataset + "' folder...") fmt.Println("Dumping data to '" + RuntimeArgs.DumpDataset + "' folder...")
dumpEverything(RuntimeArgs.DumpDataset) dumpEverything(RuntimeArgs.DumpDataset)
@ -84,7 +93,9 @@ Options:`)
RuntimeArgs.ExternalIP = flag.Arg(0) RuntimeArgs.ExternalIP = flag.Arg(0)
if RuntimeArgs.ExternalIP == "" { if RuntimeArgs.ExternalIP == "" {
logger.Debug("Getting external ip...")
RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port
logger.Debug("Using ip: %s and port %s", GetLocalIP(), RuntimeArgs.Port)
} }
RuntimeArgs.SourcePath = cwd RuntimeArgs.SourcePath = cwd

View File

@ -235,9 +235,6 @@ func getRecentlyEdited(title string, c *gin.Context) []string {
recentlyEdited = title recentlyEdited = title
} else { } else {
editedThings = strings.Split(v.(string), "|||") editedThings = strings.Split(v.(string), "|||")
fmt.Println(editedThings)
fmt.Println(v.(string))
fmt.Println(title)
if !stringInSlice(title, editedThings) { if !stringInSlice(title, editedThings) {
recentlyEdited = v.(string) + "|||" + title recentlyEdited = v.(string) + "|||" + title
} else { } else {
@ -618,7 +615,7 @@ func dumpEverything(folderpath string) {
defer Close() defer Close()
err := os.MkdirAll(folderpath, 0777) err := os.MkdirAll(folderpath, 0777)
if err != nil { if err != nil {
fmt.Println("Already exists") fmt.Printf("%s folder already exists.", folderpath)
} }
db.View(func(tx *bolt.Tx) error { db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys // Assume bucket exists and has keys
@ -627,7 +624,6 @@ func dumpEverything(folderpath string) {
for k, _ := c.First(); k != nil; k, _ = c.Next() { for k, _ := c.First(); k != nil; k, _ = c.Next() {
var p WikiData var p WikiData
p.load(string(k)) p.load(string(k))
fmt.Println(string(k), len(p.CurrentText))
if len(p.CurrentText) > 0 { if len(p.CurrentText) > 0 {
ioutil.WriteFile(path.Join(folderpath, string(k)), []byte(p.CurrentText), 0644) ioutil.WriteFile(path.Join(folderpath, string(k)), []byte(p.CurrentText), 0644)
} }

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/jcelliott/lumber"
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
) )
@ -23,12 +24,15 @@ type versionsInfo struct {
VersionNum int VersionNum int
} }
var logger *lumber.ConsoleLogger
func init() { func init() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
animalsText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/animals")) animalsText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/animals"))
animals = strings.Split(string(animalsText), ",") animals = strings.Split(string(animalsText), ",")
adjectivesText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/adjectives")) adjectivesText, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "static/text/adjectives"))
adjectives = strings.Split(string(adjectivesText), "\n") adjectives = strings.Split(string(adjectivesText), "\n")
logger = lumber.NewConsoleLogger(lumber.INFO)
} }
func randomAnimal() string { func randomAnimal() string {
@ -225,7 +229,7 @@ func GetLocalIP() string {
for _, address := range addrs { for _, address := range addrs {
// check the address type and if it is not a loopback the display it // 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, 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() return ipnet.IP.String()
} }
} }