maatma: refactor IPs getter to include some other interesting information
This commit is contained in:
parent
0af3355576
commit
bd729c9f54
@ -8,7 +8,9 @@ import (
|
||||
|
||||
func init() {
|
||||
router.GET("/api/ips", apiHandler(showIPs))
|
||||
router.GET("/api/students/:sid/ips", apiHandler(studentHandler(showStudentIPs)))
|
||||
router.GET("/api/students/:sid/ips", apiHandler(studentHandler(func(student Student, body []byte) (interface{}, error) {
|
||||
return getStudentIPs(student), nil
|
||||
})))
|
||||
}
|
||||
|
||||
func (s Student) IPSuffix() int64 {
|
||||
@ -26,25 +28,26 @@ func showIPs(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
for _, std := range students {
|
||||
sid := fmt.Sprintf("%d", std.Id)
|
||||
|
||||
r[sid] = make(map[string]string)
|
||||
r[sid] = getStudentIPs(std)
|
||||
|
||||
if std.MAC == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
r[sid]["mac"] = *std.MAC
|
||||
r[sid]["vlan0"] = fmt.Sprintf("172.23.0.%d", std.IPSuffix())
|
||||
r[sid]["vlan7"] = fmt.Sprintf("172.23.142.%d", std.IPSuffix())
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func showStudentIPs(student Student, body []byte) (interface{}, error) {
|
||||
r := make(map[string]string)
|
||||
func getStudentIPs(student Student) (r map[string]string) {
|
||||
r = make(map[string]string)
|
||||
|
||||
r["vlan0"] = fmt.Sprintf("172.23.0.%d", student.IPSuffix())
|
||||
r["vlan7"] = fmt.Sprintf("172.23.142.%d", student.IPSuffix())
|
||||
r["wg"] = studentIP(student.Id)
|
||||
r["adn"] = student.myAssociatedDomain()
|
||||
r["ddn"] = student.MyDelegatedDomain()
|
||||
|
||||
return r, nil
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user