Skip to content

Commit

Permalink
updated join for go with timing
Browse files Browse the repository at this point in the history
  • Loading branch information
czhou578 committed Jul 11, 2024
1 parent 392eb01 commit 9d11ec7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
26 changes: 17 additions & 9 deletions go-backend/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ type CombinedData struct {
operation_time map[string]int64 `json:"time"`

Check failure on line 40 in go-backend/api/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

structtag: struct field operation_time has json tag but is not exported (govet)
}

type CombinedDataCountId struct {
data []models.EmployeeId `json:"data"`

Check failure on line 44 in go-backend/api/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

structtag: struct field data has json tag but is not exported (govet)
operation_time map[string]int64 `json:"time"`

Check failure on line 45 in go-backend/api/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

structtag: struct field operation_time has json tag but is not exported (govet)
}

func (e *LockWaitTimeoutError) Error() string {
return e.Message
}

func getAllShippers(c *gin.Context) {
shippers, operation_time := models.GetShippers()
fmt.Println("Shippers, ", shippers)
fmt.Println("time, ", operation_time)

combined := CombinedData{
data: shippers,
Expand All @@ -58,20 +61,25 @@ func getAllShippers(c *gin.Context) {

fmt.Println("new", combined)

// c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
// c.Writer.WriteHeader(http.StatusOK)
c.Header("Content-Type", "text/plain; charset=utf-8")
c.String(200, shipperStrings)
// c.Data(http.StatusOK, "application/json", []byte(combined))

// c.IndentedJSON(http.StatusOK, combined)

}

func getEmployeeIDCount(c *gin.Context) {
countId := models.GetCountNumId()
countId, operation_time := models.GetCountNumId()

combined := CombinedDataCountId{
data: countId,
operation_time: operation_time,
}

countIdString := fmt.Sprintf("%v", combined)

c.IndentedJSON(http.StatusOK, countId)
fmt.Println("new", combined)

c.Header("Content-Type", "text/plain; charset=utf-8")
c.String(200, countIdString)
}

func newCategory(c *gin.Context) {
Expand Down
23 changes: 15 additions & 8 deletions go-backend/api/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"database/sql"
"fmt"
"log"
"time"
"math"
"time"

_ "github.com/go-sql-driver/mysql"
)
Expand Down Expand Up @@ -67,19 +67,21 @@ func GetShippers() ([]Shipper, map[string]int64) {
fmt.Println("test", shippers)

operation_time := time.Since(start).Milliseconds()
m := map[string]int64{
"Operation Time": operation_time,
}
m := map[string]int64{
"Operation Time": operation_time,
}

return shippers, m

}

func GetCountNumId() []EmployeeId {
func GetCountNumId() ([]EmployeeId, map[string]int64) {
start := time.Now()

db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)
if err != nil {
fmt.Println("error", err.Error())
return nil
return []EmployeeId{}, nil
}

defer db.Close()
Expand All @@ -88,7 +90,7 @@ func GetCountNumId() []EmployeeId {

if err != nil {
fmt.Println("error", err.Error())
return nil
return []EmployeeId{}, nil
}

countEmployees := []EmployeeId{}
Expand All @@ -106,7 +108,12 @@ func GetCountNumId() []EmployeeId {

}

return countEmployees
operation_time := time.Since(start).Milliseconds()
m := map[string]int64{
"Operation Time": operation_time,
}

return countEmployees, m

}

Expand Down

0 comments on commit 9d11ec7

Please sign in to comment.