Initial commit
This commit is contained in:
41
main.go
Normal file
41
main.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user