tile38/controller/readonly.go

41 lines
705 B
Go
Raw Normal View History

2016-03-05 02:08:16 +03:00
package controller
import (
"strings"
2016-03-06 17:55:00 +03:00
"github.com/tidwall/tile38/controller/log"
2016-03-05 02:08:16 +03:00
)
func (c *Controller) cmdReadOnly(line string) error {
var arg string
if line, arg = token(line); arg == "" {
return errInvalidNumberOfArguments
}
if line != "" {
return errInvalidNumberOfArguments
}
backup := c.config
switch strings.ToLower(arg) {
default:
return errInvalidArgument(arg)
case "yes":
if c.config.ReadOnly {
return nil
}
c.config.ReadOnly = true
log.Info("read only")
case "no":
if !c.config.ReadOnly {
return nil
}
c.config.ReadOnly = false
log.Info("read write")
}
2016-03-08 03:37:39 +03:00
err := c.writeConfig(false)
2016-03-05 02:08:16 +03:00
if err != nil {
c.config = backup
return err
}
return nil
}