Refactor HTTP endpoints to be less complicated and follow better standards

This commit is contained in:
Dane Everitt
2020-10-31 10:04:20 -07:00
parent c4703f5541
commit 334b3e8d10
12 changed files with 203 additions and 245 deletions

View File

@@ -112,17 +112,17 @@ func (s *Server) Log() *log.Entry {
// This also means mass actions can be performed against servers on the Panel and they
// will automatically sync with Wings when the server is started.
func (s *Server) Sync() error {
cfg, rerr, err := s.GetProcessConfiguration()
if err != nil || rerr != nil {
if err != nil {
cfg, err := api.New().GetServerConfiguration(s.Id())
if err != nil {
if !api.IsRequestError(err) {
return errors.WithStack(err)
}
if rerr.Status == "404" {
if err.(*api.RequestError).Status == "404" {
return &serverDoesNotExist{}
}
return errors.New(rerr.String())
return errors.New(err.Error())
}
return s.SyncWithConfiguration(cfg)
@@ -177,11 +177,6 @@ func (s *Server) CreateEnvironment() error {
return s.Environment.Create()
}
// Gets the process configuration data for the server.
func (s *Server) GetProcessConfiguration() (api.ServerConfigurationResponse, *api.RequestError, error) {
return api.NewRequester().GetServerConfiguration(s.Id())
}
// Checks if the server is marked as being suspended or not on the system.
func (s *Server) IsSuspended() bool {
return s.Config().Suspended