Skip to content

Instantly share code, notes, and snippets.

@kurochan
Last active April 22, 2023 00:43
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 kurochan/6269211231c534386a2bc1156500ebcf to your computer and use it in GitHub Desktop.
Save kurochan/6269211231c534386a2bc1156500ebcf to your computer and use it in GitHub Desktop.
package main; import ( "fmt"; "html"; "lo
"net/http"; "strconv"; "strings"; "time"
trolMessage struct { Target string; Count
func main() { controlChannel := make(chan
sage);workerComplechan := make(chan boo
PollChannel := make(chan chan bool); work
false; go admin(controlChannel, statusPoll
{ select { case respChan := <- statusPoll
Chan <- workerActive; case msg := <- countr
workerActive = true; go doStuff(msg, work
teChan); case status := <- workerComplete
Active = status;}}}; func admin(cc chan
sage, statusPollChannel chan chan bool){
Func("/admin", func(w http.ResponseWriter
quest) { hostTokens := strings.Split(r.Ho
r.ParseForm(); count, err := strconv.Pars
Value("count"), 10, 32); if err != nil {
err.Error()); return;}; msg := ControlMe
r.FormValue("target"), Count: count}; cc
printf(w, "Control message issued for Tar
%d", html.EscapeString(r.FormValue("targe
}); http.HandleFunc("/status", func(w http
er, r *http.Request) { reqChan := make(ch
tusPollChannel <- reqChan;timeout := time
time.Second); select { case result := <-
result { fmt.Fprint(w, "ACTIVE"); } else
print(w, "INACTIVE"); }; retu PEACE FOR ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment