Skip to content

Commit

Permalink
chore: code clean for hack known_types.go (argoproj#12304)
Browse files Browse the repository at this point in the history
Signed-off-by: yanggang <gang.yang@daocloud.io>
  • Loading branch information
Yang Gang authored and xiaowu.zhu committed Aug 9, 2023
1 parent c739a5b commit 3a23027
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions hack/known_types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"go/importer"
"go/token"
"go/types"
"os"
"strings"
Expand Down Expand Up @@ -36,15 +37,16 @@ func newCommand() *cobra.Command {
packagePath := args[1]
outputPath := args[2]

// nolint:staticcheck
imprt := importer.For("source", nil)
if !strings.HasPrefix(packagePath, packagePrefix) {
return fmt.Errorf("package must be under %s", packagePrefix)
}

imprt := importer.ForCompiler(token.NewFileSet(), "source", nil)
pkg, err := imprt.Import(packagePath)
if err != nil {
return err
}
if !strings.HasPrefix(packagePath, packagePrefix) {
return fmt.Errorf("package must be under %s", packagePrefix)
}

shortPackagePath := strings.TrimPrefix(packagePath, packagePrefix)

var mapItems []string
Expand Down

0 comments on commit 3a23027

Please sign in to comment.