-
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.
added controllers but stuck on the read all command, kinda sucks; research karke dekht akuch
- Loading branch information
Showing
10 changed files
with
167 additions
and
0 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
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,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 | ||
} | ||
] | ||
} |
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,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 | ||
|
||
} | ||
|
||
} | ||
} | ||
} |
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,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 | ||
} | ||
] | ||
} |
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 cattodb | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
go 1.18 | ||
|
||
use ( | ||
. | ||
./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
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")) | ||
} |
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,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 | ||
} |
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 purr | ||
|
||
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 |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
} | ||
} |