work in progress
This commit is contained in:
parent
38f7c31517
commit
07ff5ccffb
23 changed files with 228 additions and 240 deletions
43
pkg/db/db.go
43
pkg/db/db.go
|
|
@ -3,28 +3,31 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"git.giftfish.de/ston1th/gowiki/cache"
|
||||
"fmt"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/cache"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/index"
|
||||
"github.com/boltdb/bolt"
|
||||
)
|
||||
|
||||
const (
|
||||
dbFile = "gowiki.db"
|
||||
defUser = "admin"
|
||||
defPassword = "gowiki"
|
||||
userTable = "user"
|
||||
pageTable = "page"
|
||||
bcryptCost = 13
|
||||
indexName = "Index"
|
||||
welcome = `# Welcome to GoWiki
|
||||
dbFile = "gowiki.db"
|
||||
defUser = "admin"
|
||||
defPassword = "gowiki"
|
||||
userTable = "user"
|
||||
pageTable = "page"
|
||||
snippetTable = "snippet"
|
||||
bcryptCost = 13
|
||||
indexName = "Index"
|
||||
welcome = `# Welcome to GoWiki
|
||||
This is the [Index](/wiki/Index) page.
|
||||
You can customize it how you like.`
|
||||
wikiSection = "wiki"
|
||||
)
|
||||
const (
|
||||
|
||||
/*const (
|
||||
maxResult = 1e6
|
||||
maxSearchResult = 101
|
||||
)
|
||||
)*/
|
||||
|
||||
func dbErr(i interface{}) error {
|
||||
return fmt.Errorf("db: %s", i)
|
||||
|
|
@ -34,9 +37,13 @@ type BoltStore struct {
|
|||
Marshaler
|
||||
db *bolt.DB
|
||||
cache *cache.Cache
|
||||
index *index.Index
|
||||
}
|
||||
|
||||
func NewBoltStore() (bs *BoltStore, err error) {
|
||||
// TODO create initial wiki page
|
||||
// TODO init index
|
||||
|
||||
func NewBoltStore(indexPath string) (bs *BoltStore, err error) {
|
||||
db, err := bolt.Open(dbFile, 0666, nil)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -52,8 +59,12 @@ func NewBoltStore() (bs *BoltStore, err error) {
|
|||
}); err != nil {
|
||||
return
|
||||
}
|
||||
bs = &BoltStore{NewGOB(), db, cache.NewCache()}
|
||||
if !bs.UserExists(defUser) {
|
||||
i, err := index.NewIndex(indexPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
bs = &BoltStore{NewGOB(), db, cache.NewCache(), i}
|
||||
if bs.UserExists(defUser) == nil {
|
||||
err = bs.CreateUser(defUser, defPassword, true)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue