Skip to content

Instantly share code, notes, and snippets.

@lechuhuuha
lechuhuuha / main.go
Created August 23, 2025 14:59
value-receive and pointer-receive method
package main
import "fmt"
type Counter struct{ n int }
// ---------------------
// ⬇ value-receiver method
// ---------------------
func (c Counter) Value() int { return c.n }
@lechuhuuha
lechuhuuha / Capacity pitfall.go
Created August 23, 2025 15:35
slice pitfall
package main
import "fmt"
func main() {
a := [5]int{1, 2, 3, 4, 5}
s1 := a[0:3] // len=3 cap=5
s2 := a[3:5] // len=2 cap=2
fmt.Println("initial a :", a) // [1 2 3 4 5]
@lechuhuuha
lechuhuuha / main.go
Created August 23, 2025 17:24
auto-marshals
package main
import (
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"log"
_ "github.com/lib/pq"