Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/injoyai/ios
万物皆IO
https://github.com/injoyai/ios
Last synced: 23 days ago
JSON representation
万物皆IO
- Host: GitHub
- URL: https://github.com/injoyai/ios
- Owner: injoyai
- Created: 2024-08-08T01:07:13.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-18T03:46:15.000Z (29 days ago)
- Last Synced: 2024-12-20T15:50:07.959Z (26 days ago)
- Language: Go
- Homepage:
- Size: 210 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# io
### 如何使用
#### 如何连接TCP
```go
package main
import (
"github.com/injoyai/ios"
"github.com/injoyai/ios/client"
"github.com/injoyai/ios/client/dial"
"time"
)func main() {
addr := "127.0.0.1:10086"
c := dial.Redial(dial.WithTCP(addr),
func(c *client.Client) {
c.Logger.Debug() //开启打印日志
c.Logger.WithUTF8() //打印日志编码ASCII
c.Event.OnReadFrom = ios.NewRead4KB() //设置读取方式,一次读取全部
c.Event.OnDealMessage = func(c *client.Client, msg ios.Acker) {
// todo 业务逻辑,处理读取到的数据
}
c.GoTimerWriter(time.Minute, func(w ios.MoreWriter) error {
_, err := w.WriteString("心跳") //定时发送心跳
return err
})
})
c.Run()
}```
#### 如何连接SSH
```go
package main
import (
"bufio"
"fmt"
"github.com/injoyai/ios/client/dial"
"github.com/injoyai/ios/module/ssh"
"os"
)func main() {
c := dial.RedialSSH(&ssh.Config{
Address: os.Args[1],
User: os.Args[2],
Password: os.Args[3],
})
c.Logger.Debug(false)
c.Event.OnDealMessage = func(c *client.Client, msg ios.Acker) {
fmt.Print(string(msg.Payload()))
}
go c.Run()
reader := bufio.NewReader(os.Stdin)
for {
select {
case <-c.Done():
return
default:
bs, _, _ := reader.ReadLine()
c.Write(append(bs, '\n'))
}
}
}```
#### 如何连接Websocket
```go
package mainimport(
"bufio"
"github.com/injoyai/ios"
"github.com/injoyai/ios/client/dial"
"os"
)func main(){
<- dial.RedialWebsocket("http://127.0.0.1:80/ws",nil,
func(c *client.Client) {
c.Logger.Debug()
c.Logger.WithUTF8()
c.Event.OnDealMessage= func(c *client.Client, msg ios.Acker){
// todo 业务逻辑,处理读取到的数据
}
}).Done()
}```