mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-05-05 14:01:44 -05:00
9c9ea6dbb7
* Added WASM module for e2e * Added cmd util to read database * Changed to go 1.19 * Fixed crash with random string generator * Fixed typos and tests * Host service worker on github
52 lines
888 B
Go
52 lines
888 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/forceu/gokapi/internal/configuration/database"
|
|
"github.com/forceu/gokapi/internal/helper"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
if !correctArgs() {
|
|
showUsageAndExit()
|
|
return
|
|
}
|
|
path := os.Args[1]
|
|
database.Init(path)
|
|
metadata := database.GetAllMetadata()
|
|
for _, file := range metadata {
|
|
result, err := json.MarshalIndent(file, "", " ")
|
|
if err != nil {
|
|
log.Fatal("Error encoding file: ", err)
|
|
}
|
|
fmt.Println(string(result))
|
|
fmt.Println()
|
|
}
|
|
}
|
|
|
|
func correctArgs() bool {
|
|
if len(os.Args) < 2 {
|
|
return false
|
|
}
|
|
path := os.Args[1]
|
|
if path == "" {
|
|
return false
|
|
}
|
|
if !helper.FolderExists(path) {
|
|
fmt.Println("Error: Folder does not exist: " + path)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func showUsageAndExit() {
|
|
fmt.Println("Usage: ./databasereader /path/to/database")
|
|
osExit(1)
|
|
return
|
|
}
|
|
|
|
var osExit = os.Exit
|