about summary refs log tree commit diff
path: root/src/arch.go
blob: 52dc516aa3a132ba08a7283006814509e6747206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

type Arch struct {
	ID      int
	Name    string
	Enabled bool
}

//////////////////////////////////////////////////////////////////////////////
// GENERAL PURPOSE

func ArchGetAll() ([]Arch, error) {
	return globalState.GetAllArchs()
}

//////////////////////////////////////////////////////////////////////////////
// DATABASE

func (s *State) GetAllArchs() ([]Arch, error) {
	rows, err := s.db.Query("SELECT id, name FROM archs")
	defer rows.Close()
	if err != nil {
		return nil, err
	}

	var archs []Arch
	for rows.Next() {
		var arch Arch
		if err := rows.Scan(&arch.ID, &arch.Name); err != nil {
			return archs, err
		}
		archs = append(archs, arch)
	}
	if err = rows.Err(); err != nil {
		return archs, err
	}
	return archs, nil
}

//////////////////////////////////////////////////////////////////////////////
// HTTP