prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

wakatime.go (553B)


      1 package handlers
      2 
      3 import (
      4 	"encoding/json"
      5 	"net/http"
      6 )
      7 
      8 func (h *Handler) WakaTimeHandler(w http.ResponseWriter, r *http.Request) {
      9 	stats, err := h.wakaTimeService.FetchStats()
     10 	if err != nil {
     11 		http.Error(w, "Failed to fetch stats", http.StatusInternalServerError)
     12 		return
     13 	}
     14 
     15 	w.Header().Set("Content-Type", "application/json; charset=utf-8")
     16 	if stats == nil {
     17 		_, _ = w.Write([]byte("null"))
     18 		return
     19 	}
     20 
     21 	if err := json.NewEncoder(w).Encode(stats); err != nil {
     22 		http.Error(w, "Failed to encode stats", http.StatusInternalServerError)
     23 	}
     24 }