First attempt at splitting the Go code into seperate files to clean things up.

This commit is contained in:
2021-09-08 22:51:00 -05:00
parent bb01c11859
commit 20a6365159
3 changed files with 66 additions and 62 deletions
+40
View File
@@ -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
}