Giter Site home page Giter Site logo

Comments (3)

hotrungnhan avatar hotrungnhan commented on July 19, 2024 1

Sincerely thanks for explain me how this template work , you've show me a great point of view.

from fiber-go-template.

welcome avatar welcome commented on July 19, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template!

from fiber-go-template.

koddr avatar koddr commented on July 19, 2024

Hi,

I don't know why this option seems better to you, but I'll try to explain by example why I chose this way of organizing routes in the application. In the world of Go, it is a good thing to make fallback versions for REST API methods that are outdated but still in demand by users.

For this reason, to easily support two different versions of the API in one Fiber application, I will simply create another route file in which I set the next version of the API, like this:

// ./pkg/routes/public_routes_v2.go

// PublicRoutesV2 func for describe group of public routes for API v2.
func PublicRoutesV2(a *fiber.App) {
	// Create routes group.
	route := a.Group("/api/v2")

	// Routes for GET method:
	route.Get("/books", controllers.GetBooksV2) // <-- get list of all books for API v2

        // ...
}

Note that all controllers for the new version of the API are also marked with the new names (with the ending V2 to make it easier to identify them).

And next, I will add this new routes group to the main.go, like this:

// ./main.go

// ...
func main() {
	// ...

	// Routes.
	// ...
	routes.PublicRoutesV2(app)  // <-- register a public routes with API v2 for app
	// ...
}

As you can see, this way of organizing code in Fiber application allows you to keep a fallback version (for v1 users) and add new routes to make changes to the v2 API. And most importantly, this way is absolutely transparent for understanding and subsequent writing of unit tests because everything lies in its place: the description of routes and their challenge. 😉

If you are more convenient to use the option you gave in the example, then you are absolutely free to use it in your application! But I hope I've explained to you my point of view on this application template and the decisions made in it.

from fiber-go-template.

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.