Refactor environment sensor URL path generation
This commit is contained in:
parent
8015ed2be5
commit
7218177625
2 changed files with 28 additions and 9 deletions
20
util/util.go
Normal file
20
util/util.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetSensorURLPath generates the URL path for the given sensor details.
|
||||
// location and name may be optional depending on sensorType, see the schema definition for details.
|
||||
// The path is always all-lowercase.
|
||||
func GetSensorURLPath(sensorType, location, name string) string {
|
||||
path := fmt.Sprintf("/sensors/%s", sensorType)
|
||||
if location != "" {
|
||||
path += "/" + location
|
||||
}
|
||||
if name != "" {
|
||||
path += "/" + name
|
||||
}
|
||||
return strings.ToLower(path)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue