-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
57 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module cattobrain | ||
|
||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module errorhandle | ||
|
||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,8 @@ go 1.18 | |
|
||
use ( | ||
. | ||
./cattobrain | ||
./errorhandle | ||
|
||
./purr | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |