Step 1 : Initialising Go backend in monorepo

# STEP 1
cd apps
mkdir api-go
cd api-go

# STEP 2 : Initialising empty go backend
go mod init github.com/RitikaxG/runState/apps/api-go

Step 2 : Create folder structure inside apps/api-go

cmd/server
	|-------------> main.go
internals
	|----> routes
				|-------> websites.go
				|-------> health.go
				|-------> router.go

Step 3 : How to Fetch an External Package

Let’s say you want to use the popular web framework Gin.

You run:

go get github.com/gin-gonic/gin

This does:

Example go.mod after installing Gin:

module github.com/hkirat/go-http-server

go 1.22

require github.com/gin-gonic/gin v1.9.1


Step 4 : Learning Gin Framework

Documentation

Writing Gin application

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default() // creates Gin Router with default middleware

	// Defines a simple GET endpoint
	r.GET("/health", func(c *gin.Context) {
		// Returns JSON response
		c.JSON(200, gin.H{ // 200 can be replaced with http.StatusOK this way u use net/http with Gin for status codes
			"status": "ok",
		})
	})

	// Start server at 30
	r.Run(":3001")
}