Implement old storage.Path API

This commit is contained in:
Ken-Håvard Lieng 2020-04-20 03:02:15 +02:00
parent 164e071e7f
commit 360bed00f9
11 changed files with 44 additions and 39 deletions

View file

@ -13,14 +13,14 @@ var clearCmd = &cobra.Command{
Use: "clear",
Short: "Clear all user data",
Run: func(cmd *cobra.Command, args []string) {
err := os.Remove(storage.DataPath.Database())
err := os.Remove(storage.Path.Database())
if err == nil || os.IsNotExist(err) {
log.Println("Database cleared")
} else {
log.Println(err)
}
err = os.RemoveAll(storage.DataPath.Users())
err = os.RemoveAll(storage.Path.Users())
if err == nil {
log.Println("User data cleared")
} else {

View file

@ -16,7 +16,7 @@ var (
Short: "Edit config file",
Run: func(cmd *cobra.Command, args []string) {
if editor := findEditor(); editor != "" {
process := exec.Command(editor, storage.ConfigPath.Config())
process := exec.Command(editor, storage.Path.Config())
process.Stdin = os.Stdin
process.Stdout = os.Stdout
process.Stderr = os.Stderr

View file

@ -46,18 +46,18 @@ var rootCmd = &cobra.Command{
fmt.Printf(logo, version.Tag, version.Commit, version.Date, runtime.Version())
}
storage.Initialize()
storage.Initialize(viper.GetString("dir"), viper.GetString("data"), viper.GetString("conf"))
initConfig(storage.ConfigPath.Config(), viper.GetBool("reset-config"))
initConfig(storage.Path.Config(), viper.GetBool("reset-config"))
},
Run: func(cmd *cobra.Command, args []string) {
if viper.GetBool("dev") {
log.Println("Running in development mode, access client at http://localhost:3000")
}
log.Println("Storing data at", storage.DataPath.Root())
log.Println("Storing data at", storage.Path.DataRoot())
db, err := boltdb.New(storage.DataPath.Database())
db, err := boltdb.New(storage.Path.Database())
if err != nil {
log.Fatal(err)
}
@ -77,11 +77,11 @@ var rootCmd = &cobra.Command{
dispatch.SessionStore = db
dispatch.GetMessageStore = func(user *storage.User) (storage.MessageStore, error) {
return boltdb.New(storage.DataPath.Log(user.Username))
return boltdb.New(storage.Path.Log(user.Username))
}
dispatch.GetMessageSearchProvider = func(user *storage.User) (storage.MessageSearchProvider, error) {
return bleve.New(storage.DataPath.Index(user.Username))
return bleve.New(storage.Path.Index(user.Username))
}
dispatch.Run()