Code Monkey home page Code Monkey logo

Comments (7)

Fenny avatar Fenny commented on April 30, 2024 2

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.

alex-shpak avatar alex-shpak commented on April 30, 2024 1

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.

hyingreborn avatar hyingreborn commented on April 30, 2024 1

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.

Fenny avatar Fenny commented on April 30, 2024 1

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.

welcome avatar welcome commented on April 30, 2024

Thanks for opening your first issue here! πŸŽ‰ Be sure to follow the issue template!

from fiber.

Fenny avatar Fenny commented on April 30, 2024

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.

alex-shpak avatar alex-shpak commented on April 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.