Skip to content

Instantly share code, notes, and snippets.

@maloninc
Last active April 22, 2023 11:40
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 maloninc/5e0cdf25136594c774361a65326d7d12 to your computer and use it in GitHub Desktop.
Save maloninc/5e0cdf25136594c774361a65326d7d12 to your computer and use it in GitHub Desktop.
MOD: Akamai x UNIQLO T-Shirt

これは何?

こちらのTシャツに印字されているgolangのコードは、 そのままではコンパイルできないので、ChatGPTにもっともらしいコードに書き換えてもらった上で、Tシャツに印字できるように適切に改行を施したコードです。

動きはしますが、残念ながら意味のある動作を実現できていません。

実行方法

go run akamai-mod.go

動作確認

% curl -X POST -d "count=0" -d "target=hello" localhost:8080/administrator
Control message issued for
Target:hello, Cnt:0
% curl -X POST  localhost:8080/_status
DEAD
package main; import ( "fmt" ; "html" ;
"net/http";"strconv";"strings";"time" );
type msg struct{Tgt string;Cnt int};func
main() {ctrlCh := make(chan msg);cmpCh:=
make(chan bool); pCh := make ( chan chan
bool);wkr := false;go admin(ctrlCh, pCh)
; for {select { case respChan := <- pCh:
respChan <- wkr; case msg := <- ctrlCh:
wkr = true; go doStuff(msg, cmpCh); case
state:=<-cmpCh:wkr=state;}}};func admin(
cc chan msg,pCh chan chan bool ) { http.
HandleFunc("/administrator",func(w http.
ResponseWriter,r *http.Request){strings.
Split(r.Host,"."); r.ParseForm(); count,
err := strconv.ParseInt ( r.FormValue (
"count"),10,32); if err!=nil{http.Error(
w, err.Error(), http.StatusBadRequest );
return; }; msg:= msg { Tgt:r.FormValue (
"target"),Cnt:int(count)};cc <- msg;fmt.
Fprintf (w, `Control message issued for
Target:%s, Cnt:%d`, html.EscapeString(r.
FormValue( "target" ) ), int(count));});
http.HandleFunc("/_status", func(w http.
ResponseWriter,r*http.Request){reqCh :=
make(chan bool); pCh<-reqCh;tout:= time.
NewTicker(1 * time.Second); select {case
result := <-reqCh:if result {fmt.Fprint(
w,"ACTIVE")} else { fmt.Fprint(w,"DEAD")
};case <-tout.C:fmt.Fprint(w, "TIMEOUT")
}});http.ListenAndServe(":8080", nil) };
func doStuff(msg msg, cmpCh chan bool) {
time.Sleep(time.Duration(msg.Cnt)* time.
Second); cmpCh <- false} // PEACE FOR ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment