-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
running golangci-lint on config package
Signed-off-by: Navid Yaghoobi <[email protected]>
- Loading branch information
Showing
8 changed files
with
154 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ run: | |
- ".*_test.go" | ||
skip-dirs: | ||
- app | ||
# - cmd | ||
- config | ||
- ui/containers | ||
- ui/dialogs | ||
- ui/images | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"sort" | ||
"sync" | ||
|
@@ -13,18 +14,30 @@ const ( | |
// _configPath is the path to the podman-tui/podman-tui.conf | ||
// inside a given config directory. | ||
_configPath = "podman-tui/podman-tui.conf" | ||
// UserAppConfig holds the user podman-tui config path | ||
// UserAppConfig holds the user podman-tui config path. | ||
UserAppConfig = ".config/" + _configPath | ||
) | ||
|
||
// Config contains configuration options for container tools | ||
var ( | ||
ErrRemotePodmanUDSReport = errors.New("remote podman failed to report its UDS socket") | ||
ErrInvalidURISchemaName = errors.New("invalid schema name") | ||
ErrInvalidTCPSchemaOption = errors.New("invalid option for tcp") | ||
ErrInvalidUnixSchemaOption = errors.New("invalid option for unix") | ||
ErrFileNotUnixSocket = errors.New("not a unix domain socket") | ||
ErrEmptySSHIdentity = errors.New("empty identity field for SSH connection") | ||
ErrEmptyURIDestination = errors.New("empty URI destination") | ||
ErrEmptyServiceName = errors.New("empty service name") | ||
ErrDuplicatedServiceName = errors.New("duplicated service name") | ||
) | ||
|
||
// Config contains configuration options for container tools. | ||
type Config struct { | ||
mu sync.Mutex | ||
// Services specify the service destination connections | ||
Services map[string]Service `toml:"services,omitempty"` | ||
} | ||
|
||
// Service represents remote service destination | ||
// Service represents remote service destination. | ||
type Service struct { | ||
// URI, required. Example: ssh://[email protected]:22/run/podman/podman.sock | ||
URI string `toml:"uri"` | ||
|
@@ -36,9 +49,10 @@ type Service struct { | |
Default bool `toml:"default,omitempty"` | ||
} | ||
|
||
// NewConfig returns new config | ||
// NewConfig returns new config. | ||
func NewConfig() (*Config, error) { | ||
log.Debug().Msgf("config: new") | ||
|
||
path, err := configPath() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -54,9 +68,8 @@ func NewConfig() (*Config, error) { | |
return nil, err | ||
} | ||
} | ||
if err := newConfig.addLocalHostIfEmptyConfig(); err != nil { | ||
return nil, err | ||
} | ||
|
||
newConfig.addLocalHostIfEmptyConfig() | ||
|
||
defaultConn := newConfig.getDefault() | ||
if defaultConn.URI != "" { | ||
|
@@ -66,28 +79,25 @@ func NewConfig() (*Config, error) { | |
return newConfig, nil | ||
} | ||
|
||
func (c *Config) addLocalHostIfEmptyConfig() error { | ||
func (c *Config) addLocalHostIfEmptyConfig() { | ||
if len(c.Services) > 0 { | ||
return nil | ||
} | ||
localSocket, err := localNodeUnixSocket() | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
|
||
c.Services = make(map[string]Service) | ||
c.Services["localhost"] = Service{ | ||
URI: localSocket, | ||
URI: localNodeUnixSocket(), | ||
Default: true, | ||
} | ||
return nil | ||
} | ||
|
||
// ServicesConnections returns list of available connections | ||
// ServicesConnections returns list of available connections. | ||
func (c *Config) ServicesConnections() []registry.Connection { | ||
var conn []registry.Connection | ||
conn := make([]registry.Connection, 0) | ||
|
||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
for name, service := range c.Services { | ||
conn = append(conn, registry.Connection{ | ||
Name: name, | ||
|
@@ -96,7 +106,9 @@ func (c *Config) ServicesConnections() []registry.Connection { | |
Default: service.Default, | ||
}) | ||
} | ||
|
||
sort.Sort(connectionListSortedName{conn}) | ||
|
||
return conn | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.