Skip to content

Commit

Permalink
hw 2 done
Browse files Browse the repository at this point in the history
  • Loading branch information
Олег Владимирович Евдокимов committed Dec 21, 2023
1 parent 8459edf commit 53106cf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
4 changes: 1 addition & 3 deletions hw02_fix_app/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/fixme_my_friend/hw02_fix_app
module github.com/es-x/go_basic/hw02_fix_app

go 1.20

require golang.org/x/example v0.0.0-20230714141244-83a29069fa80 // indirect
2 changes: 0 additions & 2 deletions hw02_fix_app/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
golang.org/x/example v0.0.0-20230714141244-83a29069fa80 h1:dIO+42L/3wms+HG8CICCnwjAoQ9K7FD3JodZPpG5ymY=
golang.org/x/example v0.0.0-20230714141244-83a29069fa80/go.mod h1:DJ5Pz7jIW3ezl8PmYmOf5B1CZ98NJv/GaEcafLB3Lzk=
16 changes: 8 additions & 8 deletions hw02_fix_app/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package init
package main

import (
"github.com/fixme_my_friend/hw02_fix_app/printer"
"github.com/fixme_my_friend/hw02_fix_app/reader"
"github.com/fixme_my_friend/hw02_fix_app/types"
"fmt"

"github.com/es-x/go_basic/hw02_fix_app/printer"
"github.com/es-x/go_basic/hw02_fix_app/reader"
"github.com/es-x/go_basic/hw02_fix_app/types"
)

func init() {
var path string = "data.json"
func main() {
var path string

fmt.Printf("Enter data file path: ")
fmt.Scanln(&path)
Expand All @@ -18,10 +19,9 @@ func init() {

if len(path) == 0 {
path = "data.json"
} else {
}

staff, err = reader.ReadJSON(path, -1)
staff, err = reader.ReadJSON(path)

fmt.Print(err)

Expand Down
11 changes: 8 additions & 3 deletions hw02_fix_app/printer/pkg.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package printer

import (
"github.com/fixme_my_friend/hw02_fix_app/types"
"fmt"

"github.com/es-x/go_basic/hw02_fix_app/types"
)

func PrintStaff(staff types.Employee) {
func PrintStaff(staff []types.Employee) {
var str string
for i := 0; i < len(staff); i++ {
str := fmt.Sprintf("User ID: %d; Age: %d; Name: %s; Department ID: %d; ", staff[i].UserID, staff[i].Age, staff[i].Name, staff[i].DepartmentID)
str := fmt.Sprintf(

Check failure on line 12 in hw02_fix_app/printer/pkg.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "str" shadows declaration at line 10 (govet)
"User ID: %d; Age: %d; Name: %s; Department ID: %d; ",
staff[i].UserID, staff[i].Age, staff[i].Name, staff[i].DepartmentID,
)
fmt.Println(str)
}

Expand Down
17 changes: 9 additions & 8 deletions hw02_fix_app/reader/pkg.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package reader

import "encoding/json"
import "fmt"
import "io"
import "os"
import (
"encoding/json"
"fmt"
"io"
"os"

import "github.com/fixme_my_friend/hw02_fix_app/types"
"github.com/es-x/go_basic/hw02_fix_app/types"
)


func ReadJSON(filePath string, limit int) ([]types.Employee, error) {
func ReadJSON(filePath string) ([]types.Employee, error) {
f, err := os.Open(filePath)
if err != nil {
fmt.Printf("Error: %v", err)
}

byte, err := io.ReadAll(f)
bytes, err := io.ReadAll(f)
if err != nil {
fmt.Printf("Error: %v", err)
return nil, nil
Expand Down
6 changes: 3 additions & 3 deletions hw02_fix_app/types/employee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package types
import "fmt"

type Employee struct {
UserID int `json:"user_id"`
UserID int `json:"userId"`
Age int `json:"age"`
Name string `json:"name"`
DepartmentID int `json:"department_id"`
DepartmentID int `json:"departmentId"`
}

func (e Employee) String() string {
return fmt.Sprintf("User ID: %d; Age: %d; Name: %s; Department ID: %d; ", e.UserID, e.Age, e.FirstName, e.DepartmentID)
return fmt.Sprintf("User ID: %d; Age: %d; Name: %s; Department ID: %d; ", e.UserID, e.Age, e.Name, e.DepartmentID)
}

0 comments on commit 53106cf

Please sign in to comment.