WIP students list
This commit is contained in:
parent
7d681aa95a
commit
e927de80d0
@ -9,7 +9,10 @@ import (
|
||||
|
||||
func main() {
|
||||
var staticDir string
|
||||
var studentsFile string
|
||||
|
||||
var bind = flag.String("bind", ":8081", "Bind port/socket")
|
||||
flag.StringVar(&studentsFile, "students", "./students.csv", "Path to a CSV file containing students list")
|
||||
flag.StringVar(&staticDir, "static", "./static/", "Directory containing static files")
|
||||
flag.StringVar(&ARPTable, "arp", ARPTable, "Path to ARP table")
|
||||
//var tftpdLogs = flag.String("tftpd", "/var/logs/tftpd.log", "Path to TFTPd logs")
|
||||
@ -23,6 +26,12 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var students []Student
|
||||
students, err = readStudentsList(studentsFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Registering handlers...")
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", Index)
|
||||
|
43
validator/students.go
Normal file
43
validator/students.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Student struct {
|
||||
Lastname string
|
||||
Firstname string
|
||||
Login string
|
||||
EMail string
|
||||
Phone string
|
||||
}
|
||||
|
||||
func readStudentsList(studentsFile string) (stds []Student, err error) {
|
||||
if studentsFile, err = filepath.Abs(studentsFile); err != nil {
|
||||
return
|
||||
} else if fi, err := os.Open(studentsFile); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
r := csv.NewReader(bufio.NewReader(fi))
|
||||
if list, err := r.ReadAll(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, i := range list {
|
||||
var s Student
|
||||
|
||||
s.Lastname = i[0]
|
||||
s.Firstname = i[1]
|
||||
s.Login = i[2]
|
||||
s.EMail = i[3]
|
||||
s.Phone = i[4]
|
||||
|
||||
stds = append(stds, s)
|
||||
}
|
||||
|
||||
return stds, nil
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user