Skip to content

Commit 9fd334d

Browse files
committed
golint
1 parent 43c3cc6 commit 9fd334d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

samples/tutorials/go/crud.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ReadEmployees(db *sql.DB) (int, error) {
3737
return -1, err
3838
}
3939
defer rows.Close()
40-
var count int = 0
40+
count := 0
4141
for rows.Next() {
4242
var name, location string
4343
var id int
@@ -87,11 +87,11 @@ func main() {
8787
defer conn.Close()
8888

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

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

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

110110
// Delete from database
111111
rows, err := DeleteEmployee(conn, "Jake")

samples/tutorials/go/orm.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ var (
1515
database = "SampleDB"
1616
)
1717

18+
// User represents a user account
1819
type User struct {
1920
gorm.Model
2021
FirstName string
2122
LastName string
2223
}
2324

25+
// Task represents a task for the user
2426
type Task struct {
2527
gorm.Model
2628
Title string
@@ -29,6 +31,7 @@ type Task struct {
2931
UserID uint
3032
}
3133

34+
// ReadAllTasks read all tasks
3235
func ReadAllTasks(db *gorm.DB) {
3336
var users []User
3437
var tasks []Task
@@ -44,16 +47,18 @@ func ReadAllTasks(db *gorm.DB) {
4447
}
4548
}
4649

47-
func UpdateSomeonesTask(db *gorm.DB, userId int) {
50+
// UpdateSomeonesTask update someone's task
51+
func UpdateSomeonesTask(db *gorm.DB, userID int) {
4852
var task Task
49-
db.Where("user_id = ?", userId).First(&task).Update("Title", "Buy donuts for Luis")
53+
db.Where("user_id = ?", userID).First(&task).Update("Title", "Buy donuts for Luis")
5054
fmt.Printf("Title: %s\nDueDate: %s\nIsComplete:%t\n\n",
5155
task.Title, task.DueDate, task.IsComplete)
5256
}
5357

54-
func DeleteSomeonesTasks(db *gorm.DB, userId int) {
55-
db.Where("user_id = ?", userId).Delete(&Task{})
56-
fmt.Printf("Deleted all tasks for user %d", userId)
58+
// DeleteSomeonesTasks delete someone's task
59+
func DeleteSomeonesTasks(db *gorm.DB, userID int) {
60+
db.Where("user_id = ?", userID).Delete(&Task{})
61+
fmt.Printf("Deleted all tasks for user %d", userID)
5762
}
5863

5964
func main() {

0 commit comments

Comments
 (0)