Skip to content

Commit

Permalink
feat: Add Init function to local-storage.go (develop)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Dec 8, 2023
1 parent 4ebe866 commit eaf724a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/config/const.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package config

const LocalNotePath = "data/notes/"
const AppDataPath = "data/vortexnotes/"
const AppDbPath = AppDataPath + "app.db"
const IndexPath = AppDataPath + "notes.bleve"
import "os"

var basePath, _ = os.Getwd()
var LocalNotePath = basePath + "/data/notes/"
var AppDataPath = basePath + "/data/vortexnotes/"
var AppDbPath = AppDataPath + "app.db"
var IndexPath = AppDataPath + "notes.bleve"

const ApiHost = "0.0.0.0"
const ApiPort = "7701"
1 change: 1 addition & 0 deletions backend/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func ListNotes() []string {
}

func NoteExist(path string) bool {
logger.Logger.Println("NoteExist", path)
fileInfo, err := os.Stat(path)
if err != nil {
return false
Expand Down
6 changes: 6 additions & 0 deletions backend/storages/local-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"vortexnotes/backend/config"
"vortexnotes/backend/logger"
)

Expand Down Expand Up @@ -60,6 +61,11 @@ func ListTextFiles(dirPath string) (error, []string) {
return nil, textFiles
}

func Init() {
_ = CreateDirectoryIfNotExists(config.LocalNotePath)
_ = CreateDirectoryIfNotExists(config.AppDataPath)
}

func CreateDirectoryIfNotExists(dirPath string) error {
_, err := os.Stat(dirPath)
if os.IsNotExist(err) {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"vortexnotes/backend/api"
"vortexnotes/backend/database"
"vortexnotes/backend/indexer"
"vortexnotes/backend/storages"
)

func main() {
storages.Init()
database.Init()
indexer.Start()
api.Start()
Expand Down

0 comments on commit eaf724a

Please sign in to comment.