It is recommended to set fasthttp.Server and fasthttprouter.Router directly via atruego
imxxiv opened this issue ยท 8 comments
Atreugo is really a great web framework. In order to implement the function of custom static file service, savsgio also specially modified the code of fasthttprouter. It can be seen that savsgio is really responsible for the code. And setting parameters in the function is more flexible than setting the parameters in cfg, which is a better solution.
These days have been learning the source code of atreugo, atreugo integrates a lot of functions required by web development, fasthttp, reuseport, fasthttprouter, logger, json.
config := &atreugo.Config{
Host: "0.0.0.0",
Port: 8000,
}
server := atreugo.New(config)
For the above code, I understand that when set config, run atreugo.New (config), in fact, according to the parameters set in the config, initialize fasthttp.Server and fasthttprouter.Router
However, in atreugo, the parameters that can be adjusted are only the fields in config, and if fasthttp.Server and fasthttprouter.Router have new function parameters, they need to be adjusted by atreugo.
I suggest that you can directly adjust the initial parameters of fasthttp.Server and fasthttprouter.Router in atreugo, for example:
config := &atreugo.Config{
Host: "0.0.0.0",
Port: 8000,
}
server := atreugo.New(config)
server.Router.Router.RedirectTrailingSlash = false
server.Server.NoDefaultContentType = true
This allows you to fine-tune the settings of fasthttp.Server and fasthttprouter.Router, but now atreugo, these are not externally accessible data.
Of course, the drawback is that there may be a setting error, or even destroy the operation of atreugo, but this can be explained in the manual. It is recommended to use atreugo.Config to initialize during development.
If you are familiar with atreugo, fasthttp, fasthttprouter, and need more subtle settings, you can use atreugo to directly set the fasthttp.Server and fasthttprouter.Router parameters for initialization.
I prefer to keep router and server configuration be managed by atreugo (configuration struct) and not directly by users, for avoid errors or crashes. Atreugo was born to avoid that and make it simple.
I'm maintaining atreugo and some official packages of fasthttp (router, session and websocket), so I trying to keep aline the atreugo configuration with their configuration.
You could see that if there is any update (fasthttp, router, etc), I have immediately updated it.
But, if you need some extra configuration about router or fasthttp, please let me know or make a PR.
I will have the pleasure for review or merge it
Atreugo wants to make web development easier, so developers don't have to pay too much attention to servers and routers.
I understand your thoughts.
You contributed a lot of code in the server, router, session, websocket project, thank you very much for your contribution, we lazy developers can be lazy.
However, this is also my concern. Once the atreugo update is slow or paused, developers using atreugo will be limited to atreugo. If atreugo can be integrated into server and router, this situation will not be greatly affected.
Of course, this is just my suggestion, I support your decision.
If atreugo is the upper software of sever and router, you will be tired because you need a lot of synchronization adaptation.
If atreugo is the glue software for server and router, you will be more relaxed, because some developers can do it themselves.
My idea is that I hope that atreugo can go further.
By now, i will think about it, but i don't promise you that i will change it.
It's a hard change and it could be break all, because atreugo use a specific version of fasthttp and router, if their api change, it's very probably that atreugo will crash, so it's very unsafe.
But, probably i could add two functions that returns the pointer of router and server to just configure it under your own responsability.
For example:
s := server.ServerPtr()
s.Name = "myOverrideServerName"
s.Concurrency = 100
r := server.RouterPtr()
r.RedirectTrailingSlash = false
r.HandleOPTIONS = false
However, don't worry about slow or paused updated, because now i'm very active in Atreugo (and other projects) and fasthttp.
If it changes, i will let you know.
I understand the meaning of this example.
Thanks.