package server import ( "database/sql" "log" "net/http" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "github.com/spf13/viper" ) type HttpServer struct { config *viper.Viper router *gin.Engine dbHandler *sql.DB } func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { // repository initialisation: // service initialisation: // controller initialisation: // Service API router := gin.Default() router.Use(cors.Default()) // static content router.Static("/static", "../static") router.StaticFile("/", "./static/index.html") router.GET("/test", Test) // server return HttpServer{ config: config, router: router, dbHandler: dbHandler, } } func (hs HttpServer) Start() { err := hs.router.Run(hs.config.GetString("http.server_address")) if err != nil { log.Fatalf("Error while starting HTTP server: %v", err) } } func Test(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{ "message": "Test", }) }