Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action :Golangci lint #99

Merged
merged 5 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/go-c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ jobs:
make clean
make env
make
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
# version: v3.2.0

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --disable-all -E errcheck

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
- name: Build NOCORE
run: |
make clean
Expand Down Expand Up @@ -61,6 +85,30 @@ jobs:
make clean
make env
make
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
# version: v3.2.0

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --disable-all -E errcheck

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
- name: Build NOCORE
run: |
make clean
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ build: \
build_nocore: \
.checkver_$(CMD_GO)
#
CGO_ENABLED=0 $(CMD_GO) build -tags $(TARGET_TAG) -ldflags "-w -s -X 'ecapture/cli/cmd.GitVersion=linux_$(UNAME_M):$(VERSION):$(UNAME_R)' -X 'main.enableCORE=false'" -o bin/ecapture .
CGO_ENABLED=0 $(CMD_GO) build -tags $(TARGET_TAG) -ldflags "-w -s -X 'ecapture/cli/cmd.GitVersion=$(TARGET_TAG)_$(UNAME_M):$(VERSION):$(UNAME_R)' -X 'main.enableCORE=false'" -o bin/ecapture .


.PHONY: ebpf_nocore
Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func Execute() {
rootCmd.SetUsageFunc(usageFunc)
rootCmd.SetHelpTemplate(`{{.UsageString}}`)
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.Version = GitVersion
rootCmd.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version:\t%s" .Version}}
`)
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
9 changes: 6 additions & 3 deletions cli/cobrautl/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func getSubCommands(cmd *cobra.Command) []*cobra.Command {
func UsageFunc(cmd *cobra.Command, version string) error {
subCommands := getSubCommands(cmd)
tabOut := getTabOutWithWriter(os.Stdout)
commandUsageTemplate.Execute(tabOut, struct {
err := commandUsageTemplate.Execute(tabOut, struct {
Cmd *cobra.Command
LocalFlags string
GlobalFlags string
Expand All @@ -144,8 +144,11 @@ func UsageFunc(cmd *cobra.Command, version string) error {
subCommands,
version,
})
tabOut.Flush()
return nil
if err != nil {
return err
}
err = tabOut.Flush()
return err
}

func getTabOutWithWriter(writer io.Writer) *tabwriter.Writer {
Expand Down
1 change: 0 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import (

func Start() {
cmd.Execute()
return
}
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"ecapture/cli"
"ecapture/pkg/util/ebpf"
"ecapture/pkg/util/kernel"
"fmt"
"log"
)

Expand Down Expand Up @@ -33,7 +32,7 @@ func main() {
// BTF支持情况检测
enable, e := ebpf.IsEnableBTF()
if e != nil {
log.Fatal(fmt.Sprintf("Can't found BTF config with error:%v.\n"+BTF_NOT_SUPPORT, e))
log.Fatalf("Can't found BTF config with error:%v.\n"+BTF_NOT_SUPPORT, e)
}
if !enable {
log.Fatal("BTF not support, please check it. shell: cat /boot/config-`uname -r` | grep CONFIG_DEBUG_INFO_BTF \n " +
Expand All @@ -44,5 +43,4 @@ func main() {
// TODO check UPROBE

cli.Start()
return
}
14 changes: 5 additions & 9 deletions user/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const (
AF_INET6 = uint16(10)
)

func inet_ntop(ip uint32) string {
return fmt.Sprintf("%d.%d.%d.%d", byte(ip), byte(ip>>8), byte(ip>>16), byte(ip>>24))
}

func GetDynLibDirs() []string {
dirs, err := ParseDynLibConf(LD_LOAD_PATH)
if err != nil {
Expand Down Expand Up @@ -50,7 +46,10 @@ func GlobMany(targets []string, onErr func(string, error)) []string {
if err == nil {
// walk each match:
for _, p := range matches {
filepath.Walk(p, addFile)
e := filepath.Walk(p, addFile)
if e != nil {
continue
}
}
}
// path is not a wildcard, walk it:
Expand Down Expand Up @@ -149,7 +148,7 @@ func recurseSearchPath(searchPath []string, soName string) string {
continue
} else {
// found
return path;
return path
}
}
}
Expand Down Expand Up @@ -179,8 +178,6 @@ func recurseDynStrings(dynSym []string, searchPath []string, soName string) stri

// not match ,will open it, and recurse it
}
} else {
// Nothing
}
}

Expand All @@ -190,7 +187,6 @@ func recurseDynStrings(dynSym []string, searchPath []string, soName string) stri

if fd == nil {
log.Fatal(fmt.Sprintf("cant found lib so:%s in dirs:%v", el, searchPath))
continue
}

bint, err := elf.NewFile(fd)
Expand Down
2 changes: 1 addition & 1 deletion user/config_mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (this *MysqldConfig) Check() error {

// _Z16dispatch_command19enum_server_commandP3THDPcjbb

r, _ := regexp.Compile("\\w+dispatch_command\\w+")
r, _ := regexp.Compile(`\w+dispatch_command\w+`)
funcName := ""
for _, sym := range dynamicSymbols {
match := r.FindStringSubmatch(sym.Name)
Expand Down
2 changes: 1 addition & 1 deletion user/config_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (this *OpensslConfig) checkConnect() error {

//如果没找到,则报错。
if !found || funcName == "" {
return errors.New(fmt.Sprintf("cant found 'connect' function to hook in files::%v", sharedObjects))
return fmt.Errorf("cant found 'connect' function to hook in files::%v", sharedObjects)
}
return nil
}
3 changes: 1 addition & 2 deletions user/event_nspr.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func (this *NsprDataEvent) StringHex() string {
var b *bytes.Buffer
var s string
// firefox 进程的通讯线程名为 Socket Thread
var fire_thread string
fire_thread = strings.TrimSpace(fmt.Sprintf("%s", this.Comm[:13]))
var fire_thread = strings.TrimSpace(fmt.Sprintf("%s", this.Comm[:13]))
// disable filter default
if false && strings.Compare(fire_thread, "Socket Thread") != 0 {
b = bytes.NewBufferString(fmt.Sprintf("%s[ignore]%s", COLORBLUE, COLORRESET))
Expand Down
1 change: 0 additions & 1 deletion user/imodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type Module struct {
func (this *Module) Init(ctx context.Context, logger *log.Logger) {
this.ctx = ctx
this.logger = logger
return
}

func (this *Module) SetChild(module IModule) {
Expand Down