Initial commit
This commit is contained in:
43
handlers.go
Normal file
43
handlers.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
// GetHealth godoc
|
||||
// @Summary Health check
|
||||
// @Description Check if the API is running
|
||||
// @Tags health
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Router /health [get]
|
||||
func GetHealth(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
||||
}
|
||||
|
||||
// GetUsers godoc
|
||||
// @Summary Get users
|
||||
// @Description Get list of all users
|
||||
// @Tags users
|
||||
// @Produce json
|
||||
// @Success 200 {array} User
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users [get]
|
||||
func GetUsers(w http.ResponseWriter, r *http.Request) {
|
||||
users := []User{
|
||||
{ID: 1, Name: "John Doe", Email: "john@example.com"},
|
||||
{ID: 2, Name: "Jane Smith", Email: "jane@example.com"},
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(users)
|
||||
}
|
||||
Reference in New Issue
Block a user