Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

inproc

PkgGoDevBuild StatuscodecovGo Report CardLICENSE

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

package main
import (
"fmt""github.com/hslam/inproc""net"
)
funcmain() {
address:=":8080"l, err:=inproc.Listen(address)
iferr!=nil {
panic(err)
}
deferl.Close()
gofunc() {
for {
conn, err:=l.Accept()
iferr!=nil {
return
}
gofunc(conn net.Conn) {
buf:=make([]byte, 1024)
for {
n, err:=conn.Read(buf)
iferr!=nil {
break
}
conn.Write(buf[:n])
}
conn.Close()
}(conn)
}
}()
conn, err:=inproc.Dial(address)
iferr!=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)
iferr!=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.

About

Package inproc implements an in-process connection.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages