diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6ea84a2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..92e9268 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,55 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.54 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + args: --timeout=3m -v + + # 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 all caching functionality will be completely disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # install-mode: "goinstall" \ No newline at end of file diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index 6accd90..b93506a 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -7,7 +7,7 @@ on: jobs: release-binary: name: Release Go Binary - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..71cbb75 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: codecov + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: 'stable' + - name: Run coverage + run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c57100a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage.txt diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..268e208 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,175 @@ +### Config GolangCI + +# Options for analysis running. +run: + # The default concurrency value is the number of available CPU. + concurrency: 2 + + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 5m + + # Exit code when at least one issue was found. + # Default: 1 + issues-exit-code: 2 + + # Include test files or not. + # Default: true + tests: false + + # If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # + # Allowed values: readonly|vendor|mod + # By default, it isn't set. + modules-download-mode: readonly + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: false + + # Define the Go version limit. + # Mainly related to generics support since go1.18. + # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18 + go: '1.18' + + +# output configuration options +output: + # Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity + # + # Multiple can be specified by separating them by comma, output can be provided + # for each of them by separating format name and path by colon symbol. + # Output path can be either `stdout`, `stderr` or path to the file to write to. + # Example: "checkstyle:report.xml,json:stdout,colored-line-number" + # + # Default: colored-line-number + format: json + + # Print lines of code with issue. + # Default: true + print-issued-lines: false + # Print linter name in the end of issue text. + # Default: true + print-linter-name: false + # Make issues output unique by line. + # Default: true + uniq-by-line: false + # Add a prefix to the output file references. + # Default is no prefix. + path-prefix: "" + # Sort results by: filepath, line and column. + sort-results: false + +linters: + # Disable all linters. + # Default: false + disable-all: false + + # Enable all available linters. + # Default: false + enable-all: false + + enable: + - errcheck + - gosimple + - govet + - ineffassign + - unused + - asciicheck + - bidichk + - containedctx + - cyclop + - decorder + - depguard + - dupl + - dupword + - execinquery + - exhaustruct + - goconst + - gosec + - interfacebloat + - misspell + - sqlclosecheck + - unconvert + - unparam + - usestdlibvars + + # Run only fast linters from enabled linters set (first run won't be fast) + # Default: false + fast: true + + +linters-settings: + cyclop: + # The maximal average package complexity. + # If it's higher than 0.0 (float) the check is enabled + # Default: 0.0 + package-average: 0.5 + # Should ignore tests. + # Default: false + skip-tests: true + + decorder: + # Required order of `type`, `const`, `var` and `func` declarations inside a file. + # Default: types before constants before variables before functions. + dec-order: + - type + - const + - var + - func + # If true, underscore vars (vars with "_" as the name) will be ignored at all checks + # Default: false (underscore vars are not ignored) + ignore-underscore-vars: false + # If true, order of declarations is not checked at all. + # Default: true (disabled) + disable-dec-order-check: false + # If true, `init` func can be anywhere in file (does not have to be declared before all other functions). + # Default: true (disabled) + disable-init-func-first-check: false + # If true, multiple global `type`, `const` and `var` declarations are allowed. + # Default: true (disabled) + disable-dec-num-check: false + # If true, type declarations will be ignored for dec num check + # Default: false (type statements are not ignored) + disable-type-dec-num-check: false + # If true, const declarations will be ignored for dec num check + # Default: false (const statements are not ignored) + disable-const-dec-num-check: false + # If true, var declarations will be ignored for dec num check + # Default: false (var statements are not ignored) + disable-var-dec-num-check: false + + dupl: + # Tokens count to trigger issue. + # Default: 150 + threshold: 150 + + dupword: + # Keywords for detecting duplicate words. + # If this list is not empty, only the words defined in this list will be detected. + # Default: [] + keywords: + - "the" + - "and" + - "a" + # Keywords used to ignore detection. + # Default: [] + ignore: + - "0C0C" + + exhaustivestruct: + # Struct Patterns is list of expressions to match struct packages and names. + # The struct packages have the form `example.com/package.ExampleStruct`. + # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match. + # If this list is empty, all structs are tested. + # Default: [] + struct-patterns: + - '*.Test' + - 'example.com/package.ExampleStruct' \ No newline at end of file diff --git a/pkg/command/db.go b/pkg/command/db.go index 7bdf5b3..77e90d6 100644 --- a/pkg/command/db.go +++ b/pkg/command/db.go @@ -16,8 +16,6 @@ func init() { } type DB struct { - dummyCommand - dbType string db *sql.DB isFinished bool diff --git a/pkg/command/shell.go b/pkg/command/shell.go index eb108ba..8d2fc3a 100644 --- a/pkg/command/shell.go +++ b/pkg/command/shell.go @@ -11,6 +11,12 @@ import ( "syscall" ) +const ( + WINDOWS_OS = "windows" + LINUX_OS = "linux" + MAC_OS = "darwin" +) + func init() { commands["shell"] = &Shell{} } @@ -57,7 +63,7 @@ func ExecShell(command string) { fmt.Println(command) fmt.Println() var cmd *exec.Cmd - if runtime.GOOS == "windows" { + if runtime.GOOS == WINDOWS_OS { cmd = exec.Command("cmd", "/C", command) } else { cmd = exec.Command("bash", "-c", command) @@ -80,7 +86,7 @@ func ExecShell(command string) { case <-done: return case <-sigChan: - if runtime.GOOS == "windows" { + if runtime.GOOS == WINDOWS_OS { _ = cmd.Process.Signal(os.Kill) } else { _ = syscall.Kill(cmd.Process.Pid, syscall.SIGINT) @@ -92,11 +98,11 @@ func ExecShell(command string) { func getOSInfo() string { var version string switch runtime.GOOS { - case "darwin": + case MAC_OS: version = darwinVersion() - case "linux": + case LINUX_OS: version = linuxVersion() - case "windows": + case WINDOWS_OS: version = windowsVersion() } return fmt.Sprintf("%s %s", runtime.GOOS, version) diff --git a/pkg/command/ssh.go b/pkg/command/ssh.go index b976023..a74d1a5 100644 --- a/pkg/command/ssh.go +++ b/pkg/command/ssh.go @@ -17,8 +17,6 @@ func init() { } type Ssh struct { - dummyCommand - client *ssh.Client host string osInfo string diff --git a/pkg/command/summary.go b/pkg/command/summary.go index 344b2e4..bd8cae3 100644 --- a/pkg/command/summary.go +++ b/pkg/command/summary.go @@ -3,6 +3,7 @@ package command import ( "fmt" "net/http" + "net/url" "regexp" "strings" @@ -44,8 +45,14 @@ func (c *Summary) Prompts(input string) []string { return []string{prompt} } -func crawl(url string) string { - resp, err := http.Get(url) +func crawl(url_input string) string { + // Validate the URL + if _, err := url.ParseRequestURI(url_input); err != nil { + fmt.Println("Invalid URL: ", err) + return "" + } + + resp, err := http.Get(url_input) if err != nil { fmt.Println("Error fetching URL: ", err) return ""