-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix gopatch Signed-off-by: Jess Frazelle <[email protected]> * add websockets Signed-off-by: Jess Frazelle <[email protected]> * bump version Signed-off-by: Jess Frazelle <[email protected]> --------- Signed-off-by: Jess Frazelle <[email protected]>
- Loading branch information
Showing
14 changed files
with
267 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.2.19 | ||
v0.2.20 |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// {{.Description}} | ||
func Example{{.Tag}}Service_{{.Name}}() { | ||
client, err := {{.PackageName}}.NewClientFromEnv("your apps user agent") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create the websocket connection. | ||
ws, err := client.{{.Tag}}.{{.Name}}({{range .Args -}}{{.Example}},{{end -}}{{if .RequestBody}}{{.RequestBody.Example}}{{end -}}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer ws.Close() | ||
|
||
done := make(chan struct{}) | ||
|
||
go func() { | ||
defer close(done) | ||
for { | ||
_, message, err := ws.ReadMessage() | ||
if err != nil { | ||
log.Println("read:", err) | ||
return | ||
} | ||
log.Printf("recv: %s", message) | ||
} | ||
}() | ||
|
||
ticker := time.NewTicker(time.Second) | ||
defer ticker.Stop() | ||
|
||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, os.Interrupt) | ||
|
||
for { | ||
select { | ||
case <-done: | ||
return | ||
case t := <-ticker.C: | ||
err := ws.WriteMessage(websocket.TextMessage, []byte(t.String())) | ||
if err != nil { | ||
log.Println("write:", err) | ||
return | ||
} | ||
case <-interrupt: | ||
log.Println("interrupt") | ||
|
||
// Cleanly close the connection by sending a close message and then | ||
// waiting (with timeout) for the server to close the connection. | ||
err := ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) | ||
if err != nil { | ||
log.Println("write close:", err) | ||
return | ||
} | ||
select { | ||
case <-done: | ||
case <-time.After(time.Second): | ||
} | ||
return | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// {{.Description}} | ||
func (s *{{.Tag}}Service) {{.Name}}({{range .Args -}}{{.Name}} {{.Type}},{{end -}}{{if .RequestBody}}body {{.RequestBody.Type}}{{end}}) (*websocket.Conn, error) { | ||
// Create the url. | ||
path := "{{.Path}}" | ||
uri := resolveRelative(s.client.server, path) | ||
|
||
headers := http.Header{} | ||
headers["Authorization"] = []string{fmt.Sprintf("Bearer %s", s.client.token)} | ||
|
||
conn, _, err := websocket.DefaultDialer.Dial(strings.ReplaceAll(uri, "https://", "wss://"), headers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return conn, nil | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.