Skip to content

Refactor run method to simplify usage and improve flexibility#3

Open
josemachava wants to merge 1 commit intoGraHms:mainfrom
wolkehost:feat/set-default-port
Open

Refactor run method to simplify usage and improve flexibility#3
josemachava wants to merge 1 commit intoGraHms:mainfrom
wolkehost:feat/set-default-port

Conversation

@josemachava
Copy link

Run method in the application struct to simplify its usage by removing the need for explicitly passing an address. The method now defaults to :8000 but still allows overriding it if needed.

Changes Introduced

  • The Run method no longer requires an argument; it now uses a variadic parameter (address ...string).
  • If no address is provided, the server defaults to :8000.
  • If an address is provided, it ensures proper formatting (e.g., adding ":" if only a port is given).
  • The method no longer returns an error; instead, it logs a fatal error if the server fails to start.

Why This Change?

  • Simplifies the API by allowing app.Run() with a default port.
  • Reduces redundant code where users previously had to pass ":8000" manually.
  • Retains flexibility for specifying a custom address when needed.

Usage Example
Now, users can start the server with a default address:

app.Run() // Runs on :8000

Or specify a custom port/address:

app.Run(":8080")        // Runs on :8080  
app.Run("0.0.0.0:9090") // Runs on 0.0.0.0:9090  

Impact
This change makes the API cleaner and more user-friendly while maintaining flexibility for custom configurations.

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