Let's Encrypt
This commit is contained in:
parent
22892a4073
commit
b55cb13e44
82 changed files with 13536 additions and 107 deletions
48
storage/directory.go
Normal file
48
storage/directory.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
var Path directory
|
||||
|
||||
func SetDirectory(dir string) {
|
||||
Path = directory(dir)
|
||||
}
|
||||
|
||||
func DefaultDirectory() string {
|
||||
home, _ := homedir.Dir()
|
||||
return filepath.Join(home, ".dispatch")
|
||||
}
|
||||
|
||||
type directory string
|
||||
|
||||
func (d directory) Root() string {
|
||||
return string(d)
|
||||
}
|
||||
|
||||
func (d directory) LetsEncrypt() string {
|
||||
return filepath.Join(d.Root(), "letsencrypt")
|
||||
}
|
||||
|
||||
func (d directory) Logs() string {
|
||||
return filepath.Join(d.Root(), "logs")
|
||||
}
|
||||
|
||||
func (d directory) Log(userID string) string {
|
||||
return filepath.Join(d.Logs(), userID+".log")
|
||||
}
|
||||
|
||||
func (d directory) Index(userID string) string {
|
||||
return filepath.Join(d.Logs(), userID+".idx")
|
||||
}
|
||||
|
||||
func (d directory) Config() string {
|
||||
return filepath.Join(d.Root(), "config.toml")
|
||||
}
|
||||
|
||||
func (d directory) Database() string {
|
||||
return filepath.Join(d.Root(), "dispatch.db")
|
||||
}
|
|
@ -3,7 +3,6 @@ package storage
|
|||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/boltdb/bolt"
|
||||
)
|
||||
|
@ -18,15 +17,13 @@ var (
|
|||
bucketMessages = []byte("Messages")
|
||||
)
|
||||
|
||||
func Initialize(dir string) {
|
||||
func Initialize() {
|
||||
log.Println("Storing data at", Path.Root())
|
||||
|
||||
var err error
|
||||
appDir = dir
|
||||
|
||||
log.Println("Storing data at", dir)
|
||||
|
||||
db, err = bolt.Open(path.Join(dir, "data.db"), 0600, nil)
|
||||
db, err = bolt.Open(Path.Database(), 0600, nil)
|
||||
if err != nil {
|
||||
log.Fatal("Could not open database file")
|
||||
log.Fatal("Could not open database:", err)
|
||||
}
|
||||
|
||||
db.Update(func(tx *bolt.Tx) error {
|
||||
|
@ -42,7 +39,7 @@ func Close() {
|
|||
db.Close()
|
||||
}
|
||||
|
||||
func Clear(dir string) {
|
||||
os.RemoveAll(path.Join(dir, "logs"))
|
||||
os.Remove(path.Join(dir, "data.db"))
|
||||
func Clear() {
|
||||
os.RemoveAll(Path.Logs())
|
||||
os.Remove(Path.Database())
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -313,7 +312,7 @@ func (u *User) Close() {
|
|||
func (u *User) openMessageLog() {
|
||||
var err error
|
||||
|
||||
u.messageLog, err = bolt.Open(path.Join(appDir, "logs", u.UUID+"_log"), 0600, nil)
|
||||
u.messageLog, err = bolt.Open(Path.Log(u.UUID), 0600, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -324,7 +323,7 @@ func (u *User) openMessageLog() {
|
|||
return nil
|
||||
})
|
||||
|
||||
indexPath := path.Join(appDir, "logs", u.UUID+"_index")
|
||||
indexPath := Path.Index(u.UUID)
|
||||
u.messageIndex, err = bleve.Open(indexPath)
|
||||
if err == bleve.ErrorIndexPathDoesNotExist {
|
||||
mapping := bleve.NewIndexMapping()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue