First attempt at splitting the Go code into seperate files to clean things up.
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
type Category struct {
|
||||
Id int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Subcategory struct {
|
||||
Id int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CategoryId int32 `json:"categoryId"`
|
||||
}
|
||||
|
||||
func getAllCategories() []Category {
|
||||
db := getSQLConnection()
|
||||
|
||||
defer db.Close()
|
||||
|
||||
rows, err := db.Query("SELECT * FROM category;")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var categories []Category
|
||||
|
||||
for rows.Next() {
|
||||
var category Category
|
||||
|
||||
if err = rows.Scan(&category.Id, &category.Name); err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
|
||||
categories = append(categories, category)
|
||||
}
|
||||
|
||||
return categories
|
||||
}
|
||||
Reference in New Issue
Block a user