A couple of code samples to show how a named pipe can be used to extend Go's channel paradigm for use between different processes running on a system.
- interprocess1.go details a single byte channel.
- interprocess2.go details a channel that passes slices of bytes.
Note that opening a write channel will return two channels - one for writing to, and one which will be written to when the goroutine writing to the named pipe has completed. This last channel should be checked, prior to exiting a program, to avoid any loss of data.
The close() function should be called on the write channel once all data has been sent. This will cause any outstanding data and an EOF to be sent to the named pipe.
If you want to pass type instances over the named pipe then you will need to handle the encoding and decoding yourself.
Although intended for channel commnication between two Go processes, the other side of the named pipe can be any other process you like.
Note that named pipes can have multiple readers and writers although I don't recommend this as there are no guarantees about byte order and about who gets what.