Use sliceUtils.ContainsString instead of stringInSlice.

This commit is contained in:
scruzin 2019-11-22 17:19:27 +10:30
parent 41945c9868
commit b4570f1aa1
1 changed files with 3 additions and 12 deletions

View File

@ -35,6 +35,7 @@ import (
"bitbucket.org/ausocean/av/device" "bitbucket.org/ausocean/av/device"
"bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/av/revid/config"
"bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/logger"
"bitbucket.org/ausocean/utils/sliceutils"
) )
// To indicate package when logging. // To indicate package when logging.
@ -180,12 +181,12 @@ func (r *Raspivid) Set(c config.Config) error {
c.Saturation = defaultRaspividSaturation c.Saturation = defaultRaspividSaturation
} }
if c.Exposure == "" || !stringInSlice(c.Exposure, ExposureModes[:]) { if c.Exposure == "" || !sliceutils.ContainsString(ExposureModes[:], c.Exposure) {
errs = append(errs, errBadExposure) errs = append(errs, errBadExposure)
c.Exposure = defaultRaspividExposure c.Exposure = defaultRaspividExposure
} }
if c.AutoWhiteBalance == "" || !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]) { if c.AutoWhiteBalance == "" || !sliceutils.ContainsString(AutoWhiteBalanceModes[:], c.AutoWhiteBalance) {
errs = append(errs, errBadAutoWhiteBalance) errs = append(errs, errBadAutoWhiteBalance)
c.AutoWhiteBalance = defaultRaspividAutoWhiteBalance c.AutoWhiteBalance = defaultRaspividAutoWhiteBalance
} }
@ -277,13 +278,3 @@ func (r *Raspivid) Stop() error {
} }
return r.out.Close() return r.out.Close()
} }
// stringInSlice returns true if want is in slice.
func stringInSlice(want string, slice []string) bool {
for _, s := range slice {
if s == want {
return true
}
}
return false
}