Skip to content

Commit

Permalink
made a few changes
Browse files Browse the repository at this point in the history
taking a different approach, first im gin to build the whole project for a single type of command, doing that will get me a skeleton readt with a fully functional command. This would let me write the complete infrastructure for the DataBase and hence would help in writing and scaling harixontally of other functions.
  • Loading branch information
g4ze committed Jun 13, 2023
1 parent 45bbe28 commit 9d529f9
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 18 deletions.
5 changes: 5 additions & 0 deletions cattobrain/cattobrain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cattobrain

func meow() {
//we will have to input the command
}
3 changes: 3 additions & 0 deletions cattobrain/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module cattobrain

go 1.18
36 changes: 18 additions & 18 deletions controller/controller.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package controller

import (
"fmt"
"io/ioutil"
"path/filepath"
"errorhandle"
"purr"
)

func controller(command string, filep string) (a purr.Employee) {
func controller(command string, filep string) (purr.Employee, error) {
if command == "read" { //readingone
return purr.ReadOne(filep)
} else if command == "read-all" { //reading mutiple
files, err := ioutil.ReadDir(filep)
//got fie names just now
if err != nil {
fmt.Println("Error reading directory:", err)
return
} //iterating thru the file names
for _, file := range files {
if filepath.Ext(file.Name()) == ".json" {
path := filep + file.Name()
var fileslice purr.Employee
return purr.ReadOne(filep), nil
// } else if command == "read-all" { //reading mutiple
// files, err := ioutil.ReadDir(filep)
// //got fie names just now
// if err != nil {
// fmt.Println("Error reading directory:", err)
// return
// } //iterating thru the file names
// for _, file := range files {
// if filepath.Ext(file.Name()) == ".json" {
// path := filep + file.Name()
// var fileslice purr.Employee

}
// }

}
// }
// }
}
return purr.Employee{}, errorhandle.CustomError{Message: "invalid command meoww"}
}
9 changes: 9 additions & 0 deletions errorhandle/errorhandle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package errorhandle

type CustomError struct {
Message string
}

func (e CustomError) Error() string {
return e.Message
}
3 changes: 3 additions & 0 deletions errorhandle/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module errorhandle

go 1.18
3 changes: 3 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ go 1.18

use (
.
./cattobrain
./errorhandle

./purr
)
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ func main() {
fmt.Println("welcome to cattoDB")
// fmt.Println(purr.Data)
fmt.Println(purr.ReadOne("ajsonfile" + ".json"))

}
15 changes: 15 additions & 0 deletions parser/queryparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package parser

import "errorhandle"

func GetCommand(command string) (string, error) {
//this function will be parsing and breaking down the commands.
if command == "" {
return "", errorhandle.CustomError{Message: "no command found"}
}
if command[0:6] != "catto-" {
return "", errorhandle.CustomError{Message: "try using \"catto\" command and \"catto-help\" for more"}
}
command = command[6:]
return command, nil
}

0 comments on commit 9d529f9

Please sign in to comment.