Learning about formatIO

This commit is contained in:
Zack
2026-09-02 16:31:26 -04:00
parent d307eb2698
commit 1bae4e44b0
14 changed files with 98 additions and 11 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
module main module letsgo/composite_types
go 1.26.5 go 1.27
+2 -2
View File
@@ -1,3 +1,3 @@
module main.go module letsgo/for_if_switch
go 1.23.1 go 1.27
+2 -2
View File
@@ -1,3 +1,3 @@
module hello module letsgo/courses
go 1.23.1 go 1.27
+4
View File
@@ -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.
+2
View File
@@ -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.
+4
View File
@@ -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.
+3
View File
@@ -0,0 +1,3 @@
module letsgo/formatio
go 1.27
+40
View File
@@ -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")
}
+3
View File
@@ -0,0 +1,3 @@
module main
go 1.27.0
+19
View File
@@ -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)
}
+12
View File
@@ -0,0 +1,12 @@
go 1.27.0
use (
./Composite_Types
./For_If_Switch
./courses
./formatIO
./functions
./pointers
./strings
./types
)
+2 -2
View File
@@ -1,3 +1,3 @@
module main module letsgo/pointers
go 1.26.5 go 1.27
+2 -2
View File
@@ -1,3 +1,3 @@
module main module letsgo/strings
go 1.26.5 go 1.27
+1 -1
View File
@@ -1,3 +1,3 @@
module hello module hello
go 1.26.5 go 1.27