mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added debug mode, Fix #55
This commit is contained in:
parent
c10c7b16e2
commit
f6ee202630
11
main.go
11
main.go
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
6
utils.go
6
utils.go
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user