Created
April 19, 2017 09:56
-
-
Save SamMorrowDrums/a2953dd628e2393a7da4f775237e7a5e to your computer and use it in GitHub Desktop.
Go Domino Server
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/ioutil" | |
"log" | |
"net/http" | |
"strings" | |
) | |
func main() { | |
http.HandleFunc("/", handler) | |
fmt.Println("initialise") | |
log.Panic(http.ListenAndServe(":9001", nil)) | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
q := r.URL.Query() | |
hostList := strings.Split(q.Get("a"), ",") | |
if hostList[0] == "" { | |
fmt.Fprintf(w, "Sam's Laptop has terminated your req") | |
return | |
} | |
nextTarget := hostList[0] | |
rest := hostList[1:] | |
nextURL := fmt.Sprintf("http://192.168.21.%s:9001/?a=%s", nextTarget, strings.Join(rest, ",")) | |
res, err := http.DefaultClient.Get(nextURL) | |
if err != nil { | |
fmt.Fprintf(w, err.Error()) | |
return | |
} | |
defer res.Body.Close() | |
body, _ := ioutil.ReadAll(res.Body) | |
output := fmt.Sprintf("%s this is Sam's Laptop", body) | |
fmt.Fprintf(w, output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment