1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
Former-commit-id: ab33ec4b9e7bae76ca4cc595b5f592ce270e82da [formerly ce5634e48d51105387d3e26507b7defc9054a28b] [formerly d84debd3176eb769221034f5e01aadc0ab70fc42 [formerly 6a6b53ca0a]]
Former-commit-id: baf9031e3fc929802c670c7352d6ba5b104dfeee [formerly 6c3b7c7c0e666e8fac5890e569db8a7ca9929b05]
Former-commit-id: 50d2a8dc179e0f705a21f03283cefcf0ad82f2f0
This commit is contained in:
Zack Scholl 2016-02-10 09:13:21 -05:00
parent 1bb73acaa8
commit 3669e8809b
6 changed files with 28 additions and 28 deletions

24
db.go
View File

@ -33,8 +33,8 @@ func Close() {
db.Close()
}
// CowyoData is data for storing in DB
type CowyoData struct {
// WikiData is data for storing in DB
type WikiData struct {
Title string
CurrentText string
Diffs []string
@ -58,7 +58,7 @@ func hasPassword(title string) (bool, error) {
if val == nil {
return nil
}
var p CowyoData
var p WikiData
err = p.decode(val)
if err != nil {
return err
@ -71,7 +71,7 @@ func hasPassword(title string) (bool, error) {
return nil
})
if err != nil {
fmt.Printf("Could not get CowyoData: %s", err)
fmt.Printf("Could not get WikiData: %s", err)
return false, err
}
return hasPassword, nil
@ -96,7 +96,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
if val == nil {
return nil
}
var p CowyoData
var p WikiData
err = p.decode(val)
if err != nil {
return err
@ -111,12 +111,12 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
return nil
})
if err != nil {
fmt.Printf("Could not get CowyoData: %s", err)
fmt.Printf("Could not get WikiData: %s", err)
}
return currentText, vi, isCurrent
}
func (p *CowyoData) load(title string) error {
func (p *WikiData) load(title string) error {
title = strings.ToLower(title)
if !open {
return fmt.Errorf("db must be opened before loading!")
@ -144,13 +144,13 @@ func (p *CowyoData) load(title string) error {
return nil
})
if err != nil {
fmt.Printf("Could not get CowyoData: %s", err)
fmt.Printf("Could not get WikiData: %s", err)
return err
}
return nil
}
func (p *CowyoData) save(newText string) error {
func (p *WikiData) save(newText string) error {
if !open {
return fmt.Errorf("db must be opened before saving")
}
@ -168,7 +168,7 @@ func (p *CowyoData) save(newText string) error {
p.Diffs = append(p.Diffs, delta)
enc, err := p.encode()
if err != nil {
return fmt.Errorf("could not encode CowyoData: %s", err)
return fmt.Errorf("could not encode WikiData: %s", err)
}
err = bucket.Put([]byte(p.Title), enc)
return err
@ -176,7 +176,7 @@ func (p *CowyoData) save(newText string) error {
return err
}
func (p *CowyoData) encode() ([]byte, error) {
func (p *WikiData) encode() ([]byte, error) {
enc, err := json.Marshal(p)
if err != nil {
return nil, err
@ -184,7 +184,7 @@ func (p *CowyoData) encode() ([]byte, error) {
return enc, nil
}
func (p *CowyoData) decode(data []byte) error {
func (p *WikiData) decode(data []byte) error {
err := json.Unmarshal(data, &p)
if err != nil {
return err

16
main.go
View File

@ -11,7 +11,7 @@ import (
)
// AllowedIPs is a white/black list of
// IP addresses allowed to access cowyo
// IP addresses allowed to access awwkoala
var AllowedIPs = map[string]bool{
"192.168.1.13": true,
"192.168.1.12": true,
@ -39,13 +39,13 @@ func main() {
flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt")
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
flag.CommandLine.Usage = func() {
fmt.Println(`cowyo: a websocket notepad
fmt.Println(`awwkoala: a websocket notepad
run this to start the server and then visit localhost at the port you specify
(see parameters).
Example: 'cowyo localhost'
Example: 'cowyo -p :8080 localhost'
Example: 'cowyo -db /var/lib/cowyo/db.bolt localhost'
Example: 'cowyo -p :8080 -crt ssl/server.crt -key ssl/server.key localhost'
Example: 'awwkoala localhost'
Example: 'awwkoala -p :8080 localhost'
Example: 'awwkoala -db /var/lib/awwkoala/db.bolt localhost'
Example: 'awwkoala -p :8080 -crt ssl/server.crt -key ssl/server.key localhost'
Options:`)
flag.CommandLine.PrintDefaults()
}
@ -59,10 +59,10 @@ Options:`)
defer Close()
// Default page
p := CowyoData{"about", about_page, []string{}, []string{}}
p := WikiData{"about", about_page, []string{}, []string{}}
p.save(about_page)
var q CowyoData
var q WikiData
q.load("SpikySeaSlug2")
fmt.Println(getImportantVersions(q))

View File

@ -165,7 +165,7 @@ func renderList(c *gin.Context, title string) {
if strings.ToLower(title) == "about" { //}&& strings.Contains(AllowedIPs, c.ClientIP()) != true {
c.Redirect(302, "/about/view")
}
var p CowyoData
var p WikiData
err := p.load(strings.ToLower(title))
if err != nil {
panic(err)
@ -183,7 +183,7 @@ func deleteListItem(c *gin.Context) {
lineNum, err := strconv.Atoi(c.DefaultQuery("lineNum", "None"))
title := c.Query("title") // shortcut for c.Request.URL.Query().Get("lastname")
if err == nil {
var p CowyoData
var p WikiData
err := p.load(strings.ToLower(title))
if err != nil {
panic(err)
@ -225,7 +225,7 @@ func listEverything() string {
b := tx.Bucket([]byte("datas"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var p CowyoData
var p WikiData
p.load(string(k))
if len(p.CurrentText) > 1 {
contentSize := strconv.Itoa(len(p.CurrentText))

View File

@ -55,7 +55,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Cowyo</a>
<a class="navbar-brand" href="/">Wiki</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">

File diff suppressed because one or more lines are too long

View File

@ -40,7 +40,7 @@ func wshandler(w http.ResponseWriter, r *http.Request) {
panic(err)
}
var p CowyoData
var p WikiData
err = p.load(strings.ToLower(m.Title))
if err != nil {
panic(err)