Skip to content

Instantly share code, notes, and snippets.

@esehara
Created October 6, 2016 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esehara/0a0308c5f24506a4ca8cd57c609bacd7 to your computer and use it in GitHub Desktop.
Save esehara/0a0308c5f24506a4ca8cd57c609bacd7 to your computer and use it in GitHub Desktop.
Goで簡単なエコーサーバーを作る ref: http://qiita.com/esehara@github/items/34f8675c61169da06d73
package main
import (
"fmt"
"net/http"
"net/url"
"io/ioutil"
)
func getRSS(s string) string {
u, _ := url.Parse(s)
q := u.Query()
for k, _ := range u.Query() { q.Del(k) }
q.Set("hoge", "fuga")
u.RawQuery = q.Encode()
return u.String()
}
func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
url := getRSS(r.Form["u"][0])
resp, _ := http.Get(url)
defer resp.Body.Close()
byteArray, _ := ioutil.ReadAll(resp.Body)
fmt.Fprint(w, string(byteArray))
}
func main() {
fmt.Println("Start Server ...")
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment