Skip to content

Modernize heffalump: any, math/rand/v2#1

Merged
bdk38 merged 2 commits intomainfrom
copilot/modernize-heffalump-package
Mar 6, 2026
Merged

Modernize heffalump: any, math/rand/v2#1
bdk38 merged 2 commits intomainfrom
copilot/modernize-heffalump-package

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 6, 2026

Brings the heffalump package up to current Go idioms using features available since the module's declared minimum (Go 1.24).

Changes

  • heffalump/heffalump.gosync.Pool New func: interface{}any; drop intermediate b variable
  • heffalump/markov.gomath/randmath/rand/v2; rand.Intnrand.IntN
// Before
pool: &sync.Pool{New: func() interface{} {
    b := make([]byte, buffsize)
    return b
}},

// After
pool: &sync.Pool{New: func() any {
    return make([]byte, buffsize)
}},
Original prompt

Objective

Modernize the heffalump package code to use current Go language features and idioms while maintaining backward compatibility and functionality.

Background

The heffalump package hasn't been updated in several years and uses older Go patterns. This modernization will make the code more maintainable and align with current Go best practices.

Required Changes

1. Update interface{} to any (Go 1.18+)

File: heffalump/markov.go

The sync.Pool initialization currently uses the older interface{} type. Update to use any:

Current code (around line 30-35):

pool: &sync.Pool{New: func() interface{} {
    b := make([]byte, buffsize)
    return b
}},

Should become:

pool: &sync.Pool{New: func() any {
    return make([]byte, buffsize)
}},

2. Modernize math/rand usage

Files: heffalump/markov.go

Currently uses the legacy math/rand package. Consider updating to math/rand/v2 (Go 1.22+) for better API and performance, or at minimum use local random generators instead of global functions.

Current pattern:

import "math/rand"
// ...
rand.Intn(length)

Modern approach (if Go version supports it):

import "math/rand/v2"
// Use local rand.Rand instance or the improved v2 API

3. Code simplifications

Review the buffer pool return statement and ensure it's using the most concise modern Go syntax.

Requirements

  • ✅ All existing tests must pass
  • ✅ Maintain exact same public API (no breaking changes)
  • ✅ Preserve all functionality (Markov generation, buffer pooling, HTTP streaming)
  • ✅ Keep MIT license attribution
  • ✅ Check Go version in go.mod - ensure it's set to minimum required version for features used (1.18+ for any, 1.22+ for math/rand/v2)

Testing

After changes:

  1. Run existing tests: go test ./heffalump/...
  2. Verify the HellPot server still starts and responds correctly
  3. Ensure Markov text generation still produces output

Files to Modify

  • heffalump/markov.go - Main modernization target
  • Possibly go.mod - Verify/update Go version if needed

Notes

  • The non-cryptographic random number generation is acceptable for this use case (text generation)
  • The buffer pool pattern with sync.Pool is already modern and should be preserved
  • This is a code modernization only - no functional changes to the honeypot behavior

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: bdk38 <244781262+bdk38@users.noreply.github.com>
Copilot AI changed the title [WIP] Modernize heffalump package code for Go best practices Modernize heffalump: any, math/rand/v2 Mar 6, 2026
Copilot finished work on behalf of bdk38 March 6, 2026 14:23
@bdk38 bdk38 marked this pull request as ready for review March 6, 2026 14:25
@bdk38 bdk38 merged commit 37bac3e into main Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants