Skip to content

feat: add host binding configuration option#920

Open
FLASH2332 wants to merge 3 commits into
OneBusAway:mainfrom
FLASH2332:feature/binding-address
Open

feat: add host binding configuration option#920
FLASH2332 wants to merge 3 commits into
OneBusAway:mainfrom
FLASH2332:feature/binding-address

Conversation

@FLASH2332
Copy link
Copy Markdown
Contributor

@FLASH2332 FLASH2332 commented May 10, 2026

Adds a host field to the configuration file to control the server's binding address, allowing operators to restrict the server to a specific interface (e.g. 127.0.0.1) instead of binding to all interfaces (0.0.0.0).

The field is optional and defaults to 0.0.0.0 to preserve existing behavior.

image

Fixes #896

@aaronbrethorst
@chrisls121

Summary by CodeRabbit

  • New Features
    • Added -host command-line flag and host configuration field, enabling configuration of the server bind address.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

📝 Walkthrough

Walkthrough

This PR adds support for configuring the HTTP server bind address via a new host parameter. Changes include schema definition, type structures, CLI flag, and server binding logic. The host defaults to 0.0.0.0 when unspecified, enabling both explicit host configuration and backward-compatible behavior.

Changes

Host Address Configuration

Layer / File(s) Summary
Configuration Schema Contract
config.schema.json
Schema defines host as a string property with default "0.0.0.0" and description. First example includes host: "127.0.0.1".
Configuration Data Types
internal/appconf/config.go, internal/appconf/json_config.go
Config struct gains Host field. JSONConfig adds Host field with JSON tag. ToAppConfig() maps j.Host to the returned Config.Host.
CLI Flag and Server Binding
cmd/api/main.go, cmd/api/app.go
New -host CLI flag sets cfg.Host. CreateServer defaults empty host to "0.0.0.0" and binds server to "<host>:<port>" instead of ":<port>".
Example Configuration
config.example.json
Example configuration file includes host setting with value "127.0.0.1".

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a host binding configuration option across multiple files and the configuration system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/appconf/json_config.go (1)

37-37: ⚡ Quick win

Consider defaulting Host in setDefaults() for config-layer consistency.

Right now the schema advertises a 0.0.0.0 default, but JSON config defaults do not set it explicitly. Centralizing that default in setDefaults() keeps behavior/documentation aligned across consumers.

♻️ Suggested tweak
 func (j *JSONConfig) setDefaults() {
 	if j.Port == 0 {
 		j.Port = 4000
 	}
+	if j.Host == "" {
+		j.Host = "0.0.0.0"
+	}
 	if j.Env == "" {
 		j.Env = "development"
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/appconf/json_config.go` at line 37, The config struct's Host field
is advertised to default to "0.0.0.0" but that default isn't being applied in
setDefaults(); update the setDefaults() function to explicitly set Host =
"0.0.0.0" when Host is empty (or zero-valued) so JSON-configured instances align
with the schema/documentation—look for the Host field on the config struct and
the setDefaults() method to add this conditional assignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/api/app.go`:
- Around line 153-157: The local variable host defined in app.go (host :=
cfg.Host with fallback to "0.0.0.0") is never used which causes a compile error;
update the server startup to use that host variable instead of cfg.Host (e.g.,
replace any direct use of cfg.Host when constructing the server address/Addr
with the local host variable), or alternatively remove the unused host variable
and implement the fallback directly where the server address is built so the
effective host value is used by the http.Server/start call.

---

Nitpick comments:
In `@internal/appconf/json_config.go`:
- Line 37: The config struct's Host field is advertised to default to "0.0.0.0"
but that default isn't being applied in setDefaults(); update the setDefaults()
function to explicitly set Host = "0.0.0.0" when Host is empty (or zero-valued)
so JSON-configured instances align with the schema/documentation—look for the
Host field on the config struct and the setDefaults() method to add this
conditional assignment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33c06213-6379-4f77-aa5b-5fc8eaed1b20

📥 Commits

Reviewing files that changed from the base of the PR and between f89f0fd and 8addaaa.

📒 Files selected for processing (6)
  • cmd/api/app.go
  • cmd/api/main.go
  • config.example.json
  • config.schema.json
  • internal/appconf/config.go
  • internal/appconf/json_config.go

Comment thread cmd/api/app.go
fix : host reference
@FLASH2332 FLASH2332 force-pushed the feature/binding-address branch from 8d1c11c to f46490b Compare May 10, 2026 03:54
@sonarqubecloud
Copy link
Copy Markdown

@FLASH2332
Copy link
Copy Markdown
Contributor Author

Shall I update the appropriate comments and documentation for this addition ?

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.

Binding Address Configuration

1 participant