Added handlers used in a radiodj service. Currently just for listeners.
This commit is contained in:
parent
61e2f6d8fd
commit
978a2602d8
39
internal/http/dj_handlers.go
Normal file
39
internal/http/dj_handlers.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dwelling-radio/internal/radio"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DJHandlers struct {
|
||||||
|
listeners *radio.Listeners
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDJHandlers(listeners *radio.Listeners) *DJHandlers {
|
||||||
|
return &DJHandlers{listeners: listeners}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dj *DJHandlers) ListenersGet(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Content-Type", "text/plain")
|
||||||
|
fmt.Fprint(w, dj.listeners.Current(), dj.listeners.Peak())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dj *DJHandlers) ListenersInc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
l := dj.listeners.Inc()
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
w.Header().Add("Content-Type", "text/plain")
|
||||||
|
fmt.Fprint(w, l)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dj *DJHandlers) ListenersDec(w http.ResponseWriter, r *http.Request) {
|
||||||
|
l, err := dj.listeners.Dec()
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Header().Add("Content-Type", "text/plain")
|
||||||
|
fmt.Fprint(w, l)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user