fix golint issues

Signed-off-by: roywang <seiwy2010@gmail.com>
This commit is contained in:
roywang
2020-12-10 12:10:42 +09:00
parent f48aba6f66
commit d14558a227
5 changed files with 19 additions and 14 deletions

View File

@@ -29,18 +29,21 @@ func GetCliBinary() string {
return path.Join(cwd, "../..", "./bin")
}
// Exec executes a command
func Exec(cli string) (string, error) {
var output []byte
session, err := AsyncExec(cli)
session, err := asyncExec(cli)
if err != nil {
return string(output), err
}
s := session.Wait(30 * time.Second)
return string(s.Out.Contents()) + string(s.Err.Contents()), nil
}
// ExecAndTerminate executes a long-running command and terminate it after 3s
func ExecAndTerminate(cli string) (string, error) {
var output []byte
session, err := AsyncExec(cli)
session, err := asyncExec(cli)
if err != nil {
return string(output), err
}
@@ -49,9 +52,10 @@ func ExecAndTerminate(cli string) (string, error) {
return string(s.Out.Contents()) + string(s.Err.Contents()), nil
}
// LongTimeExec executes a long-running command and wait it exits by itself
func LongTimeExec(cli string, timeout time.Duration) (string, error) {
var output []byte
session, err := AsyncExec(cli)
session, err := asyncExec(cli)
if err != nil {
return string(output), err
}
@@ -59,7 +63,7 @@ func LongTimeExec(cli string, timeout time.Duration) (string, error) {
return string(s.Out.Contents()) + string(s.Err.Contents()), nil
}
func AsyncExec(cli string) (*gexec.Session, error) {
func asyncExec(cli string) (*gexec.Session, error) {
c := strings.Fields(cli)
commandName := path.Join(rudrPath, c[0])
command := exec.Command(commandName, c[1:]...)
@@ -67,6 +71,7 @@ func AsyncExec(cli string) (*gexec.Session, error) {
return session, err
}
// InteractiveExec executes a command with interactive input
func InteractiveExec(cli string, consoleFn func(*expect.Console)) (string, error) {
var output []byte
console, _, err := vt10x.NewVT10XConsole(expect.WithStdout(ginkgo.GinkgoWriter))

View File

@@ -20,10 +20,10 @@ func main() {
fmt.Fprintln(os.Stderr, "error getting chart source:", err)
os.Exit(1)
}
PrintToFile(source)
printToFile(source)
}
func PrintToFile(data string) {
func printToFile(data string) {
var buffer bytes.Buffer
buffer.WriteString(`package fake
var ChartSource = "`)

View File

@@ -147,7 +147,7 @@ func (ref *ReferenceMarkdown) parseParameters(paraValue cue.Value, paramKey stri
case cue.StructKind:
arguments, err := paraValue.Struct()
if err != nil {
return errors.New(fmt.Sprintf("arguments not defined as struct %v", err))
return fmt.Errorf("arguments not defined as struct %w", err)
}
for i := 0; i < arguments.Len(); i++ {
var param Parameter
@@ -179,7 +179,7 @@ func (ref *ReferenceMarkdown) parseParameters(paraValue cue.Value, paramKey stri
case cue.ListKind:
elem, success := val.Elem()
if !success {
return errors.New(fmt.Sprintf("failed to get elements from %s", val))
return fmt.Errorf("failed to get elements from %s", val)
}
switch elem.Kind() {
case cue.StructKind:
@@ -228,15 +228,15 @@ func generateSpecification(capability string) (string, error) {
configurationPath, err := filepath.Abs(filepath.Join("hack/references/configurations",
fmt.Sprintf("%s.yaml", capability)))
if err != nil {
return "", errors.New(fmt.Sprintf("failed to get configuration path: %v", err))
return "", fmt.Errorf("failed to get configuration path: %w", err)
}
f, err := os.Open(configurationPath)
if err != nil {
return "", errors.New(fmt.Sprintf("failed to open configuration file: %v", err))
return "", fmt.Errorf("failed to open configuration file: %w", err)
}
spec, err := ioutil.ReadAll(f)
if err != nil {
return "", errors.New(fmt.Sprintf("failed to read configuration file: %v", err))
return "", fmt.Errorf("failed to read configuration file: %w", err)
}
return fmt.Sprintf("```yaml\n%s```", spec), nil
}

View File

@@ -5,8 +5,8 @@ import (
"fmt"
)
// From https://github.com/rakyll/statik/blob/master/statik.go#L313
// FprintZipData converts zip binary contents to a string literal.
// From https://github.com/rakyll/statik/blob/master/statik.go#L313
func FprintZipData(dest *bytes.Buffer, zipData []byte) {
for _, b := range zipData {
if b == '\n' {

View File

@@ -77,7 +77,7 @@ func Install(kubecli client.Client) {
}
}
// nolint
// Uninstall will uninstall kubevela helm release
func Uninstall(kubecli client.Client) {
velaConfig, err := fetchVelaConfig(kubecli)
if err != nil {
@@ -89,7 +89,7 @@ func Uninstall(kubecli client.Client) {
for _, chart := range velaConfig.Data {
err := uninstallHelmChart([]byte(chart), log)
if err != nil {
log.Error(err, "failed to install helm chart")
log.Error(err, "failed to uninstall helm chart")
}
}
}