mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-22 15:18:02 +00:00
Made harsh loading/error experience friendlier
This commit is contained in:
@ -12,10 +12,12 @@ import (
|
||||
mongoOptions "go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type HostInfo struct {
|
||||
Databases []string `json:"databases"`
|
||||
Status bson.M `json:"status"`
|
||||
SystemInfo bson.M `json:"systemInfo"`
|
||||
type OpenConnectionResult struct {
|
||||
Databases []string `json:"databases"`
|
||||
Status bson.M `json:"status"`
|
||||
StatusError string `json:"statusError"`
|
||||
SystemInfo bson.M `json:"systemInfo"`
|
||||
SystemInfoError string `json:"systemInfoError"`
|
||||
}
|
||||
|
||||
func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, func(), error) {
|
||||
@ -49,38 +51,35 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) OpenConnection(hostKey string) (info HostInfo) {
|
||||
func (a *App) OpenConnection(hostKey string) (result OpenConnectionResult) {
|
||||
client, ctx, close, err := a.connectToHost(hostKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer close()
|
||||
|
||||
info.Databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
||||
result.Databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve database names for host "+hostKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Error while getting databases"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
command := bson.M{"serverStatus": 1}
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&info.Status)
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&result.Status)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve server status")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not get server status"), zenity.ErrorIcon)
|
||||
return
|
||||
result.StatusError = err.Error()
|
||||
}
|
||||
|
||||
command = bson.M{"hostInfo": 1}
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&info.SystemInfo)
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&result.SystemInfo)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve system info")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not get system info"), zenity.ErrorIcon)
|
||||
return
|
||||
result.SystemInfoError = err.Error()
|
||||
}
|
||||
|
||||
defer close()
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user