1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-20 22:48:02 +00:00

Many at once - this seems a good time to commit

This commit is contained in:
2023-01-19 20:57:22 +01:00
parent 0b5ec78d8c
commit 9811235be7
12 changed files with 252 additions and 58 deletions

View File

@ -16,8 +16,19 @@ import (
)
type Host struct {
Name string `json:"name"`
URI string `json:"uri"`
Name string `json:"name"`
URI string `json:"uri"`
Databases map[string]struct {
Collections map[string]struct {
ViewConfig struct {
HideObjectIndicators bool `json:"hideObjectIndicators"`
Columns []struct {
Key string `json:"key"`
Width int64 `json:"width"`
} `json:"columns"`
} `json:"viewConfig"`
} `json:"collections"`
} `json:"databases"`
}
func updateHostsFile(newData map[string]Host) error {
@ -81,7 +92,7 @@ func (a *App) AddHost(jsonData string) error {
Type: runtime.InfoDialog,
Title: "Malformed JSON",
})
return errors.New("could not retrieve existing host list")
return errors.New("invalid JSON")
}
id, err := uuid.NewRandom()
@ -93,8 +104,6 @@ func (a *App) AddHost(jsonData string) error {
return errors.New("could not generate a UUID")
}
fmt.Println(hosts)
hosts[id.String()] = newHost
err = updateHostsFile(hosts)
if err != nil {
@ -108,6 +117,39 @@ func (a *App) AddHost(jsonData string) error {
return nil
}
func (a *App) UpdateHost(hostKey string, jsonData string) error {
hosts, err := a.Hosts()
if err != nil {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Could not retrieve hosts",
})
return errors.New("could not retrieve existing host list")
}
var host Host
err = json.Unmarshal([]byte(jsonData), &host)
if err != nil {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Malformed JSON",
})
return errors.New("invalid JSON")
}
hosts[hostKey] = host
err = updateHostsFile(hosts)
if err != nil {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Could not update host list",
})
return errors.New("could not update host list")
}
return nil
}
func (a *App) RemoveHost(key string) error {
hosts, err := a.Hosts()
if err != nil {