### Install Nano ID with go get Source: https://github.com/sixafter/nanoid/blob/main/README.md Run this command to install the Nano ID package. Use the import statement in your Go project to access the package. ```sh go get -u github.com/sixafter/nanoid ``` -------------------------------- ### Install yaml package with go get Source: https://github.com/sixafter/nanoid/blob/main/vendor/go.yaml.in/yaml/v3/README.md Command to install the go.yaml.in/yaml/v3 package. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Benchmark output example Source: https://github.com/sixafter/nanoid/blob/main/README.md Example output from running 'make bench' on an Apple M4 Max, showing benchmark results for allocations, read operations, and alphabet variations. ```shell make bench go test -bench=. -benchmem -memprofile=mem.out -cpuprofile=cpu.out goos: darwin goarch: arm64 pkg: github.com/sixafter/nanoid cpu: Apple M4 Max Benchmark_Allocations_Serial-16 14830308 74.10 ns/op 24 B/op 1 allocs/op Benchmark_Allocations_Parallel-16 87374926 13.93 ns/op 24 B/op 1 allocs/op Benchmark_Read_DefaultLength-16 21823753 54.01 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_2-16 49202928 24.94 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_3-16 47922843 25.39 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_5-16 44769436 27.30 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_13-16 31385779 37.98 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_21-16 24563296 49.45 ns/op 0 B/op 0 allocs/op Benchmark_Read_VaryingBufferSizes/BufferSize_34-16 17664668 67.80 ns/op 0 B/op 0 allocs/op Benchmark_Read_ZeroLengthBuffer-16 986404063 1.212 ns/op 0 B/op 0 allocs/op Benchmark_Read_Concurrent/Concurrency_1-16 23469319 50.41 ns/op 0 B/op 0 allocs/op Benchmark_Read_Concurrent/Concurrency_2-16 47287224 25.17 ns/op 0 B/op 0 allocs/op Benchmark_Read_Concurrent/Concurrency_4-16 89502978 13.22 ns/op 0 B/op 0 allocs/op Benchmark_Read_Concurrent/Concurrency_8-16 123994070 9.912 ns/op 0 B/op 0 allocs/op Benchmark_Read_Concurrent/Concurrency_16-16 209096799 5.656 ns/op 0 B/op 0 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen8-16 31861614 37.86 ns/op 8 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen16-16 22977042 51.86 ns/op 16 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen21-16 18545468 64.42 ns/op 24 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen32-16 15435464 76.98 ns/op 32 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen64-16 9426519 126.7 ns/op 64 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen2/IDLen128-16 5483312 217.6 ns/op 128 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen16/IDLen8-16 32191970 37.13 ns/op 8 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen16/IDLen16-16 22994911 51.37 ns/op 16 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen16/IDLen21-16 18733461 64.11 ns/op 24 B/op 1 allocs/op Benchmark_Alphabet_Varying_Serial/ASCII_AlphabetLen16/IDLen32-16 15541071 76.51 ns/op 32 B/op 1 allocs/op ``` -------------------------------- ### Install aes-ctr-drbg with go get Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Install the aes-ctr-drbg module using the Go package manager. ```bash go get -u github.com/sixafter/aes-ctr-drbg ``` -------------------------------- ### Install prng-chacha with go get Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Install the prng-chacha module using the Go package manager. ```bash go get -u github.com/sixafter/prng-chacha ``` -------------------------------- ### Output of YAML example Source: https://github.com/sixafter/nanoid/blob/main/vendor/go.yaml.in/yaml/v3/README.md The output generated by the preceding Go example, showing the unmarshalled struct and map, and their marshalled YAML representations. ```text --- t: {Easy! {2 [3 4]}} --- t dump: a: Easy! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 3 - 4 ``` -------------------------------- ### YAML unmarshal and marshal example in Go Source: https://github.com/sixafter/nanoid/blob/main/vendor/go.yaml.in/yaml/v3/README.md Complete Go program showing how to unmarshal YAML into a struct and a map, then marshal them back to YAML. Note that struct fields must be public for unmarshal to work. The output demonstrates the difference in flow style for the 'd' field when marshalling from a struct vs a map. ```go package main import ( "fmt" "log" "go.yaml.in/yaml/v3" ) var data = ` a: Easy! b: c: 2 d: [3, 4] ` // Note: struct fields must be public in order for unmarshal to // correctly populate the data. type T struct { A string B struct { RenamedC int `yaml:"c"` D []int `yaml:",flow"` } } func main() { t := T{} err := yaml.Unmarshal([]byte(data), &t) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- t:\n%v\n\n", t) d, err := yaml.Marshal(&t) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- t dump:\n%s\n\n", string(d)) m := make(map[interface{}]interface{}) err = yaml.Unmarshal([]byte(data), &m) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- m:\n%v\n\n", m) d, err = yaml.Marshal(&m) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- m dump:\n%s\n\n", string(d)) } ``` -------------------------------- ### Read random bytes using prng.Reader Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Use the global prng.Reader to read random bytes into a buffer. The example reads 64 bytes and prints the count and hex representation. ```go package main import ( "fmt" "github.com/sixafter/prng-chacha" ) func main() { buffer := make([]byte, 64) n, err := prng.Reader.Read(buffer) if err != nil { // Handle error } fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) } ``` -------------------------------- ### Clone and enter the repository Source: https://github.com/sixafter/nanoid/blob/main/CONTRIBUTING.md Clone the forked repository and change into the project directory. ```bash git clone https://github.com/sixafter/nanoid.git cd nanoid ``` -------------------------------- ### Run benchmarks with make bench Source: https://github.com/sixafter/nanoid/blob/main/README.md Executes the benchmark suite using the 'bench' make target. Output includes go test with memory and CPU profiling. ```shell make bench ``` -------------------------------- ### Use personalization and additional input with NewReader Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Creates a reader with personalization string and AES-256 key size, then reads random bytes. Requires handling errors from NewReader and Read. ```go package main import ( "fmt" "log" "github.com/sixafter/aes-ctr-drbg" ) func main() { r, err := ctrdrbg.NewReader( ctrdrbg.WithPersonalization([]byte("service-id-1")), ctrdrbg.WithKeySize(ctrdrbg.KeySize256), // AES-256 ) if err != nil { log.Fatalf("failed to create ctrdrbg.Reader: %v", err) } buf := make([]byte, 64) n, err := r.Read(buf) if err != nil { log.Fatalf("failed to read random bytes: %v", err) } fmt.Printf("Read %d random bytes: %x\n", n, buf) } ``` -------------------------------- ### Run lint and tests Source: https://github.com/sixafter/nanoid/blob/main/CONTRIBUTING.md Run the linter and test suite to ensure code quality. ```bash make lint make test ``` -------------------------------- ### Benchmark results for prng.Reader Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Output from running `make bench-csprng` on darwin/arm64 with Apple M4 Max, showing performance metrics for concurrent and serial random byte generation. ```shell make bench-csprng goos: darwin goarch: arm64 pkg: github.com/sixafter/prng-chacha cpu: Apple M4 Max BenchmarkPRNG_Concurrent_SyncPool_Baseline/G2-16 1000000000 0.5689 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G4-16 1000000000 0.5723 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G8-16 1000000000 0.5711 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G16-16 1000000000 0.5912 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G32-16 1000000000 0.5396 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G64-16 1000000000 0.5438 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_Concurrent_SyncPool_Baseline/G128-16 1000000000 0.5442 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_8Bytes-16 67387809 17.69 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_16Bytes-16 49208646 24.18 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_21Bytes-16 40782282 28.73 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_32Bytes-16 32735828 36.40 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_64Bytes-16 20102887 59.11 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_100Bytes-16 13549210 88.57 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_256Bytes-16 7663681 158.2 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_512Bytes-16 4108966 292.5 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_1000Bytes-16 2069100 577.4 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_4096Bytes-16 546291 2176 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadSerial/Serial_Read_16384Bytes-16 138847 8614 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_2Goroutines-16 315906483 3.780 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_4Goroutines-16 315760286 3.834 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_8Goroutines-16 319002478 3.759 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_16Goroutines-16 320004976 3.766 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_32Goroutines-16 319288269 3.771 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_64Goroutines-16 320027024 3.747 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_16Bytes_128Goroutines-16 322911223 3.718 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_21Bytes_2Goroutines-16 268402184 4.528 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_21Bytes_4Goroutines-16 267405596 4.472 ns/op 0 B/op 0 allocs/op BenchmarkPRNG_ReadConcurrent/Concurrent_Read_21Bytes_8Goroutines-16 266455920 4.447 ns/op 0 B/op 0 allocs/op ``` -------------------------------- ### Run UUID benchmarks with make bench-uuid Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Command to execute the UUID benchmark suite. It runs all benchmarks matching '^BenchmarkUUID_' with memory and CPU profiling enabled. ```shell make bench-uuid ``` ```shell go test -bench='^BenchmarkUUID_' -run=^$ -benchmem -memprofile=mem.out -cpuprofile=cpu.out . ``` -------------------------------- ### Verify release tarball and checksums with Cosign Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Fetch the latest release tag, download the tarball and checksums manifest with their Sigstore bundles, verify each blob with cosign verify-blob using the published public key, and confirm local integrity with shasum. On success, Cosign outputs 'Verified OK'. ```sh # Fetch the latest release tag from GitHub API (e.g., "v1.21.0") TAG=$(curl -s https://api.github.com/repos/sixafter/aes-ctr-drbg/releases/latest | jq -r .tag_name) # Remove leading "v" for filenames (e.g., "v1.21.0" -> "1.21.0") VERSION=${TAG#v} # --------------------------------------------------------------------- # Verify the source archive using Sigstore bundles # --------------------------------------------------------------------- # Download the release tarball and its signature bundle curl -LO "https://github.com/sixafter/aes-ctr-drbg/releases/download/${TAG}/aes-ctr-drbg-${VERSION}.tar.gz" curl -LO "https://github.com/sixafter/aes-ctr-drbg/releases/download/${TAG}/aes-ctr-drbg-${VERSION}.tar.gz.sigstore.json" # Verify the tarball with Cosign using the published public key cosign verify-blob \ --key "https://raw.githubusercontent.com/sixafter/aes-ctr-drbg/main/cosign.pub" \ --bundle "aes-ctr-drbg-${VERSION}.tar.gz.sigstore.json" \ "aes-ctr-drbg-${VERSION}.tar.gz" # --------------------------------------------------------------------- # Verify the checksums manifest using Sigstore bundles # --------------------------------------------------------------------- curl -LO "https://github.com/sixafter/aes-ctr-drbg/releases/download/${TAG}/checksums.txt" curl -LO "https://github.com/sixafter/aes-ctr-drbg/releases/download/${TAG}/checksums.txt.sigstore.json" cosign verify-blob \ --key "https://raw.githubusercontent.com/sixafter/aes-ctr-drbg/main/cosign.pub" \ --bundle "checksums.txt.sigstore.json" \ "checksums.txt" # --------------------------------------------------------------------- # Confirm local artifact integrity # --------------------------------------------------------------------- shasum -a 256 -c checksums.txt ``` ```shell Verified OK ``` -------------------------------- ### Import Nano ID package Source: https://github.com/sixafter/nanoid/blob/main/README.md Import the Nano ID package in your Go code to use its functions. ```go import "github.com/sixafter/nanoid" ``` -------------------------------- ### Verify module checksum for the latest version Source: https://github.com/sixafter/nanoid/blob/main/CHANGELOG/CHANGELOG-1.x.md Use this command to verify the Go module checksum against the latest version, as mentioned in the 1.57.0 changelog. ```bash make module-verify ``` -------------------------------- ### Create a new branch Source: https://github.com/sixafter/nanoid/blob/main/CONTRIBUTING.md Create a new branch for your changes. ```bash git checkout -b feature/your-feature-name ``` -------------------------------- ### Stage and commit changes Source: https://github.com/sixafter/nanoid/blob/main/CONTRIBUTING.md Stage all changes and commit with a descriptive message. ```bash git add . git commit -m "Add descriptive commit message" ``` -------------------------------- ### Generate Nano ID with default settings Source: https://github.com/sixafter/nanoid/blob/main/README.md Generates a Nano ID using default settings (predefined alphabet and default length). The output shows a sample generated ID. ```go package main import ( "fmt" "github.com/sixafter/nanoid" ) func main() { id, err := nanoid.New() if err != nil { panic(err) } fmt.Println("Generated ID:", id) } ``` ```bash Generated ID: mGbzQkkPBidjL4IP_MwBM ``` -------------------------------- ### make bench-uuid output Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Output from running the UUID benchmark comparing default random reader and CSPRNG-based generation. Shows performance metrics for serial, parallel, and concurrent scenarios. ```shell make bench-uuid goos: darwin goarch: arm64 pkg: github.com/sixafter/prng-chacha cpu: Apple M4 Max BenchmarkUUID_v4_Default_Serial-16 6239547 183.6 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Parallel-16 2614206 457.2 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_4-16 2867928 419.2 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_8-16 2520130 482.1 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_16-16 2617567 455.6 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_32-16 2312065 521.1 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_64-16 2300226 533.1 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_128-16 2300107 523.4 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_256-16 2331600 523.7 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Serial-16 30584091 37.70 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Parallel-16 209297205 5.871 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_4-16 100000000 11.36 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_8-16 150149610 7.712 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_16-16 203733687 5.944 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_32-16 205883962 5.788 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_64-16 208636114 5.735 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_128-16 212263852 5.705 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CSPRNG_Concurrent/Goroutines_256-16 204421857 5.794 ns/op 16 B/op 1 allocs/op PASS ok github.com/sixafter/prng-chacha 31.142s ``` -------------------------------- ### Clone the forked repository Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/CONTRIBUTING.md Clone the forked repository to your local machine and navigate into the project directory. ```bash git clone https://github.com/sixafter/aes-ctr-drbg.git cd aes-ctr-drbg ``` -------------------------------- ### Cosign verification script for nanoid release artifacts Source: https://github.com/sixafter/nanoid/blob/main/README.md Downloads the release tarball and checksums manifest with their Sigstore bundles, then verifies each with `cosign verify-blob` using the published public key. Finally confirms local artifact integrity with `shasum -a 256 -c checksums.txt`. Requires `curl`, `jq`, `cosign`, and `shasum`. ```sh # Fetch the latest release tag from GitHub API (e.g., "v1.66.0") TAG=$(curl -s https://api.github.com/repos/sixafter/nanoid/releases/latest | jq -r .tag_name) # Remove leading "v" for filenames (e.g., "v1.66.0" -> "1.66.0") VERSION=${TAG#v} # --------------------------------------------------------------------- # Verify the source archive using Sigstore bundles # --------------------------------------------------------------------- # Download the release tarball and its signature bundle curl -LO "https://github.com/sixafter/nanoid/releases/download/${TAG}/nanoid-${VERSION}.tar.gz" curl -LO "https://github.com/sixafter/nanoid/releases/download/${TAG}/nanoid-${VERSION}.tar.gz.sigstore.json" # Verify the tarball with Cosign using the published public key cosign verify-blob \ --key "https://raw.githubusercontent.com/sixafter/nanoid/main/cosign.pub" \ --bundle "nanoid-${VERSION}.tar.gz.sigstore.json" \ "nanoid-${VERSION}.tar.gz" # --------------------------------------------------------------------- # Verify the checksums manifest using Sigstore bundles # --------------------------------------------------------------------- curl -LO "https://github.com/sixafter/nanoid/releases/download/${TAG}/checksums.txt" curl -LO "https://github.com/sixafter/nanoid/releases/download/${TAG}/checksums.txt.sigstore.json" cosign verify-blob \ --key "https://raw.githubusercontent.com/sixafter/nanoid/main/cosign.pub" \ --bundle "checksums.txt.sigstore.json" \ "checksums.txt" # --------------------------------------------------------------------- # Confirm local artifact integrity # --------------------------------------------------------------------- shasum -a 256 -c checksums.txt ``` -------------------------------- ### Run lint and tests Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/CONTRIBUTING.md Runs the project's linting and test commands to ensure code quality and that all tests pass before committing. ```bash make lint make test ``` -------------------------------- ### Verify module checksum for a specific tag Source: https://github.com/sixafter/nanoid/blob/main/CHANGELOG/CHANGELOG-1.x.md Use this command to verify the Go module checksum against a specific version tag, as mentioned in the 1.57.0 changelog. Replace the tag value with the desired version. ```bash TAG=v1.56.0 make module-verify ``` -------------------------------- ### Cosign verification success output Source: https://github.com/sixafter/nanoid/blob/main/README.md Expected output when Cosign successfully verifies the release artifacts. The command prints "Verified OK" to indicate the signature and bundle are valid. ```shell Verified OK ``` -------------------------------- ### Customize alphabet and length with WithAlphabet Source: https://github.com/sixafter/nanoid/blob/main/README.md Creates a generator with a custom alphabet and length hint using WithAlphabet and WithLengthHint. The output shows a sample generated ID. ```go package main import ( "fmt" "github.com/sixafter/nanoid" ) func main() { // Define a custom alphabet alphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // Create a new generator with a custom alphabet and length hint gen, err := nanoid.NewGenerator( nanoid.WithAlphabet(alphabet), nanoid.WithLengthHint(10), ) if err != nil { fmt.Println("Error creating Nano ID generator:", err) return } // Generate a Nano ID using the custom generator id, err := gen.New() // or gen.NewWithLength(10) if err != nil { fmt.Println("Error generating Nano ID:", err) return } fmt.Println("Generated ID:", id) } ``` ```bash Generated ID: G5J8K2M0QZ ``` -------------------------------- ### Customize random number generator with WithRandReader Source: https://github.com/sixafter/nanoid/blob/main/README.md Creates a generator with a custom random number generator using WithRandReader. The output shows a sample generated ID. ```go package main import ( "crypto/rand" "fmt" "github.com/sixafter/nanoid" ) func main() { // Create a new generator with a custom random number generator gen, err := nanoid.NewGenerator( nanoid.WithRandReader(rand.Reader), ) if err != nil { fmt.Println("Error creating Nano ID generator:", err) return } // Generate a Nano ID using the custom generator with // the default length. id, err := gen.New() if err != nil { fmt.Println("Error generating Nano ID:", err) return } fmt.Println("Generated ID:", id) } ``` ```bash Generated ID: A8I8K3J0QY ``` -------------------------------- ### Run ctrdrbg.Reader benchmarks with make bench Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Command to run the DRBG benchmarks using the Makefile target 'bench'. It executes the Go benchmark suite for the BenchmarkDRBG_ functions with memory profiling enabled. ```shell make bench ``` ```shell go test -bench='^BenchmarkDRBG_' -run=^$ -benchmem -memprofile=mem.out -cpuprofile=cpu.out . ``` -------------------------------- ### Generate secure random bytes with NewReader and KeySize256 Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Creates a new reader with AES-256 key size and reads 64 random bytes. Requires handling errors from NewReader and Read. ```go package main import ( "fmt" "log" "github.com/sixafter/aes-ctr-drbg" ) func main() { // Example: AES-256 (32 bytes) key r, err := ctrdrbg.NewReader(ctrdrbg.WithKeySize(ctrdrbg.KeySize256)) if err != nil { log.Fatalf("failed to create ctrdrbg.Reader: %v", err) } buf := make([]byte, 64) n, err := r.Read(buf) if err != nil { log.Fatalf("failed to read random bytes: %v", err) } fmt.Printf("Read %d random bytes: %x\n", n, buf) } ``` -------------------------------- ### Clone the forked repository Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/CONTRIBUTING.md Clones the prng-chacha repository from GitHub and changes into the project directory. This is the first step after forking the repository. ```bash git clone https://github.com/sixafter/prng-chacha.git cd prng-chacha ``` -------------------------------- ### Push branch to fork Source: https://github.com/sixafter/nanoid/blob/main/CONTRIBUTING.md Push the branch to your forked repository. ```bash git push origin feature/your-feature-name ``` -------------------------------- ### BenchmarkPRNG_ReadExtremeSizes output Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Output from running the benchmark for extreme read sizes with concurrent goroutines. Shows performance metrics for 104857600 bytes with 128 goroutines. ```shell BenchmarkPRNG_ReadExtremeSizes/Concurrent_Read_Extreme_104857600Bytes_128Goroutines-16 284 4138645 ns/op 1123 B/op 18 allocs/op PASS ok github.com/sixafter/prng-chacha 377.422s ``` -------------------------------- ### Generate Nano ID with custom length Source: https://github.com/sixafter/nanoid/blob/main/README.md Generates a Nano ID with a custom length using NewWithLength. The output shows a sample generated ID. ```go package main import ( "fmt" "github.com/sixafter/nanoid" ) func main() { id, err := nanoid.NewWithLength(10) if err != nil { panic(err) } fmt.Println("Generated ID:", id) } ``` ```bash Generated ID: 1A3F5B7C9D ``` -------------------------------- ### Use Nano ID as io.Reader Source: https://github.com/sixafter/nanoid/blob/main/README.md Reads a Nano ID into a byte buffer using the io.Reader interface. The default length is 21. The output shows a sample generated ID. ```go package main import ( "fmt" "io" "github.com/sixafter/nanoid" ) func main() { // Nano ID default length is 21 buf := make([]byte, nanoid.DefaultLength) // Read a Nano ID into the buffer _, err := nanoid.Read(buf) if err != nil && err != io.EOF { panic(err) } // Convert the byte slice to a string id := string(buf) fmt.Printf("Generated ID: %s\n", id) } ``` ```bash Generated ID: 2mhTvy21bBZhZcd80ZydM ``` -------------------------------- ### UUID benchmark results output Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Output from running the UUID benchmarks on darwin/arm64 with an Apple M4 Max CPU. Shows ns/op, B/op, and allocs/op for both default crypto/rand and CTRDRBG implementations across serial, parallel, and concurrent scenarios. ```shell goos: darwin goarch: arm64 pkg: github.com/sixafter/aes-ctr-drbg cpu: Apple M4 Max BenchmarkUUID_v4_Default_Serial-16 5764681 207.8 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Parallel-16 2523262 467.4 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_2-16 3328860 360.3 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_4-16 2731453 436.8 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_8-16 2447664 491.7 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_16-16 2558335 473.6 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_32-16 2366698 510.7 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_64-16 2340867 511.9 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_128-16 2345401 510.6 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_Default_Concurrent/Goroutines_256-16 2329904 515.1 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Serial-16 23044700 50.41 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Parallel-16 94280326 12.50 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_2-16 43251036 26.58 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_4-16 80453218 14.85 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_8-16 100000000 10.95 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_16-16 139321384 8.189 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_32-16 146813631 8.137 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_64-16 144867888 8.253 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_128-16 147125661 8.219 ns/op 16 B/op 1 allocs/op BenchmarkUUID_v4_CTRDRBG_Concurrent/Goroutines_256-16 143012491 8.396 ns/op 16 B/op 1 allocs/op PASS ok github.com/sixafter/aes-ctr-drbg 32.857s ``` -------------------------------- ### Generate secure random bytes with ctrdrbg.Reader Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Uses the package-level Reader to read 64 random bytes. Requires importing the module and handling errors from Read. ```go package main import ( "fmt" "log" "github.com/sixafter/aes-ctr-drbg" ) func main() { buf := make([]byte, 64) n, err := ctrdrbg.Reader.Read(buf) if err != nil { log.Fatalf("failed to read random bytes: %v", err) } fmt.Printf("Read %d random bytes: %x\n", n, buf) } ``` -------------------------------- ### Removed Buffer interface Source: https://github.com/sixafter/nanoid/blob/main/CHANGELOG/CHANGELOG-1.x.md Removed in version 1.13.2 as unused. The interface was a type constraint allowing either []byte or []rune. ```go // Buffer is a type constraint that allows either []byte or []rune. type Buffer interface { ~[]byte | ~[]rune } ``` -------------------------------- ### Create a new branch for changes Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/CONTRIBUTING.md Creates a new Git branch with a descriptive feature name. This isolates your changes from the main branch. ```bash git checkout -b feature/your-feature-name ``` -------------------------------- ### Replace default random reader for UUID generation Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/README.md Set prng.Reader as the global random source for github.com/google/uuid, then generate a v4 UUID. ```go package main import ( "fmt" "github.com/google/uuid" "github.com/sixafter/prng-chacha" ) func main() { // Set the global random reader for UUID generation uuid.SetRand(prng.Reader) // Generate a new v4 UUID u := uuid.New() fmt.Printf("Generated UUID: %s\n", u) } ``` -------------------------------- ### Benchmark results for ctrdrbg.Reader Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/aes-ctr-drbg/README.md Output from the benchmark command showing performance metrics for various DRBG read operations. Includes baseline concurrent benchmarks and serial/concurrent read benchmarks for different buffer sizes and goroutine counts. ```shell goos: darwin goarch: arm64 pkg: github.com/sixafter/aes-ctr-drbg cpu: Apple M4 Max BenchmarkDRBG_SyncPool_Baseline_Concurrent/G2-16 1000000000 0.6112 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G4-16 1000000000 0.6134 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G8-16 1000000000 0.5971 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G16-16 1000000000 0.5937 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G32-16 1000000000 0.5700 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G64-16 1000000000 0.5587 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_SyncPool_Baseline_Concurrent/G128-16 1000000000 0.5644 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_16Bytes-16 34062441 34.18 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_32Bytes-16 29895489 39.54 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_64Bytes-16 24042694 50.42 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_256Bytes-16 10366684 115.3 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_512Bytes-16 5998489 200.1 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_4096Bytes-16 871158 1377 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Serial/Serial_Read_16384Bytes-16 222878 5376 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_2Goroutines-16 19962072 85.99 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_4Goroutines-16 19596702 84.39 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_8Goroutines-16 19851349 80.85 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_16Goroutines-16 19654436 64.24 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_32Goroutines-16 19521876 81.78 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_64Goroutines-16 19818331 82.29 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_16Bytes_128Goroutines-16 20155250 82.61 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_2Goroutines-16 18829485 88.29 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_4Goroutines-16 19666596 88.22 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_8Goroutines-16 19722001 83.93 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_16Goroutines-16 19440373 85.58 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_32Goroutines-16 19804376 84.60 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_64Goroutines-16 19879699 84.29 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_32Bytes_128Goroutines-16 19940580 82.55 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_2Goroutines-16 18446626 80.89 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_4Goroutines-16 19594609 84.27 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_8Goroutines-16 19475618 84.79 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_16Goroutines-16 19886919 85.68 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_32Goroutines-16 19558533 81.82 ns/op 0 B/op 0 allocs/op BenchmarkDRBG_Read_Concurrent/Concurrent_Read_64Bytes_64Goroutines-16 19842116 82.01 ns/op 0 B/op 0 allocs/op ``` -------------------------------- ### Commit changes Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/CONTRIBUTING.md Stages all changes and commits them with a descriptive message. This is part of the standard Git workflow for contributing. ```bash git add . git commit -m "Add descriptive commit message" ``` -------------------------------- ### Push changes to fork Source: https://github.com/sixafter/nanoid/blob/main/vendor/github.com/sixafter/prng-chacha/CONTRIBUTING.md Pushes the local branch to the forked repository on GitHub, making the changes available for a pull request. ```bash git push origin feature/your-feature-name ```