mirror of
https://github.com/Maronato/go-finger.git
synced 2026-05-06 21:06:16 +02:00
- Remove Gitea-specific "Fix docker sock permissions" step - actions/checkout: v2 → v4 - docker/setup-qemu-action: v1 → v3 - docker/setup-buildx-action: v1 → v3 - docker/login-action: v2 → v3 - docker/metadata-action: v4 → v5 - actions/cache: v3 → v4; remove Gitea-runner-specific Go module cache paths (/go/pkg/mod/, /tmp/.go-build-cache) — only buildx cache is relevant for Docker-only builds on GitHub Actions - docker/build-push-action: v2 → v5 https://claude.ai/code/session_01WSTmBCLVtmPMFqxCnjM9fh
49 lines
1008 B
Go
49 lines
1008 B
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/Maronato/go-finger/webfingers"
|
|
)
|
|
|
|
func WebfingerHandler(fingers webfingers.WebFingers) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Only handle GET requests
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
return
|
|
}
|
|
|
|
// Get the query params
|
|
q := r.URL.Query()
|
|
|
|
// Get the resource
|
|
resource := q.Get("resource")
|
|
if resource == "" {
|
|
http.Error(w, "No resource provided", http.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
|
|
// Get and validate resource
|
|
finger, ok := fingers[resource]
|
|
if !ok {
|
|
http.Error(w, "Resource not found", http.StatusNotFound)
|
|
|
|
return
|
|
}
|
|
|
|
// Set the content type
|
|
w.Header().Set("Content-Type", "application/jrd+json")
|
|
|
|
// Write the response
|
|
if err := json.NewEncoder(w).Encode(finger); err != nil {
|
|
http.Error(w, "Error encoding json", http.StatusInternalServerError)
|
|
|
|
return
|
|
}
|
|
})
|
|
}
|