Skip to content

Instantly share code, notes, and snippets.

@jdbaldry
Created August 29, 2024 06:05
Show Gist options
  • Select an option

  • Save jdbaldry/7b1d41adc1b93724c2a91ce06f6607c5 to your computer and use it in GitHub Desktop.

Select an option

Save jdbaldry/7b1d41adc1b93724c2a91ce06f6607c5 to your computer and use it in GitHub Desktop.
package main; import ( "fmt"; "html"; "io
"net/http"; "strconv"; "strings"; "time"
trolMessage struct { Target string; Count
func main() { controlChannel := make(chan
sage; workerCompleteChan := make(chan boo
pollChannel := make(chan chan bool); work
false;go admin(controlChannel, statusPoll
{ select { case respChan := <- statusPoll
Chan <- workerActive; case msg := <-contr
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.Fprintf(w, "ACTIVE"); } else
Print(w, "INACTIVE"); }; returPEACEFORALL
@tolzhabayev
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment