Skip to content
Snippets Groups Projects
Select Git revision
  • aac6d1d3cb6ab603ac90ef62253fe11ace92db8a
  • master default protected
  • feat/new-image-formats
  • clickable-select-chevron
  • 2.20.0
  • 2.19.0
  • 2.18.0
  • 2.17.0
  • 2.16.1
  • 2.16.0
  • 2.15.0
  • 2.14.0
  • 2.13.0
  • 2.12.1
  • 2.11.0
  • 2.10.0
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.1
  • 2.7.0
  • 2.6.0
  • 2.5.2
  • 2.5.1
24 results

hover-active-card.mustache

Blame
  • 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")
        }
    }