Skip to content

Commit

Permalink
golint
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Jun 9, 2017
1 parent 43c3cc6 commit 9fd334d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions samples/tutorials/go/crud.go
Expand Up @@ -37,7 +37,7 @@ func ReadEmployees(db *sql.DB) (int, error) {
return -1, err
}
defer rows.Close()
var count int = 0
count := 0
for rows.Next() {
var name, location string
var id int
Expand Down Expand Up @@ -87,11 +87,11 @@ func main() {
defer conn.Close()

// Create employee
createId, err := CreateEmployee(conn, "Jake", "United States")
createID, err := CreateEmployee(conn, "Jake", "United States")
if err != nil {
log.Fatal("CreateEmployee failed:", err.Error())
}
fmt.Printf("Inserted ID: %d successfully.\n", createId)
fmt.Printf("Inserted ID: %d successfully.\n", createID)

// Read employees
count, err := ReadEmployees(conn)
Expand All @@ -101,11 +101,11 @@ func main() {
fmt.Printf("Read %d rows successfully.\n", count)

// Update from database
updateId, err := UpdateEmployee(conn, "Jake", "Poland")
updateID, err := UpdateEmployee(conn, "Jake", "Poland")
if err != nil {
log.Fatal("UpdateEmployee failed:", err.Error())
}
fmt.Printf("Updated row with ID: %d successfully.\n", updateId)
fmt.Printf("Updated row with ID: %d successfully.\n", updateID)

// Delete from database
rows, err := DeleteEmployee(conn, "Jake")
Expand Down
15 changes: 10 additions & 5 deletions samples/tutorials/go/orm.go
Expand Up @@ -15,12 +15,14 @@ var (
database = "SampleDB"
)

// User represents a user account
type User struct {
gorm.Model
FirstName string
LastName string
}

// Task represents a task for the user
type Task struct {
gorm.Model
Title string
Expand All @@ -29,6 +31,7 @@ type Task struct {
UserID uint
}

// ReadAllTasks read all tasks
func ReadAllTasks(db *gorm.DB) {
var users []User
var tasks []Task
Expand All @@ -44,16 +47,18 @@ func ReadAllTasks(db *gorm.DB) {
}
}

func UpdateSomeonesTask(db *gorm.DB, userId int) {
// UpdateSomeonesTask update someone's task
func UpdateSomeonesTask(db *gorm.DB, userID int) {
var task Task
db.Where("user_id = ?", userId).First(&task).Update("Title", "Buy donuts for Luis")
db.Where("user_id = ?", userID).First(&task).Update("Title", "Buy donuts for Luis")
fmt.Printf("Title: %s\nDueDate: %s\nIsComplete:%t\n\n",
task.Title, task.DueDate, task.IsComplete)
}

func DeleteSomeonesTasks(db *gorm.DB, userId int) {
db.Where("user_id = ?", userId).Delete(&Task{})
fmt.Printf("Deleted all tasks for user %d", userId)
// DeleteSomeonesTasks delete someone's task
func DeleteSomeonesTasks(db *gorm.DB, userID int) {
db.Where("user_id = ?", userID).Delete(&Task{})
fmt.Printf("Deleted all tasks for user %d", userID)
}

func main() {
Expand Down

0 comments on commit 9fd334d

Please sign in to comment.