Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joe-at-startupmedia/gipc
IPC library featuring multi-client support without enabling CGO
https://github.com/joe-at-startupmedia/gipc
ipc multiclient tcp unix-socket
Last synced: 27 days ago
JSON representation
IPC library featuring multi-client support without enabling CGO
- Host: GitHub
- URL: https://github.com/joe-at-startupmedia/gipc
- Owner: joe-at-startupmedia
- License: cc0-1.0
- Created: 2024-05-20T21:46:01.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-05-25T23:56:51.000Z (7 months ago)
- Last Synced: 2024-10-18T14:16:00.547Z (3 months ago)
- Topics: ipc, multiclient, tcp, unix-socket
- Language: Go
- Homepage:
- Size: 115 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gipc
[![Testing](https://github.com/joe-at-startupmedia/gipc/actions/workflows/testing.yml/badge.svg)](https://github.com/joe-at-startupmedia/gipc/actions/workflows/testing.yml)
[![codecov](https://codecov.io/gh/joe-at-startupmedia/gipc/graph/badge.svg?token=0G9FP0QN5S)](https://codecov.io/gh/joe-at-startupmedia/gipc)
[![Go Report Card](https://goreportcard.com/badge/github.com/joe-at-startupmedia/gipc)](https://goreportcard.com/report/github.com/joe-at-startupmedia/gipc)### Overview
A simple-to-use package that creates a communication channel between two go processes.## Usage
Create a server with the default configuration and start listening for the client:
```go
s, err := gipc.StartServer(&ServerConfig{Name:""})
if err != nil {
log.Println(err)
return
}
```
Create a client and connect to the server:```go
c, err := gipc.StartClient(&ClientConfig{Name:""})
if err != nil {
log.Println(err)
return
}
```### Read messages
Read each message sent (blocking):
```go
for {//message, err := s.Read() // server
message, err := c.Read() // client
if err == nil {
// handle error
}
// do something with the received messages
}
```Read each message sent until a specific duration has surpassed.
```go
for {message, err := c.ReadTimed(5*time.Second)
if message == gipc.TimeoutMessage {
continue
}
if err == nil && c.StatusCode() != gipc.Connecting {
}
}
```### MultiClient Mode
Allow polling of newly created clients on each iteration until a specific duration has surpassed.
```go
s, err := gipc.StartServer(&ServerConfig{Name:"", MultiClient: true})
if err != nil {
log.Println(err)
return
}for {
s.Connections.ReadTimed(5*time.Second, func(srv *ipc.Server, message *ipc.Message, err error) {
if message == gipc.TimeoutMessage {
continue
}
if message.MsgType == -1 && message.Status == "Connected" {
}
})
}
```* `Server.Connections.ReadTimed` will block until the slowest ReadTimed callback completes.
* `Server.Connections.ReadTimedFastest` will unblock after the first ReadTimed callback completes.While `ReadTimedFastest` will result in faster iterations, it will also result in more running goroutines in scenarios where clients requests are not evenly distributed.
To get a better idea of how these work, run the following examples:
Using `ReadTimed`:
```bash
go run --race example/multiclient/multiclient.go
```Using `ReadTimedFastest`:
```bash
FAST=true go run --race example/multiclient/multiclient.go
```Notice that the Server receives messages faster and the process will finish faster
### Message Struct
All received messages are formatted into the type Message
```go
type Message struct {
Err error // details of any error
MsgType int // 0 = reserved , -1 is an internal message (disconnection or error etc), all messages recieved will be > 0
Data []byte // message data received
Status string // the status of the connection
}
```### Write a message
```go
//err := s.Write(1, []byte(" 5` will specify the amount of milliseconds to wait in between critical intervals whereas a value `<= 5` will resolve to the amount of seconds to wait in between the same. The default value is 10 milliseconds. You can also provide the `IPC_DEBUG=true` environment variable to set the `logrus.Loglevel` to debug mode. The following command will make the tests run in debug mode while waiting 500ms in between critical intervals:
```bash
GIPC_WAIT=500 GIPC_DEBUG=true make test run
```