Select Git revision
hover-active-card.mustache
main.go 968 B
package main
import (
"fmt"
"log"
"path"
"strings"
"net/http"
"pirates/piratar/octopus"
)
func main() {
http.HandleFunc("/", handler)
port := 3000 // TODO: ENV
fmt.Printf("Piratar service listening on port %d...\n", port)
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil {
log.Fatalf("Server failed: %v", err)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
// Extrakce username nebo UUID
id := strings.ToLower(path.Base(r.URL.Path))
if dotIndex := strings.LastIndex(id, "."); dotIndex != -1 {
id = id[:dotIndex]
}
// Profilova fotka nebo default
if photo, err := octopus.ProfilePhoto(id); err == nil {
fmt.Printf("Piratar for %s: %s\n", id, photo)
http.Redirect(w, r, photo, http.StatusFound)
} else {
fmt.Printf("Piratar for %s not found\n", id)
w.Header().Set("Content-Type", "image/jpeg")
http.ServeFile(w, r, "default.jpg")
}
}