Port most of the HTTP code over to gin
This commit is contained in:
12
server/power.go
Normal file
12
server/power.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package server
|
||||
|
||||
type PowerAction struct {
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
func (pr *PowerAction) IsValid() bool {
|
||||
return pr.Action == "start" ||
|
||||
pr.Action == "stop" ||
|
||||
pr.Action == "kill" ||
|
||||
pr.Action == "restart"
|
||||
}
|
||||
@@ -394,3 +394,24 @@ func (s *Server) SetState(state string) error {
|
||||
func (s *Server) GetProcessConfiguration() (*api.ServerConfigurationResponse, *api.RequestError, error) {
|
||||
return api.NewRequester().GetServerConfiguration(s.Uuid)
|
||||
}
|
||||
|
||||
// Helper function that can receieve a power action and then process the
|
||||
// actions that need to occur for it.
|
||||
func (s *Server) HandlePowerAction(action PowerAction) error {
|
||||
switch action.Action {
|
||||
case "start":
|
||||
return s.Environment.Start()
|
||||
case "restart":
|
||||
if err := s.Environment.WaitForStop(60, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.Environment.Start()
|
||||
case "stop":
|
||||
return s.Environment.Stop()
|
||||
case "kill":
|
||||
return s.Environment.Terminate(os.Kill)
|
||||
default:
|
||||
return errors.New("an invalid power action was provided")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user