Skip to content

Refactor: encapsulate WebServerConfig fields and add constructor - #5

Open
Rayato159 wants to merge 1 commit into
MalekiRe:mainfrom
Rayato159:web_server_config_refactoring
Open

Refactor: encapsulate WebServerConfig fields and add constructor#5
Rayato159 wants to merge 1 commit into
MalekiRe:mainfrom
Rayato159:web_server_config_refactoring

Conversation

@Rayato159

Copy link
Copy Markdown

This PR improves the encapsulation of WebServerConfig by making the ip and port fields private and exposing a clear constructor for external use.

🔨 Changes:

  • ip and port are now private
  • Added WebServerConfig::new(ip: IpAddr, port: u16) for construction
  • Updated test to validate instantiation
  • Maintains backward compatibility via Default implementation

Why ?

As discussed in Issue #4, public fields can lead to:

  • Accidental external mutation
  • Unclear API usage
  • Reduced flexibility for future validation/extensions

This refactor helps establish a more robust and consistent API surface.

Releated Issue: #4

Let me know if you’d prefer accessor methods ip, port added as well, happy to include.

PS. This is tested screenshot, I have changed from default WebServerConfig from Addr: 127.0.0.1, Port: 8080 to Addr: 127.0.0.1, Port: 3000 and It's works.

image

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