[#58] Update types for golint
This patch addresses guidance from effective go [0] and golint failures such as: pkg/document/document.go:8:6: type name will be used as document.DocumentFactory by other packages, and that stutters; consider calling this Factory pkg/remote/errors.go:9:6: type name will be used as remote.RemoteDirectError by other packages, and that stutters; consider calling this DirectError pkg/remote/remote_direct.go:27:6: type name will be used as remote.RemoteDirectClient by other packages, and that stutters; consider calling this DirectClient pkg/remote/redfish/errors.go:10:6: type name will be used as redfish.RedfishClientError by other packages, and that stutters; consider calling this ClientError pkg/remote/redfish/redfish.go:14:6: type name will be used as redfish.RedfishRemoteDirect by other packages, and that stutters; consider calling this RemoteDirect [0] https://golang.org/doc/effective_go.html#package-names Relates-To: #58 Change-Id: I6d94da7755c8719bbcc4a77917e283074281309a Signed-off-by: Alexander Hughes <Alexander.Hughes@pm.me>
This commit is contained in:
parent
517cf775c9
commit
2bf3117197
@ -180,9 +180,9 @@ func (b *BundleFactory) GetByName(name string) (Document, error) {
|
||||
// by adding strongly typed errors
|
||||
switch found := len(resSet); {
|
||||
case found == 0:
|
||||
return &DocumentFactory{}, fmt.Errorf("no documents found with name %s", name)
|
||||
return &Factory{}, fmt.Errorf("no documents found with name %s", name)
|
||||
case found > 1:
|
||||
return &DocumentFactory{}, fmt.Errorf("more than one document found with name %s", name)
|
||||
return &Factory{}, fmt.Errorf("more than one document found with name %s", name)
|
||||
default:
|
||||
return NewDocument(resSet[0])
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
// DocumentFactory holds document data
|
||||
type DocumentFactory struct {
|
||||
// Factory holds document data
|
||||
type Factory struct {
|
||||
resource.Resource
|
||||
}
|
||||
|
||||
@ -29,90 +29,90 @@ type Document interface {
|
||||
}
|
||||
|
||||
// GetNamespace returns the namespace the resource thinks it's in.
|
||||
func (d *DocumentFactory) GetNamespace() string {
|
||||
func (d *Factory) GetNamespace() string {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetNamespace()
|
||||
}
|
||||
|
||||
// GetString returns the string value at path.
|
||||
func (d *DocumentFactory) GetString(path string) (string, error) {
|
||||
func (d *Factory) GetString(path string) (string, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetString(path)
|
||||
}
|
||||
|
||||
// GetStringSlice returns a string slice at path.
|
||||
func (d *DocumentFactory) GetStringSlice(path string) ([]string, error) {
|
||||
func (d *Factory) GetStringSlice(path string) ([]string, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetStringSlice(path)
|
||||
}
|
||||
|
||||
// GetBool returns a bool at path.
|
||||
func (d *DocumentFactory) GetBool(path string) (bool, error) {
|
||||
func (d *Factory) GetBool(path string) (bool, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetBool(path)
|
||||
}
|
||||
|
||||
// GetFloat64 returns a float64 at path.
|
||||
func (d *DocumentFactory) GetFloat64(path string) (float64, error) {
|
||||
func (d *Factory) GetFloat64(path string) (float64, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetFloat64(path)
|
||||
}
|
||||
|
||||
// GetInt64 returns an int64 at path.
|
||||
func (d *DocumentFactory) GetInt64(path string) (int64, error) {
|
||||
func (d *Factory) GetInt64(path string) (int64, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetInt64(path)
|
||||
}
|
||||
|
||||
// GetSlice returns a slice at path.
|
||||
func (d *DocumentFactory) GetSlice(path string) ([]interface{}, error) {
|
||||
func (d *Factory) GetSlice(path string) ([]interface{}, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetSlice(path)
|
||||
}
|
||||
|
||||
// GetStringMap returns a string map at path.
|
||||
func (d *DocumentFactory) GetStringMap(path string) (map[string]string, error) {
|
||||
func (d *Factory) GetStringMap(path string) (map[string]string, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetStringMap(path)
|
||||
}
|
||||
|
||||
// GetMap returns a map at path.
|
||||
func (d *DocumentFactory) GetMap(path string) (map[string]interface{}, error) {
|
||||
func (d *Factory) GetMap(path string) (map[string]interface{}, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetMap(path)
|
||||
}
|
||||
|
||||
// AsYAML returns the document as a YAML byte stream.
|
||||
func (d *DocumentFactory) AsYAML() ([]byte, error) {
|
||||
func (d *Factory) AsYAML() ([]byte, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.AsYAML()
|
||||
}
|
||||
|
||||
// MarshalJSON returns the document as JSON.
|
||||
func (d *DocumentFactory) MarshalJSON() ([]byte, error) {
|
||||
func (d *Factory) MarshalJSON() ([]byte, error) {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.MarshalJSON()
|
||||
}
|
||||
|
||||
// GetName returns the name: field from the document.
|
||||
func (d *DocumentFactory) GetName() string {
|
||||
func (d *Factory) GetName() string {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetName()
|
||||
}
|
||||
|
||||
// GetKind returns the Kind: field from the document.
|
||||
func (d *DocumentFactory) GetKind() string {
|
||||
func (d *Factory) GetKind() string {
|
||||
r := d.GetKustomizeResource()
|
||||
return r.GetKind()
|
||||
}
|
||||
|
||||
// GetKustomizeResource returns a Kustomize Resource object for this document.
|
||||
func (d *DocumentFactory) GetKustomizeResource() resource.Resource {
|
||||
func (d *Factory) GetKustomizeResource() resource.Resource {
|
||||
return d.Resource
|
||||
}
|
||||
|
||||
// SetKustomizeResource sets a Kustomize Resource object for this document.
|
||||
func (d *DocumentFactory) SetKustomizeResource(r *resource.Resource) error {
|
||||
func (d *Factory) SetKustomizeResource(r *resource.Resource) error {
|
||||
d.Resource = *r
|
||||
return nil
|
||||
}
|
||||
@ -124,7 +124,7 @@ func (d *DocumentFactory) SetKustomizeResource(r *resource.Resource) error {
|
||||
// documents - e.g. in the future all documents require an airship
|
||||
// annotation X
|
||||
func NewDocument(r *resource.Resource) (Document, error) {
|
||||
var doc Document = &DocumentFactory{}
|
||||
var doc Document = &Factory{}
|
||||
err := doc.SetKustomizeResource(r)
|
||||
return doc, err
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import (
|
||||
aerror "opendev.org/airship/airshipctl/pkg/errors"
|
||||
)
|
||||
|
||||
type RemoteDirectError struct {
|
||||
type GenericError struct {
|
||||
aerror.AirshipError
|
||||
}
|
||||
|
||||
func NewRemoteDirectErrorf(format string, v ...interface{}) error {
|
||||
e := &RemoteDirectError{}
|
||||
e := &GenericError{}
|
||||
e.Message = fmt.Sprintf(format, v...)
|
||||
return e
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
aerror "opendev.org/airship/airshipctl/pkg/errors"
|
||||
)
|
||||
|
||||
type RedfishClientError struct {
|
||||
type ClientError struct {
|
||||
aerror.AirshipError
|
||||
}
|
||||
|
||||
func NewRedfishClientErrorf(format string, v ...interface{}) error {
|
||||
e := &RedfishClientError{}
|
||||
e := &ClientError{}
|
||||
e.Message = fmt.Sprintf(format, v...)
|
||||
return e
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
alog "opendev.org/airship/airshipctl/pkg/log"
|
||||
)
|
||||
|
||||
type RedfishRemoteDirect struct {
|
||||
type RemoteDirect struct {
|
||||
|
||||
// Context
|
||||
Context context.Context
|
||||
@ -30,7 +30,7 @@ type RedfishRemoteDirect struct {
|
||||
}
|
||||
|
||||
// Top level function to handle Redfish remote direct
|
||||
func (cfg RedfishRemoteDirect) DoRemoteDirect() error {
|
||||
func (cfg RemoteDirect) DoRemoteDirect() error {
|
||||
alog.Debugf("Using Redfish Endpoint: '%s'", cfg.RemoteURL.String())
|
||||
|
||||
/* TODO: Add Authentication when redfish library supports it. */
|
||||
@ -82,23 +82,23 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
|
||||
remoteURL string,
|
||||
ephNodeID string,
|
||||
isoPath string,
|
||||
) (RedfishRemoteDirect, error) {
|
||||
) (RemoteDirect, error) {
|
||||
if remoteURL == "" {
|
||||
return RedfishRemoteDirect{},
|
||||
return RemoteDirect{},
|
||||
ErrRedfishMissingConfig{
|
||||
What: "redfish remote url empty",
|
||||
}
|
||||
}
|
||||
|
||||
if ephNodeID == "" {
|
||||
return RedfishRemoteDirect{},
|
||||
return RemoteDirect{},
|
||||
ErrRedfishMissingConfig{
|
||||
What: "redfish ephemeral node id empty",
|
||||
}
|
||||
}
|
||||
|
||||
if isoPath == "" {
|
||||
return RedfishRemoteDirect{},
|
||||
return RemoteDirect{},
|
||||
ErrRedfishMissingConfig{
|
||||
What: "redfish ephemeral node iso Path empty",
|
||||
}
|
||||
@ -114,13 +114,13 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
|
||||
|
||||
parsedURL, err := url.Parse(remoteURL)
|
||||
if err != nil {
|
||||
return RedfishRemoteDirect{},
|
||||
return RemoteDirect{},
|
||||
ErrRedfishMissingConfig{
|
||||
What: fmt.Sprintf("invalid url format: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
client := RedfishRemoteDirect{
|
||||
client := RemoteDirect{
|
||||
Context: ctx,
|
||||
RemoteURL: *parsedURL,
|
||||
EphemeralNodeID: ephNodeID,
|
||||
|
@ -75,7 +75,7 @@ func TestRedfishRemoteDirectInvalidSystemId(t *testing.T) {
|
||||
|
||||
err := localRDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func TestRedfishRemoteDirectGetSystemNetworkError(t *testing.T) {
|
||||
|
||||
err := rDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ func TestRedfishRemoteDirectInvalidIsoPath(t *testing.T) {
|
||||
|
||||
err := localRDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ func TestRedfishRemoteDirectCdDvdNotAvailableInBootSources(t *testing.T) {
|
||||
|
||||
err := rDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ func TestRedfishRemoteDirectSetSystemBootSourceFailed(t *testing.T) {
|
||||
|
||||
err := rDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ func TestRedfishRemoteDirectSystemRebootFailed(t *testing.T) {
|
||||
|
||||
err := rDCfg.DoRemoteDirect()
|
||||
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ func getTestSystem() redfishClient.ComputerSystem {
|
||||
}
|
||||
}
|
||||
|
||||
func getDefaultRedfishRemoteDirectObj(t *testing.T, api redfishAPI.RedfishAPI) RedfishRemoteDirect {
|
||||
func getDefaultRedfishRemoteDirectObj(t *testing.T, api redfishAPI.RedfishAPI) RemoteDirect {
|
||||
t.Helper()
|
||||
|
||||
rDCfg, err := NewRedfishRemoteDirectClient(
|
||||
|
@ -25,7 +25,7 @@ func TestRedfishErrorNonNilErrorWithoutHttpResp(t *testing.T) {
|
||||
realErr := fmt.Errorf("sample error")
|
||||
err := ScreenRedfishError(nil, realErr)
|
||||
assert.Error(t, err)
|
||||
_, ok := err.(*RedfishClientError)
|
||||
_, ok := err.(*ClientError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ const (
|
||||
)
|
||||
|
||||
// Interface to be implemented by remoteDirect implementation
|
||||
type RemoteDirectClient interface {
|
||||
type Client interface {
|
||||
DoRemoteDirect() error
|
||||
}
|
||||
|
||||
// Get remotedirect client based on config
|
||||
func getRemoteDirectClient(remoteConfig *config.RemoteDirect, remoteURL string) (RemoteDirectClient, error) {
|
||||
var client RemoteDirectClient
|
||||
func getRemoteDirectClient(remoteConfig *config.RemoteDirect, remoteURL string) (Client, error) {
|
||||
var client Client
|
||||
switch remoteConfig.RemoteType {
|
||||
case AirshipRemoteTypeRedfish:
|
||||
alog.Debug("Remote type redfish")
|
||||
|
@ -36,7 +36,7 @@ func TestUnknownRemoteType(t *testing.T) {
|
||||
|
||||
err := DoRemoteDirect(s)
|
||||
|
||||
_, ok := err.(*RemoteDirectError)
|
||||
_, ok := err.(*GenericError)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user