How to design MVC with Go Fiber

Hello community,

I am looking for tutorial to build full stack web site with MVC pattern.
Can anyone recommend me the good resource to start with?

BR, TONY.

Hello! There are several excellent online resources for learning how to develop a full stack web application using the MVC paradigm. Here are a few I would suggest:

Microsoftā€™s ā€œGetting Started with ASP. NET MVC 5ā€: This instructional series will lead you through the process of creating a basic MVC web application with C# and Visual Studio. It covers everything from configuring your development environment to hosting your application on a web server. It is available at ASP.NET MVC Getting Started | Microsoft Learn.

ā€œThe Complete Node.js Developer Courseā€ by Andrew Mead: This Udemy course will show you how to build a full-stack web application using Node.js, Express, and MongoDB. It goes over MVC design as well as other important web development concepts like authentication and security.

William S. Vincentā€™s ā€œDjango for Beginnersā€: This book will teach you how to create a web application with Django, a Python web framework that adheres to the MVC design. It covers everything from configuring your development environment to hosting your application on a web server.

These links should help you get started learning how to construct full-stack web apps using the MVC framework. Good luck with your studies!

Have a great day.

What part are you struggling with? You can start with the docs and have a working app pretty quickly. When you say ā€œMVCā€ Iā€™m assuming that means server-side rendering with a templating engine, right? Thatā€™s a pretty generic term but GENERALLY in web dev Iā€™ve used it to describe something like:

  • The controller is more or less your routing engine and associated plumbing therein.
  • The model is usually going to be a struct that represents a DB object or something similar.
  • The view is a templating engine which sends HTML back to the client.

Definitions get more complicated if you have a RESTful API and a SPA on top of that (since then you have multiple patterns of MVC) but again, this is generally what I see people refer to as ā€œMVC patternā€ with regard to web development. Is that what youā€™re after more or less?

Anyway, check out the recipes:

Decide on a templating engine:

ā€¦ and go to town. Here are a few more links for inspiration:

All that said, fiber doesnā€™t use net/http and is thus a bit of an outlier. Are you sure you need to use fiber? You might be able to find more official support if you use net/http:

https://gowebexamples.com/

Anyway, I donā€™t think thereā€™s anything wrong with fiber or fasthttp per se. But it seems like you might be a new gopher and it could be a bit jarring to go from that to a web app built using net/http. :slight_smile:

Thanks @Dean_Davidson for good reply. Yes, I new to gopher and I need to build web site for my client fast. After searching awhile I see fiber is good to start, but I donā€™t realise that it not using net/http. And yes MVC I refer to design patterns (Model, View, Controller).

MVC is a design pattren that sperate an applicationā€™s concern into three interconnect components: model included data and logic and the view( user interface), controller ( mediator between model and view). 1. The model contains the applicationā€™s data and business logic. Define your data models and any functions that will interact with the data.
2. Define your views: The views are responsible for rendering the applicationā€™s user interface. In Go Fiber, you can use templates to render your views. then define your routes to map incoming request to appropiate controller fuctions.

Now various framworks are available in mark that are these pattren such as model, view and controller. mainly it has been used in web and desktop field.

Can you share few of them?

I recommend starting with the Node.js MVC Frameworks - Express.js tutorials by FreeCodeCamp. Express.js is a popular web framework for Node.js that follows the MVC architectural pattern. This tutorial will guide you through the process of setting up an Express.js application, organizing your code into models, views and controllers, and handling routing and data management. It covers essential concepts such as routing, middleware, template engines, and database integration.

Hello Tony,

If youā€™re looking to build a full-stack web application using the Model-View-Controller (MVC) pattern with Go Fiber, I can guide you through the basic steps. While there isnā€™t a specific tutorial dedicated to Go Fiber and MVC, you can apply the MVC pattern in Go Fiber by structuring your code in a way that separates concerns into models, views, and controllers.

Hereā€™s a general outline to help you get started:

  1. Install Go: Make sure you have Go installed on your machine. You can download it from the official Go website and follow the installation instructions.
  2. Set up a new Go Fiber project: Create a new directory for your project and initialize a Go module by running the following command in your terminal:

bashCopy code

go mod init github.com/your-username/your-project-name
  1. Install Go Fiber: Use the following command to install Go Fiber and its dependencies:

arduinoCopy code

go get -u github.com/gofiber/fiber
  1. Create the MVC structure: Inside your project directory, create the following subdirectories:
  • models: This directory will contain your data models and business logic.
  • views: This directory will hold your HTML templates or any other view-related files.
  • controllers: This directory will include your request handlers and route definitions.
  1. Implement the models: In the models directory, define the data models and any relevant business logic. These models represent the structure of your data and may include functions to interact with the database or perform other operations.
  2. Create the views: In the views directory, you can store HTML templates or any other view-related files. These templates will be rendered by your controller and passed the necessary data.
  3. Define the controllers: In the controllers directory, create Go files that handle HTTP requests and route definitions. These files will handle incoming requests, interact with the models, and render the appropriate views. You can use Go Fiberā€™s routing capabilities to define routes and associate them with the corresponding controller functions.
  4. Integrate the MVC components: In your controller functions, utilize the models to retrieve data, perform business logic, and prepare the data to be rendered in the views. Use Go Fiberā€™s rendering capabilities to render the appropriate views with the data.
  5. Start the Go Fiber server: In your main Go file, import Go Fiber and set up the server to listen on a specific port. Run the server using app.Listen().
  6. Test and iterate: Start your server, visit the defined routes in your web browser, and verify that everything is working as expected. Iterate and refine your MVC components as needed.

While this is a general overview of how to implement MVC with Go Fiber, keep in mind that the specifics of your application will depend on your requirements and the complexity of your project.

Additionally, you may find it helpful to explore Go Fiberā€™s documentation (docs. gofiber. io) and examples (https:// github .com/gofiber/examples) to get a better understanding of how to use the framework effectively.

I hope this helps you get started on building your full-stack web application with Go Fiber and the MVC pattern. Good luck with your project!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.