From 1bae4e44b09df2071884fcecfc464670853661fb Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 2 Sep 2026 16:31:26 -0400 Subject: [PATCH] Learning about formatIO --- Composite_Types/go.mod | 4 ++-- For_If_Switch/go.mod | 4 ++-- courses/go.mod | 4 ++-- formatIO/a.txt | 4 ++++ formatIO/b.txt | 2 ++ formatIO/c.txt | 4 ++++ formatIO/go.mod | 3 +++ formatIO/main.go | 40 ++++++++++++++++++++++++++++++++++++++++ functions/go.mod | 3 +++ functions/main.go | 19 +++++++++++++++++++ go.work | 12 ++++++++++++ pointers/go.mod | 4 ++-- strings/go.mod | 4 ++-- types/go.mod | 2 +- 14 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 formatIO/a.txt create mode 100644 formatIO/b.txt create mode 100644 formatIO/c.txt create mode 100644 formatIO/go.mod create mode 100644 formatIO/main.go create mode 100644 functions/go.mod create mode 100644 functions/main.go create mode 100644 go.work diff --git a/Composite_Types/go.mod b/Composite_Types/go.mod index a9eb3f6..64f32ae 100644 --- a/Composite_Types/go.mod +++ b/Composite_Types/go.mod @@ -1,3 +1,3 @@ -module main +module letsgo/composite_types -go 1.26.5 +go 1.27 diff --git a/For_If_Switch/go.mod b/For_If_Switch/go.mod index 96dbddb..0d447af 100644 --- a/For_If_Switch/go.mod +++ b/For_If_Switch/go.mod @@ -1,3 +1,3 @@ -module main.go +module letsgo/for_if_switch -go 1.23.1 +go 1.27 diff --git a/courses/go.mod b/courses/go.mod index 378a044..6006268 100644 --- a/courses/go.mod +++ b/courses/go.mod @@ -1,3 +1,3 @@ -module hello +module letsgo/courses -go 1.23.1 +go 1.27 diff --git a/formatIO/a.txt b/formatIO/a.txt new file mode 100644 index 0000000..331acbc --- /dev/null +++ b/formatIO/a.txt @@ -0,0 +1,4 @@ +Root cause: +- ~/.local/share/nvim/mason/bin/gopls:1 reported expected 'package', found 'EOF' on any empty *.go (/tmp/empty.go:1:1). Valid files now show 0 diagnostics. +- ~/gitclone/letsGO/*/go.mod:1 had invalid/mixed modules (main, main.go, hello v1.23.1-1.26.5) and no go.work — gopls couldn't resolve workspace. +- ~/.config/nvim/lua/plugins/go.lua:8 used wrong plugin name "mason.nvim" (should be "mason-org/mason.nvim"), so ensure_installed never ran. diff --git a/formatIO/b.txt b/formatIO/b.txt new file mode 100644 index 0000000..c697f0f --- /dev/null +++ b/formatIO/b.txt @@ -0,0 +1,2 @@ +Fixes applied: +1. ~/.config/nvim/lua/plugins/go.lua:1 — fixed mason name to mason-org/mason.nvim, ensure_installed = { "gopls","gofumpt","goimports","golangci-lint","delve" }, kept nvim-treesitter for go/gomod/gowork/gosum, tuned gopls (gofumpt=true, staticcheck, completeUnimported). Relies on lazyvim.plugins.extras.lang.go in ~/.config/nvim/lazyvim.json:3. diff --git a/formatIO/c.txt b/formatIO/c.txt new file mode 100644 index 0000000..0a8eede --- /dev/null +++ b/formatIO/c.txt @@ -0,0 +1,4 @@ +Verified: +- ~/.local/share/nvim/mason/bin/gopls version v0.23.0, go vet OK for all 7 modules +- nvim --headless edit formatIO/main.go → 0 diagnostics (was EOF on empty) +- nvim --headless edit /tmp/should_show_eof.go (empty) → 1 diag expected 'package', found 'EOF' — expected, template will prevent. diff --git a/formatIO/go.mod b/formatIO/go.mod new file mode 100644 index 0000000..074a6ac --- /dev/null +++ b/formatIO/go.mod @@ -0,0 +1,3 @@ +module letsgo/formatio + +go 1.27 diff --git a/formatIO/main.go b/formatIO/main.go new file mode 100644 index 0000000..7ff137e --- /dev/null +++ b/formatIO/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func main() { + var tlc, tcc, twc int + for _, fname := range os.Args[1:] { + + var lc, cc, wc int + file, err := os.Open(fname) + if err != nil { + fmt.Fprintln(os.Stderr, err) + continue + } + defer file.Close() + + scan := bufio.NewScanner(file) + for scan.Scan() { + s := scan.Text() + + wc += len(strings.Fields(s)) + cc += len(s) + lc++ + } + tlc += lc + tcc += cc + twc += wc + if err := scan.Err(); err != nil { + fmt.Printf("Invalid Input: %s", err) + } + + fmt.Printf("%5d %5d %5d %s\n", lc, cc, wc, fname) + } + fmt.Printf("%5d %5d %5d %s\n", tlc, tcc, twc, "total") +} diff --git a/functions/go.mod b/functions/go.mod new file mode 100644 index 0000000..e092793 --- /dev/null +++ b/functions/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.27.0 diff --git a/functions/main.go b/functions/main.go new file mode 100644 index 0000000..ba5ac9b --- /dev/null +++ b/functions/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func do(m1 *map[int]int) { + (*m1)[0] = 0 + + *m1 = make(map[int]int) + (*m1)[10] = 10 + fmt.Println("m1", *m1) +} + +func main() { + m := map[int]int{1: 21, 2: 56, 3: 45} + + fmt.Println("m", m) + do(&m) + fmt.Println("m", m) +} diff --git a/go.work b/go.work new file mode 100644 index 0000000..5cc5fb3 --- /dev/null +++ b/go.work @@ -0,0 +1,12 @@ +go 1.27.0 + +use ( + ./Composite_Types + ./For_If_Switch + ./courses + ./formatIO + ./functions + ./pointers + ./strings + ./types +) diff --git a/pointers/go.mod b/pointers/go.mod index a9eb3f6..e05e971 100644 --- a/pointers/go.mod +++ b/pointers/go.mod @@ -1,3 +1,3 @@ -module main +module letsgo/pointers -go 1.26.5 +go 1.27 diff --git a/strings/go.mod b/strings/go.mod index a9eb3f6..e5c7e83 100644 --- a/strings/go.mod +++ b/strings/go.mod @@ -1,3 +1,3 @@ -module main +module letsgo/strings -go 1.26.5 +go 1.27 diff --git a/types/go.mod b/types/go.mod index 96b3692..d1bcab7 100644 --- a/types/go.mod +++ b/types/go.mod @@ -1,3 +1,3 @@ module hello -go 1.26.5 +go 1.27