package slowtwitch import ( "database/sql" "fmt" "sort" ) type SlowtwitchCategory struct { Id int Name string FullName string FatherId int CatDepth int NumberOfLinks int } func GetCategories(db *sql.DB) []SlowtwitchCategory { rows, err := db.Query("select ID, Name, Full_Name, FatherID, CatDepth, Number_of_Links from glinks_Category where Number_of_Links > 0;") if err != nil { fmt.Println(err) } defer rows.Close() var categories []SlowtwitchCategory for rows.Next() { category := SlowtwitchCategory{} err := rows.Scan(&category.Id, &category.Name, &category.FullName, &category.FatherId, &category.CatDepth, &category.NumberOfLinks) if err != nil { fmt.Println(err) } categories = append(categories, category) } sort.Slice(categories, func(i, j int) bool { return categories[i].CatDepth < categories[j].CatDepth }) return categories }