Skip to content

refactor: eliminate small-package smell#85

Merged
elevran merged 4 commits into
mainfrom
pkg-restructure
Jul 8, 2026
Merged

refactor: eliminate small-package smell#85
elevran merged 4 commits into
mainfrom
pkg-restructure

Conversation

@elevran

@elevran elevran commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Delete internal/httputil — inline writeJSON/writeError as unexported helpers directly in cmd/proxy and internal/server; no shared abstraction needed for two call sites
  • Delete internal/metrics — fold the two Prometheus vars and Register() into internal/server as RegisterMetrics(); only internal/server/middleware.go and the two entry points ever touched it
  • Move internal/inferencecmd/proxy/inference/ — demo/proxy-only code with no consumers outside cmd/proxy; keeping it under internal/ implied broader reuse that doesn't exist
  • Split internal/configinternal/charonconfig + internal/proxyconfigCharonOptions and ByteSize live in charonconfig; ProxyOptions in proxyconfig; each owns its own private YAML loader and TelemetryOptions; charon's listen address is passed as a plain string so there is no cross-package dependency
  • Fix .gitignore — replace bare charon (which also excluded cmd/charon/ source) with rooted /charon and /proxy

All packages build clean and make presubmit passes.

Test plan

  • make presubmit passes (fmt + vet + tests)
  • cmd/proxy/inference tests pass independently
  • internal/charonconfig and internal/proxyconfig tests cover defaults, file loading, CLI override, and strict-parse rejection

elevran added 2 commits July 8, 2026 18:08
- Delete internal/httputil: inline writeJSON/writeError as unexported
  helpers in cmd/proxy (httputil.go) and internal/server (httputil.go)

- Delete internal/metrics: fold HTTPRequestsTotal, HTTPRequestDuration,
  and Register() into internal/server as unexported vars + RegisterMetrics()

- Move internal/inference → cmd/proxy/inference/ (proxy-only demo code;
  no other package used it)

- Split internal/config into internal/charonconfig (CharonOptions +
  ByteSize) and internal/proxyconfig (ProxyOptions); each holds its own
  private YAML loader and TelemetryOptions; charon.listen is passed as a
  plain string to proxyconfig so there is no cross-package dependency

Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Replace bare 'charon' (which also matched cmd/charon/) with rooted
/charon and /proxy so only the top-level binaries are excluded and
cmd/* source directories are tracked normally.

Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Comment thread .gitignore Outdated
Comment thread cmd/charon/main.go Outdated
Comment thread cmd/proxy/main.go Outdated
Comment thread internal/charonconfig/charonconfig.go
Comment thread internal/charonconfig/charonconfig.go Outdated
Comment thread internal/proxyconfig/proxyconfig.go
Comment thread internal/proxyconfig/testdata/bytesize.yaml Outdated
Comment thread internal/charonconfig/testdata/invalid.yaml Outdated
Comment thread internal/charonconfig/testdata/bytesize.yaml Outdated
Comment thread internal/server/metrics.go Outdated

@elevran elevran left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted.

Comment thread cmd/proxy/httputil.go Outdated
Comment thread internal/charonconfig/charonconfig_test.go Outdated
Comment thread internal/charonconfig/charonconfig_test.go Outdated
Comment thread internal/charonconfig/charonconfig.go Outdated
Comment thread internal/proxyconfig/proxyconfig.go Outdated
Comment thread internal/charonconfig/charonconfig.go Outdated
elevran added 2 commits July 8, 2026 20:13
- Delete internal/httputil: inline writeJSON/writeError as unexported
  helpers in cmd/proxy and internal/server (WriteJSON/WriteError exported
  from internal/server so cmd/proxy can use them without a separate pkg)

- Delete internal/metrics: fold HTTPRequestsTotal, HTTPRequestDuration,
  and Register() into internal/server as unexported vars + RegisterMetrics()

- Move TelemetryOptions to internal/telemetry as Options; both charonconfig
  and proxyconfig import it instead of defining their own copy

- Split internal/config into internal/charonconfig (CharonOptions +
  ByteSize) and internal/proxyconfig (ProxyOptions); each has its own
  private YAML loader with strict unmarshalling; no shared config file
  between the two processes — all json.RawMessage absorbers removed

- Simplify proxyconfig: collapse fileConfigRaw+fileConfig into a single
  fileConfig struct; fileCharonSection holds only Listen (no storage/workers
  absorbers); applyFileDefaults called post-unmarshal only

- Fix .gitignore: build outputs go under ./bin/; remove stale /charon and
  /proxy entries that blocked staging source files

- Update Makefile: build targets write to ./bin/; add clean target

Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Remove all testdata/*.yaml files from charonconfig and proxyconfig.
Replace file references with inline []byte literals written to temp files
via a configFromBytes helper. Expand strict-parse rejection tests into
table-driven subtests covering unknown keys at each nesting level.

Signed-off-by: Etai Lev Ran <elevran@gmail.com>
@elevran elevran merged commit 847f44f into main Jul 8, 2026
6 checks passed
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.

1 participant