Created
August 29, 2024 06:05
-
-
Save jdbaldry/7b1d41adc1b93724c2a91ce06f6607c5 to your computer and use it in GitHub Desktop.
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"; "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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://qiita.com/o-ga/items/d32b93149e23d56ebd01