Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.24.x
go-version: 1.25.x
- name: Build and pack for linux-amd64
run: GOOS=linux GOARCH=amd64 go build -o nmap-formatter && tar -czvf nmap-formatter-linux-amd64.tar.gz nmap-formatter
- name: Build and pack for linux-arm64
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ jobs:
lint:
strategy:
matrix:
go-version: [1.24.x]
go-version: [1.25.x]
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout 10m
test:
strategy:
matrix:
go-version: [1.24.x]
go-version: [1.25.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -47,7 +47,7 @@ jobs:
coverage:
strategy:
matrix:
go-version: [1.24.x]
go-version: [1.25.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ All major components have corresponding `_test.go` files. Tests typically:
- Test filter expressions with various host/port conditions
- Validate format-specific output structure

The CI runs tests on Go 1.24.x across Linux, macOS, and Windows.
The CI runs tests on Go 1.25.x across Linux, macOS, and Windows.

## Module Information

- Module path: `github.com/vdjagilev/nmap-formatter/v3`
- Go version: 1.24
- Go version: 1.25
- Uses go modules for dependency management

## Key Dependencies
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM golang:1.24-alpine AS builder
FROM golang:1.25-alpine AS builder

WORKDIR /src/
COPY . /src/

RUN apk add --update gcc musl-dev
RUN CGO_ENABLED=1 go build -o /bin/nmap-formatter

FROM alpine:3.21
FROM alpine:3.22

COPY --from=builder /bin/nmap-formatter /bin/nmap-formatter

Expand Down
10 changes: 7 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var config = formatter.Config{
}

// VERSION is describing current version of the nmap-formatter
const VERSION string = "3.0.2"
const VERSION string = "3.1.0"

var workflow formatter.Workflow

Expand Down Expand Up @@ -184,10 +184,14 @@ func run(cmd *cobra.Command, args []string) error {
}

if config.Writer != nil {
config.Writer.Close()
if closeErr := config.Writer.Close(); closeErr != nil {
log.Printf("Error closing writer: %v", closeErr)
}
}
if config.InputFileConfig.Source != nil {
config.InputFileConfig.Source.Close()
if closeErr := config.InputFileConfig.Source.Close(); closeErr != nil {
log.Printf("Error closing input source: %v", closeErr)
}
}

return nil
Expand Down
8 changes: 5 additions & 3 deletions cmd/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func validateIOFiles(config formatter.Config) error {
if err != nil {
return fmt.Errorf("unable to create output file: %s", err)
}
outputFile.Close()
os.Remove(string(config.OutputFile))
_ = outputFile.Close()
_ = os.Remove(string(config.OutputFile))
}
return nil
}
Expand All @@ -56,7 +56,9 @@ func validateTemplateConfig(config formatter.Config) error {
if err != nil {
return fmt.Errorf("could not read template file: %v", err)
}
defer file.Close()
defer func() {
_ = file.Close()
}()
}
return nil
}
6 changes: 4 additions & 2 deletions formatter/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type InputFileConfig struct {
// ExistsOpen tries to open a file for reading, returning an error if it fails
func (i *InputFileConfig) ExistsOpen() error {
f, err := os.Open(i.Path)
f.Close()
return err
if err != nil {
return err
}
return f.Close()
}
6 changes: 4 additions & 2 deletions formatter/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ func TestInputFileConfig_ExistsOpen(t *testing.T) {
if err != nil {
t.Errorf("error creating temporary file: %s", err)
}
defer f.Close()
defer func() {
_ = f.Close()
}()
}
afterFunc := func(name string) {
os.Remove(name)
_ = os.Remove(name)
}
tests := []struct {
name string
Expand Down
4 changes: 3 additions & 1 deletion formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func TemplateContent(f Formatter, c *Config) (string, error) {
if err != nil {
return "", err
}
defer file.Close()
defer func() {
_ = file.Close()
}()
content, err := io.ReadAll(file)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions formatter/formatter_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func (f *CSVFormatter) Format(td *TemplateData, templateContent string) (err err
func (f *CSVFormatter) convert(td *TemplateData) (data [][]string) {
data = append(data, []string{"IP", "Port", "Protocol", "State", "Service", "Reason", "Product", "Version", "Extra info"})
for i := range td.NMAPRun.Host {
var host *Host = &td.NMAPRun.Host[i]
host := &td.NMAPRun.Host[i]
address := fmt.Sprintf("%s (%s)", host.JoinedAddresses("/"), host.Status.State)
data = append(data, []string{address, "", "", "", "", "", "", "", ""})
for j := range host.Port {
var port *Port = &host.Port[j]
port := &host.Port[j]
data = append(
data,
[]string{
Expand Down
2 changes: 1 addition & 1 deletion formatter/formatter_dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func portStateColor(port *Port) string {

// hopList function returns a map with a list of hops where very first hop is `startHop` (scanner itself)
func hopList(hops []Hop, startHop string, endHopName string, endHopKey int) map[string]string {
var hopList map[string]string = map[string]string{}
hopList := map[string]string{}
var previous *Hop = nil
for i := range hops {
// Skip last hop, because it has the same IP as the target server
Expand Down
6 changes: 4 additions & 2 deletions formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func TestTemplateContent(t *testing.T) {
if err != nil {
t.Errorf("failed to create a file: %v", err)
}
defer f.Close()
defer func() {
_ = f.Close()
}()
}
afterFunc := func(path string) {
os.Remove(path)
_ = os.Remove(path)
}
tests := []struct {
name string
Expand Down
4 changes: 2 additions & 2 deletions formatter/nmap_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Host struct {

// JoinedAddresses joins all possible host addresses with a delimiter string
func (h *Host) JoinedAddresses(delimiter string) string {
var addr string = ""
addr := ""
for i := range h.HostAddress {
// First element does not require prepended delimiter
if i == 0 {
Expand All @@ -39,7 +39,7 @@ func (h *Host) JoinedAddresses(delimiter string) string {

// JoinedHostNames returns a joined string of host names with a provided delimiter
func (h *Host) JoinedHostNames(delimiter string) string {
var hostAddr string = ""
hostAddr := ""
for i := range h.HostNames.HostName {
// First element does not require prepended delimiter
if i != 0 {
Expand Down
2 changes: 1 addition & 1 deletion formatter/nmap_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type StatHosts struct {
// AllHops is getting all possible hops that occurred during the scan and
// merges them uniquely into one map
func (n *NMAPRun) AllHops() map[string]Hop {
var hops map[string]Hop = map[string]Hop{}
hops := map[string]Hop{}
for i := range n.Host {
for j := range n.Host[i].Trace.Hops {
// Skip the last hop, because it has the same IP as the target server
Expand Down
16 changes: 12 additions & 4 deletions formatter/sqlite_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (s *SqliteDB) schemaExists() bool {
if err != nil {
return false
}
defer rows.Close()
defer func() {
_ = rows.Close()
}()
return true
}

Expand Down Expand Up @@ -99,7 +101,9 @@ func (s *SqliteDB) populate(n *NMAPRun) error {

// finish is a place where commit or rollback should happen and database connection is closed
func (s *SqliteDB) finish(err error) error {
defer s.db.Close()
defer func() {
_ = s.db.Close()
}()
if err != nil {
rollbackErr := s.tx.Rollback()
if rollbackErr != nil {
Expand All @@ -122,7 +126,9 @@ func (s *SqliteDB) insertReturnID(sql string, args ...any) (int64, error) {
if err != nil {
return 0, err
}
defer insert.Close()
defer func() {
_ = insert.Close()
}()
result, err := insert.Exec(args...)
if err != nil {
return 0, err
Expand All @@ -137,7 +143,9 @@ func (s *SqliteDB) insert(sql string, args ...any) error {
if err != nil {
return err
}
defer insert.Close()
defer func() {
_ = insert.Close()
}()
_, err = insert.Exec(args...)
return err
}
16 changes: 12 additions & 4 deletions formatter/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ func TestMainWorkflow_parse(t *testing.T) {
t.Errorf("Could not write file, error %v", err)
}
// deferring file removal after the test
defer os.Remove(name)
defer func() {
_ = os.Remove(name)
}()
f, err := os.Open(name)
if err != nil {
t.Errorf("could not read source file: %v", err)
}
defer f.Close()
defer func() {
_ = f.Close()
}()
tt.w.Config.InputFileConfig = InputFileConfig{
Path: name,
Source: f,
Expand Down Expand Up @@ -213,8 +217,12 @@ func TestMainWorkflow_Execute(t *testing.T) {
if err != nil {
t.Errorf("Could not write file, error %v", err)
}
defer os.Remove(name)
defer os.Remove(name + "_output")
defer func() {
_ = os.Remove(name)
}()
defer func() {
_ = os.Remove(name + "_output")
}()
tt.w.Config.InputFileConfig = InputFileConfig{
Path: name,
}
Expand Down
46 changes: 23 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
module github.com/vdjagilev/nmap-formatter/v3

go 1.24
go 1.25

require (
github.com/expr-lang/expr v1.17.2
github.com/expr-lang/expr v1.17.6
github.com/google/uuid v1.6.0
github.com/mattn/go-sqlite3 v1.14.24
github.com/spf13/cobra v1.9.1
github.com/xuri/excelize/v2 v2.9.0
golang.org/x/net v0.38.0
oss.terrastruct.com/d2 v0.6.9
github.com/mattn/go-sqlite3 v1.14.32
github.com/spf13/cobra v1.10.1
github.com/xuri/excelize/v2 v2.10.0
golang.org/x/net v0.46.0
oss.terrastruct.com/d2 v0.7.1
)

require (
github.com/PuerkitoBio/goquery v1.10.2 // indirect
github.com/alecthomas/chroma/v2 v2.15.0 // indirect
github.com/PuerkitoBio/goquery v1.10.3 // indirect
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c // indirect
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e // indirect
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mazznoer/csscolorparser v0.1.5 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mazznoer/csscolorparser v0.1.6 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/xuri/efp v0.0.0-20250227110027-3491fafc2b79 // indirect
github.com/xuri/nfp v0.0.0-20250226145837-86d5fc24b2ba // indirect
github.com/yuin/goldmark v1.7.8 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
golang.org/x/image v0.25.0 // indirect
golang.org/x/text v0.23.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/tiendc/go-deepcopy v1.7.1 // indirect
github.com/xuri/efp v0.0.1 // indirect
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect
github.com/yuin/goldmark v1.7.13 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/image v0.32.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
gonum.org/v1/plot v0.16.0 // indirect
oss.terrastruct.com/util-go v0.0.0-20250213174338-243d8661088a // indirect
)
Loading
Loading