Comments (7)
I have discussed this with @koddr, and we want to share our conclusion on this matter.
Most methods that use the ...interface{}
argument are used for app.METHODS
to register routes with an optional path. We think that this is straightforward because this is the first thing you learn visiting Fiber or coming from Express.
Now there are some Context
methods that accept ...interface{}
as an argument:
ctx.Body
, ctx.Cookies
, ctx.Format
When you managed to understand the Route handlers, you are left with these 3
+/- methods where you need docs. So I think Fiber is still a strong typed API besides these 3 methods. But we could improve the above methods and maybe all Route handlers (except Use
).
I started working on clarifying some *Ctx
functions, these are safe changes to make.
master...Fenny:master
We can change all app.METHODS
to have a required (path string, handlers ...func(*Ctx))
for the following methods:
Static
, Connect
, Put
, Delete
, Head
, Patch
, Options
, Trace
, Get
, All
.
This is a big change, and I might create an Poll for this and take a vote.
from fiber.
I see.
Well, it is up to library maintainers to decide. I feel like having non strongly typed API can turn off some Go developers. Would be nice to have Β―\_(γ)_/Β―
.
In my case I added fiber
to dependencies, started to write main
function to try around and hit app.
autocompletion, saw args ...interface{}
and was like: damn... now I need to go find docs.
And not to mention I'm a member of strongly typed camp. π
from fiber.
agreeοΌFiber made it easy for me to migrate from nodejs to Goγ
The reason I chose to learn Go instead of TypeScript:
- A strong typed language can reduce errors and catch exceptions more easily
- Moderate development efficiency and adequate operational performance
- Cross-compile into binaries for easy distribution and deployment
Now, it's true that docs are often needed οΌand Some exceptions can only be caught at runtime.
from fiber.
Thanks @alex-shpak for your input, all suggestions will be addressed in v1.8.0.
PS: We went with Get(path string, handlers ...func(*Ctx))
because we don't want to confuse people with the order of where to place the middleware handlers.
app.Get("/", secretpage(), auth())
// Might cause unintended results since auth() will run after the secretpage
app.Get("/", auth(), secretpage())
// We think with the current arg types this will be encouraged.
I'm closing this issue because v1.8.0
will be released soon, feel free to re-open for more ideas/suggestions!
from fiber.
Thanks for opening your first issue here! π Be sure to follow the issue template!
from fiber.
Fiber started as a personal project to be able to rewrite all my node apps into Go. I tried to stick to the same workflow as Express by using interfaces when a function had multiple purposes, now I know that this is not the best way to go.
I thought about going with a 100% strong typed API weeks ago, but Fiber got a lot of users within a short period of time. So changing Fiber to be a fully strong typed framework will break the current API, but we can take notes for v1.8
from fiber.
I like that π
I guess Static
method would be Static(string, ...string)
. Also for method functions something like this might be good: Get(path string, handler func(*Ctx), handlers ...func(*Ctx)
so it requires to have at least one handler, or more.
I think having strong typing could cleanup router.go@register
function and make it more safe.
I cant help with some PRs if you have something specific in mind.
from fiber.
Related Issues (20)
- π [Feature]: Tutorial(s) or Blog(s) HOT 1
- π [Bug]: β500ms Performance penalty using compression on and 'br' in 'Accept-Encoding' HOT 25
- π [Feature]: Using Number as Valid Boolean Query Parameter HOT 10
- π€ [Question]: Fiber App copies its mutex lock when passing as parameter HOT 2
- π€ [Question]: 403 forbidden on POST CSRF request HOT 16
- π€ [Question]: Adding colour to a CustomTag in the logger middleware HOT 1
- π [Bug]: Logger middleware default Format isn't the format that's used HOT 3
- π [Bug]: Missing ContextKey in requestid middleware configuration HOT 2
- π€ [Question]: Problem with CSRF after updating fiber to 2.51 HOT 10
- π [Bug]: utils.IsIPv4 and net.ParseIP have inconsistent results HOT 5
- π [Feature]: middleware/logger: use Logger interface HOT 4
- π€ [Question]: how to debug requests in Fiber within GoLand HOT 2
- π [Bug]: Inconsistency in Session and CSRF Middleware Handling of Timeout and Expiration HOT 11
- π [Bug]: Csrf with Session store does not support secure cookie middleware HOT 4
- π [v3 Proposal]: Parity for res.format and Ctx.Format HOT 4
- π€ [Question]: PR template and CONTRIBUTING.md Inconsistency HOT 1
- The compiled package is too big, isn't it HOT 6
- π [Bug]: Middleware Rate Limiter Not Work as expected if Header Value Using IP HOT 2
- π [Bug]: Very rare panics in ctx.BodyParser or in fasthttp under unknown conditions HOT 14
- π [Feature]: Implement Generic APIs for Enhanced Variable Type HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fiber.