Initial commit

This commit is contained in:
2025-10-08 16:49:13 +00:00
commit 7274adfa0d
12 changed files with 624 additions and 0 deletions

41
main.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"log"
"net/http"
_ "goapi/docs"
"github.com/joho/godotenv"
httpSwagger "github.com/swaggo/http-swagger"
)
// @title GoApi
// @version 1.0
// @description A basic API with support for Swagger and Middleware
// @host localhost:8080
// @BasePath /api/v1
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name X-API-Key
func main() {
// Load .env file
if err := godotenv.Load(); err != nil {
log.Println("No .env file found, using environment variables")
}
mux := http.NewServeMux()
// API routes
mux.HandleFunc("/api/v1/health", GetHealth)
mux.HandleFunc("/api/v1/users", GetUsers)
// Swagger UI
mux.Handle("/swagger/", httpSwagger.WrapHandler)
// Apply middleware
handler := LoggingMiddleware(AuthMiddleware(mux))
log.Println("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", handler))
}