help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
go-rest-api
/
cmd
/
api
RSK World
go-rest-api
Go REST API - Enterprise-grade REST API with JWT Authentication + PostgreSQL + Redis Caching + Docker + Comprehensive Testing + Educational Design
api
  • main.go1.9 KB
main.go
cmd/api/main.go
Raw Download
Find: Go to:
/*
* Author: RSK World
* Email: help@rskworld.in / support@rskworld.in
* Website: https://rskworld.in/contact.php
* Year: 2026
*/

package main

import (
	"log"

	"github.com/gin-gonic/gin"
	"github.com/rskworld/go-rest-api/internal/cache"
	"github.com/rskworld/go-rest-api/internal/config"
	"github.com/rskworld/go-rest-api/internal/database"
	"github.com/rskworld/go-rest-api/internal/models"
	"github.com/rskworld/go-rest-api/internal/routes"

	_ "github.com/rskworld/go-rest-api/docs" // Import generated docs
)

// @title Go REST API
// @version 1.0
// @description RESTful API service built with Go programming language.
// @termsOfService http://swagger.io/terms/

// @contact.name RSK World Support
// @contact.url https://rskworld.in/contact.php
// @contact.email help@rskworld.in

// @license.name MIT
// @license.url https://opensource.org/licenses/MIT

// @host localhost:8080
// @BasePath /api

// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization

func main() {
	// Load Configuration
	cfg := config.LoadConfig()

	// Initialize Cache
	if err := cache.InitCache(cfg); err != nil {
		log.Printf("Warning: Failed to initialize cache: %v", err)
		log.Println("Continuing without cache...")
	} else if cfg.CacheEnabled {
		log.Println("Cache initialized successfully")
	}

	// Connect to Database
	database.Connect(cfg)

	// Migrate Database
	err := database.DB.AutoMigrate(&models.User{}, &models.Category{}, &models.Product{})
	if err != nil {
		log.Fatal("Database migration failed: ", err)
	}

	log.Println("Database migration completed successfully")

	// Setup Router
	r := gin.New()

	// Setup Routes
	routes.SetupRouter(r, cfg)

	// Start Server
	log.Printf("Server starting on port %s", cfg.Port)
	if err := r.Run(":" + cfg.Port); err != nil {
		log.Fatal("Failed to start server: ", err)
	}
}
77 lines•1.9 KB
go

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer