Skip to content

Commit

Permalink
i have added some stuff
Browse files Browse the repository at this point in the history
added controllers but stuck on the read all command, kinda sucks;  research karke dekht akuch
  • Loading branch information
g4ze committed Jun 12, 2023
1 parent 18079a2 commit cd9b4e7
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ Command | Functionality
-catto-snatchfrom-{id} OR catto-read-{id} | GETs you the id element❌
-catto-snatch-{object}-from-{id} OR catto-read-{object}-from-{id} | GETs you data of an object with ID❌
-catto-snatch-all OR catto-get-all | GETs you everything❌
-catto-paw-{name} OR catto-make-{name} | Makes a new JSON file with "NAME" and "ID"❌



23 changes: 23 additions & 0 deletions ajsonfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"FirstName": "Mark",
"LastName": "Jones",
"Email": "[email protected]",
"Age": 25,
"MonthlySalary": [
{
"Basic": 15000,
"HRA": 5000,
"TA": 2000
},
{
"Basic": 16000,
"HRA": 5000,
"TA": 2100
},
{
"Basic": 17000,
"HRA": 5000,
"TA": 2200
}
]
}
29 changes: 29 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package controller

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

func controller(command string, filep string) (a purr.Employee) {
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

}

}
}
}
23 changes: 23 additions & 0 deletions filename.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"FirstName": "Mark",
"LastName": "Jones",
"Email": "[email protected]",
"Age": 25,
"MonthlySalary": [
{
"Basic": 15000,
"HRA": 5000,
"TA": 2000
},
{
"Basic": 16000,
"HRA": 5000,
"TA": 2100
},
{
"Basic": 17000,
"HRA": 5000,
"TA": 2200
}
]
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module cattodb

go 1.18
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
./purr
)
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"fmt"
"purr"
)

func main() {
fmt.Println("welcome to cattoDB")
// fmt.Println(purr.Data)
fmt.Println(purr.ReadOne("ajsonfile" + ".json"))
}
27 changes: 27 additions & 0 deletions purr/basicops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package purr

import (
"encoding/json"
"io/ioutil"
"log"
"os"
)

func WriteOne(filepath string, data Employee) {
file, _ := json.MarshalIndent(data, "", " ")
_ = ioutil.WriteFile(filepath, file, 0644)

}
func DeleteOne(filepath string) {
e := os.Remove(filepath)
if e != nil {
log.Fatal(e)
}
}
func ReadOne(filepath string) (a Employee) {
file, _ := ioutil.ReadFile(filepath)
var datatype Employee

_ = json.Unmarshal([]byte(file), &datatype)
return datatype
}
3 changes: 3 additions & 0 deletions purr/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module purr

go 1.18
39 changes: 39 additions & 0 deletions purr/tester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package purr

type Salary struct {
Basic, HRA, TA float64
}

type Employee struct {
FirstName, LastName, Email string
Age int
MonthlySalary []Salary
}

var Data Employee

func init() {
Data = Employee{
FirstName: "Mark",
LastName: "Jones",
Email: "[email protected]",
Age: 25,
MonthlySalary: []Salary{
Salary{
Basic: 15000.00,
HRA: 5000.00,
TA: 2000.00,
},
Salary{
Basic: 16000.00,
HRA: 5000.00,
TA: 2100.00,
},
Salary{
Basic: 17000.00,
HRA: 5000.00,
TA: 2200.00,
},
},
}
}

0 comments on commit cd9b4e7

Please sign in to comment.