Last active
October 24, 2024 13:47
-
-
Save kaihendry/9f6f48d0c7529933baeb81a30aede3ee to your computer and use it in GitHub Desktop.
Revisions
-
kaihendry revised this gist
Oct 24, 2024 . No changes.There are no files selected for viewing
-
kaihendry created this gist
Oct 24, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ package main import ( "log" "net/http" "math/rand" ) func main() { const html = ` <html> <head> <script src="https://unpkg.com/[email protected]" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script> </head> <body> <div id="parent-div"> <p>Say something</p> </div> <button hx-post="/clicked" hx-trigger="click" hx-target="#parent-div" hx-swap="outerHTML" > Click Me! </button> </body> </html> ` http.HandleFunc("/clicked", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) greetings := []string{"hello", "hi", "howdy", "hola", "bonjour", "ciao", "hallo", "hej", "guten tag", "namaste", "ni hao", "salut", "merhaba", "こんにちは", "안녕하세요", "안녕", "你好", "नमस्ते", "П��ивет", "你好", "Olá", "Hallo", "Ciao", "Hola", "Bonjour", "Merhaba", "こんにちは", "안녕하세요", "안녕", "你好", "नमस्ते", "Привет", "你好", "Olá", "Hallo", "Ciao", "Hola", "Bonjour", "Merhaba", "こんにちは", "안녕하세요", "안녕", "你好", "नमस्ते", "Привет", "你好", "Olá", "Hallo", "Ciao", "Hola", "Bonjour", "Merhaba"} randomGreeting := greetings[rand.Intn(len(greetings))] w.Write([]byte("<div id=\"parent-div\"><h1>" + randomGreeting + "</h1></div>")) }) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(html)) }) log.Println("starting server on port 8080") log.Fatal(http.ListenAndServe(":8080", nil)) }