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" | |
| "syscall/js" | |
| ) | |
| func Sample(this js.Value, args []js.Value) interface{} { | |
| fmt.Println(this, args) |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Go wasm</title> | |
| </head> | |
| <body> | |
| <div id="output">Foobar</div> | |
| <button id="action" onclick="sample()">Run</button> |
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" | |
| "os" | |
| "net/http" | |
| "testing" | |
| "github.com/tebeka/selenium" | |
| "github.com/tebeka/selenium/chrome" |
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
| func TestSample(t *testing.T) { | |
| service, wd, server := setup(t) | |
| defer service.Stop() | |
| defer wd.Quit() | |
| defer server.Close() | |
| t.Log("Loading webpage") | |
| if err := wd.Get("http://localhost:8090/index.html"); err != nil { |
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
| type App struct { | |
| Bus *dbus.Conn | |
| Conns []*websocket.Conn | |
| } |
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
| const ( | |
| AppPath = "/medium/examples/chat" | |
| AppID = "medium.examples.chat" | |
| ) | |
| var upgrader = websocket.Upgrader{ | |
| ReadBufferSize: 1024, | |
| WriteBufferSize: 1024, | |
| } |
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
| func (a *App) broadcast(message []byte) { | |
| for _, conn := range a.Conns { | |
| // ignoring errors, with respect to UDP | |
| conn.WriteMessage(1, message) | |
| } | |
| } |
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
| func (a *App) listen() { | |
| conn, err := dbus.SystemBus() | |
| if err != nil { | |
| log.Fatal(os.Stderr, "Failed to connect to session bus:", err) | |
| } | |
| a.Bus = conn | |
| if err = conn.AddMatchSignal( |
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
| func (a *App) handler(w http.ResponseWriter, r *http.Request) { | |
| conn, err := upgrader.Upgrade(w, r, nil) | |
| if err != nil { | |
| log.Println(err) | |
| return | |
| } | |
| a.Conns = append(a.Conns, conn) |
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
| func main() { | |
| var app App | |
| http.HandleFunc("/sockettome", app.handler) | |
| // Listen for messages and broadcast it. | |
| go app.listen() | |
| log.Fatal(http.ListenAndServe(":8080", nil)) |
OlderNewer