Refactor HTTP endpoints to be less complicated and follow better standards
This commit is contained in:
@@ -13,10 +13,10 @@ import (
|
||||
// Notifies the panel of a backup's state and returns an error if one is encountered
|
||||
// while performing this action.
|
||||
func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, successful bool) error {
|
||||
r := api.NewRequester()
|
||||
rerr, err := r.SendBackupStatus(uuid, ad.ToRequest(successful))
|
||||
if rerr != nil || err != nil {
|
||||
if err != nil {
|
||||
r := api.New()
|
||||
err := r.SendBackupStatus(uuid, ad.ToRequest(successful))
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
s.Log().WithFields(log.Fields{
|
||||
"backup": uuid,
|
||||
"error": err,
|
||||
@@ -25,7 +25,7 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.New(rerr.String())
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -87,13 +87,13 @@ func (s *Server) Reinstall() error {
|
||||
|
||||
// Internal installation function used to simplify reporting back to the Panel.
|
||||
func (s *Server) internalInstall() error {
|
||||
script, rerr, err := api.NewRequester().GetInstallationScript(s.Id())
|
||||
if err != nil || rerr != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
script, err := api.New().GetInstallationScript(s.Id())
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return errors.New(rerr.String())
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
|
||||
p, err := NewInstallationProcess(s, &script)
|
||||
@@ -512,15 +512,13 @@ func (ip *InstallationProcess) StreamOutput(id string) error {
|
||||
// value of "true" means everything was successful, "false" means something went
|
||||
// wrong and the server must be deleted and re-created.
|
||||
func (s *Server) SyncInstallState(successful bool) error {
|
||||
r := api.NewRequester()
|
||||
|
||||
rerr, err := r.SendInstallationStatus(s.Id(), successful)
|
||||
if rerr != nil || err != nil {
|
||||
if err != nil {
|
||||
err := api.New().SendInstallationStatus(s.Id(), successful)
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return errors.New(rerr.String())
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -32,13 +32,13 @@ func LoadDirectory() error {
|
||||
}
|
||||
|
||||
log.Info("fetching list of servers from API")
|
||||
configs, rerr, err := api.NewRequester().GetAllServerConfigurations()
|
||||
if err != nil || rerr != nil {
|
||||
if err != nil {
|
||||
configs, err := api.New().GetAllServerConfigurations()
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return errors.New(rerr.String())
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user