Skip to content

Instantly share code, notes, and snippets.

@SamMorrowDrums
Created April 19, 2017 09:56
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 SamMorrowDrums/a2953dd628e2393a7da4f775237e7a5e to your computer and use it in GitHub Desktop.
Save SamMorrowDrums/a2953dd628e2393a7da4f775237e7a5e to your computer and use it in GitHub Desktop.
Go Domino Server
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