mirror of https://bitbucket.org/ausocean/av.git
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
|
/*
|
||
|
DESCRIPTION
|
||
|
utils.go houses generic vidforward utilities and helper functions.
|
||
|
|
||
|
AUTHORS
|
||
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
||
|
|
||
|
LICENSE
|
||
|
Copyright (C) 2022 the Australian Ocean Lab (AusOcean)
|
||
|
|
||
|
It is free software: you can redistribute it and/or modify them
|
||
|
under the terms of the GNU General Public License as published by the
|
||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||
|
option) any later version.
|
||
|
|
||
|
It is distributed in the hope that it will be useful, but WITHOUT
|
||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
|
for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||
|
*/
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
|
||
|
"bitbucket.org/ausocean/utils/logging"
|
||
|
)
|
||
|
|
||
|
// writeError logs an error and writes to w in JSON format.
|
||
|
func (m *broadcastManager) errorLogWrite(log logging.Logger, w http.ResponseWriter, msg string, args ...interface{}) {
|
||
|
log.Error(msg, args...)
|
||
|
w.Header().Add("Content-Type", "application/json")
|
||
|
fmt.Fprint(w, `{"er":"`+msg+`"}`)
|
||
|
}
|
||
|
|
||
|
// isMac returns true if the provided string is a valid mac address.
|
||
|
func isMac(m string) bool {
|
||
|
if len(m) != 17 || m == "00:00:00:00:00:00" {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
for i := 0; i <= 15; i++ {
|
||
|
if (i+1)%3 == 0 && m[i] != ':' {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
if (3-i)%3 != 0 {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
_, err := strconv.ParseUint(m[i:i+2], 16, 64)
|
||
|
if err != nil {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
return true
|
||
|
}
|