Gin

Main

  • To initialize the server when run on specific port

package main

import (
	"golang-playground/controller"
	"log"

	"os"
	"os/signal"
	"syscall"

	"github.com/joho/godotenv"
)

func main() {
	err := godotenv.Load()
	if err != nil {
		log.Println("Error loading .env file")
	}
	controller := controller.NewInternalController()
	// open the new thread to run the server instead of blocking the main thread
	go func() {
		if err := controller.Run("8080"); err != nil {
			log.Fatalf("Failed to start server: %v", err)
		}
	}()
	quit := make(chan os.Signal, 1)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit
}

Controller

  • To declare each api end point and applied middleware

Middleware

  • To declare the middleware to intercept the request before passing to the controller

Service

  • The logicial layer

Last updated

Was this helpful?