Better HTTP server routing in Go 1.22
How did this kind of syntax become so popular? I think express is the first to do the scheme of:<p><pre><code>    app.handleGet(&quot;&#x2F;route&#x2F;goes&#x2F;here&quot;, (req, res) =&gt; {

    });
</code></pre>
Which seems like it&#x27;s useful for making really quick and dirty micro-services (nano-services, even), but I still vastly prefer the more declarative and modular schemes of bootstrap or asp.net:<p><pre><code>    &#x2F;&#x2F; Middleware automatically routes &quot;&#x2F;Foo&quot; to FooController
    [Controller]
    public class FooController : Controller
    {
        private IMyService _service { get; init; }
        
        &#x2F;&#x2F; Declarative dependency injection
        FooController(IMyService service)
        {
            this._service = service;
        }

        &#x2F;&#x2F; HTTP Method and Route are declarative
        [HttpGet(&quot;&#x2F;&quot;)]
        public ActionResult GetBar([FromBody] Model myModel)
                                 &#x2F;&#x2F; ^ automatic user input validation using reflection
        {
            this._service.create(myModel); &#x2F;&#x2F; or whatever you need to do
            return Ok();
        }
    }
</code></pre>
This has always seemed way more maintainable to me. Even microsoft has added the ability to do these quick and dirty HTTP routing methods along with top level statements.