ci: add go lint

This commit is contained in:
2025-03-14 05:24:46 +01:00
parent 6300a8f2dd
commit 731e2d789d
3 changed files with 27 additions and 3 deletions

23
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Lint
on:
push:
pull_request:
jobs:
lint:
name: Run on Ubuntu
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.23'
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.61

View File

@@ -27,6 +27,7 @@ package pkg
import (
"bytes"
"errors"
"fmt"
"github.com/jkaninda/encryptor"
"github.com/jkaninda/go-storage/pkg/local"
@@ -388,7 +389,7 @@ func listDatabases(db dbConfig) ([]string, error) {
databases := []string{}
// Create the mysql client config file
if err := createMysqlClientConfigFile(db); err != nil {
return databases, fmt.Errorf(err.Error())
return databases, errors.New(err.Error())
}
utils.Info("Listing databases...")
// Step 1: List all databases

View File

@@ -26,6 +26,7 @@ package pkg
import (
"bytes"
"errors"
"fmt"
goutils "github.com/jkaninda/go-utils"
"github.com/jkaninda/mysql-bkup/utils"
@@ -70,14 +71,13 @@ func deleteTemp() {
func testDatabaseConnection(db *dbConfig) error {
// Create the mysql client config file
if err := createMysqlClientConfigFile(*db); err != nil {
return fmt.Errorf(err.Error())
return errors.New(err.Error())
}
utils.Info("Connecting to %s database ...", db.dbName)
// Set database name for notification error
utils.DatabaseName = db.dbName
// Prepare the command to test the database connection
//cmd := exec.Command("mariadb", "-h", db.dbHost, "-P", db.dbPort, "-u", db.dbUserName, db.dbName, "-e", "quit")
cmd := exec.Command("mariadb", fmt.Sprintf("--defaults-file=%s", mysqlClientConfig), db.dbName, "-e", "quit")
// Capture the output
var out bytes.Buffer