Created
May 10, 2019 23:44
-
-
Save brydavis/1e320b146432108a28c323e5efe4d76e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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