Can pass multiple students files (concatenate them)
This commit is contained in:
parent
e9cc2e1331
commit
e486ad0c1b
36
main.go
36
main.go
@ -205,11 +205,22 @@ func ServeJSONStudent(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type arrayFlags []string
|
||||||
|
|
||||||
|
func (i *arrayFlags) String() string {
|
||||||
|
return fmt.Sprintf("%v", *i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *arrayFlags) Set(value string) error {
|
||||||
|
*i = append(*i, value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var studentsFile string
|
var studentsFiles arrayFlags
|
||||||
|
|
||||||
var bind = flag.String("bind", "0.0.0.0:8081", "Bind port/socket")
|
var bind = flag.String("bind", "0.0.0.0:8081", "Bind port/socket")
|
||||||
flag.StringVar(&studentsFile, "students", "./students.csv", "Path to a CSV file containing in the third column the name of the directory to look for")
|
flag.Var(&studentsFiles, "students", "Path to a CSV file containing in the third column the name of the directory to look for (can be repeated multiple times)")
|
||||||
flag.StringVar(&rendusDir, "path", "./rendu/", "Path to the submissions directory (each subdirectory is a project)")
|
flag.StringVar(&rendusDir, "path", "./rendu/", "Path to the submissions directory (each subdirectory is a project)")
|
||||||
flag.StringVar(&title, "title", "Rendus VIRLI", "Title of the page")
|
flag.StringVar(&title, "title", "Rendus VIRLI", "Title of the page")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -234,14 +245,21 @@ func main() {
|
|||||||
|
|
||||||
// Read and parse students list
|
// Read and parse students list
|
||||||
log.Println("Reading students files...")
|
log.Println("Reading students files...")
|
||||||
if studentsFile, err = filepath.Abs(studentsFile); err != nil {
|
for _, studentsFile := range studentsFiles {
|
||||||
log.Fatal(err)
|
log.Println("Reading", studentsFile, "...")
|
||||||
} else if fi, err := os.Open(studentsFile); err != nil {
|
if studentsFile, err = filepath.Abs(studentsFile); err != nil {
|
||||||
log.Fatal(err)
|
|
||||||
} else {
|
|
||||||
r := csv.NewReader(bufio.NewReader(fi))
|
|
||||||
if students, err = r.ReadAll(); err != nil {
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
} else if fi, err := os.Open(studentsFile); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
var nstudents [][]string
|
||||||
|
|
||||||
|
r := csv.NewReader(bufio.NewReader(fi))
|
||||||
|
if nstudents, err = r.ReadAll(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
students = append(students, nstudents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println(len(students), "students loaded.")
|
log.Println(len(students), "students loaded.")
|
||||||
|
Reference in New Issue
Block a user