package client import ( "time" ) type Model struct { ID string IsCreated bool IsDeleted bool IsUpdated bool LatestUpdatedTime *time.Time } func modelFromMap(m map[string]interface{}) *Model { createdAtStr := ToString(m["created_at"]) updatedAtStr := ToString(m["updated_at"]) deletedAtStr := ToString(m["deleted_at"]) updatedAt, _ := ToTime(updatedAtStr) isCreated := false isUpdated := false isDeleted := false if createdAtStr == updatedAtStr { isCreated = true } else if deletedAtStr != "" { isDeleted = true } else { isUpdated = true } return &Model{ID: ToString(m["id"]), LatestUpdatedTime: updatedAt, IsCreated: isCreated, IsUpdated: isUpdated, IsDeleted: isDeleted} } type Product struct { Model Name string Color string } func ProductFromMap(m map[string]interface{}) *Product { return &Product{Model: *modelFromMap(m), Name: ToString(m["name"]), Color: ToString(m["color"])} }