Skip to content

Instantly share code, notes, and snippets.

@brydavis
Created May 10, 2019 23:44
Show Gist options
  • Save brydavis/1e320b146432108a28c323e5efe4d76e to your computer and use it in GitHub Desktop.
Save brydavis/1e320b146432108a28c323e5efe4d76e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
http.HandleFunc("/radio", func(w http.ResponseWriter, r *http.Request) {
resp, err := http.Get("http://prclive1.listenon.in:9960")
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
flusher, ok := w.(http.Flusher)
if !ok {
panic("expected http.ResponseWriter to be an http.Flusher")
}
w.Header().Set("Connection", "Keep-Alive")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Set("Content-Type", "audio/mpeg")
for true {
io.Copy(w, resp.Body)
flusher.Flush()
return
}
})
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment