https://github.com/hslam/inproc
Package inproc implements an in-process connection.
https://github.com/hslam/inproc
conn go golang in-process inproc listener net network
Last synced: 4 months ago
JSON representation
Package inproc implements an in-process connection.
- Host: GitHub
- URL: https://github.com/hslam/inproc
- Owner: hslam
- License: mit
- Created: 2021-08-07T18:46:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-12T03:28:38.000Z (over 4 years ago)
- Last Synced: 2025-03-30T11:32:45.034Z (9 months ago)
- Topics: conn, go, golang, in-process, inproc, listener, net, network
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inproc
[](https://pkg.go.dev/github.com/hslam/inproc)
[](https://github.com/hslam/inproc/actions)
[](https://codecov.io/gh/hslam/inproc)
[](https://goreportcard.com/report/github.com/hslam/inproc)
[](https://github.com/hslam/inproc/blob/master/LICENSE)
Package inproc implements an in-process connection.
## Features
* In-process connection.
* Compatible with the net.Conn and the net.Listener interface.
## Get started
### Install
```
go get github.com/hslam/inproc
```
### Import
```
import "github.com/hslam/inproc"
```
### Usage
#### Example
```go
package main
import (
"fmt"
"github.com/hslam/inproc"
"net"
)
func main() {
address := ":8080"
l, err := inproc.Listen(address)
if err != nil {
panic(err)
}
defer l.Close()
go func() {
for {
conn, err := l.Accept()
if err != nil {
return
}
go func(conn net.Conn) {
buf := make([]byte, 1024)
for {
n, err := conn.Read(buf)
if err != nil {
break
}
conn.Write(buf[:n])
}
conn.Close()
}(conn)
}
}()
conn, err := inproc.Dial(address)
if err != nil {
panic(err)
}
msg := "Hello World"
if _, err := conn.Write([]byte(msg)); err != nil {
panic(err)
}
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
panic(err)
}
fmt.Println(string(buf[:n]))
conn.Close()
}
```
### Output
```
Hello World
```
### License
This package is licensed under a MIT license (Copyright (c) 2021 Meng Huang)
### Author
inproc was written by Meng Huang.