https://github.com/implex-ltd/bridge
Make a bridge between tool using websocket protocol.
https://github.com/implex-ltd/bridge
bridge discord
Last synced: 2 months ago
JSON representation
Make a bridge between tool using websocket protocol.
- Host: GitHub
- URL: https://github.com/implex-ltd/bridge
- Owner: Implex-ltd
- License: apache-2.0
- Created: 2023-09-24T11:13:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T13:29:39.000Z (over 2 years ago)
- Last Synced: 2024-04-30T07:15:37.963Z (about 2 years ago)
- Topics: bridge, discord
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bridge
Make a bridge between tool using websocket protocol.
## Install
```
go get -u github.com/Implex-ltd/bridge/bridge
```
## Example
```go
package main
import (
"log"
"time"
"github.com/Implex-ltd/bridge/bridge"
)
var port = 1337
func server() {
S, err := bridge.NewServer("", port, func(msg string) {
log.Printf("recv: %s", msg)
if msg == "test 3" {
log.Println("got test #3")
}
})
if err != nil {
panic(err)
}
log.Println("openning..")
if err := S.Serve(); err != nil {
panic(err)
}
log.Println("Server open")
}
func client() {
C, err := bridge.NewClient("localhost", port)
if err != nil {
panic(err)
}
for _, str := range []string{
"test 1",
"test 2",
"test 3",
} {
if err := C.PushData(str); err != nil {
panic(err)
}
time.Sleep(1 * time.Millisecond)
}
}
func main() {
go server()
time.Sleep(1 * time.Second)
client()
}
/**
Expected output:
- 2023/09/24 16:01:30 openning..
- 2023/09/24 16:01:31 recv: test 1
- 2023/09/24 16:01:31 recv: test 2
- 2023/09/24 16:01:31 recv: test 3
- 2023/09/24 16:01:31 got test #3
*/
```