2020-11-27 18:32:27 +08:00
|
|
|
# msg
|
2020-11-27 18:41:43 +08:00
|
|
|
[](https://pkg.go.dev/github.com/hslam/msg)
|
2020-12-18 13:03:35 +08:00
|
|
|
[](https://github.com/hslam/msg/actions)
|
2020-11-27 18:41:43 +08:00
|
|
|
[](https://goreportcard.com/report/github.com/hslam/msg)
|
|
|
|
[](https://github.com/hslam/msg/blob/master/LICENSE)
|
|
|
|
|
2020-11-29 03:33:55 +08:00
|
|
|
Package msg provides a way to use System V message queues.
|
2020-11-27 18:41:43 +08:00
|
|
|
|
|
|
|
## Get started
|
|
|
|
|
|
|
|
### Install
|
|
|
|
```
|
|
|
|
go get github.com/hslam/msg
|
|
|
|
```
|
|
|
|
### Import
|
|
|
|
```
|
|
|
|
import "github.com/hslam/msg"
|
|
|
|
```
|
|
|
|
### Usage
|
|
|
|
#### Example
|
2020-11-28 23:10:51 +08:00
|
|
|
**msgsnd**
|
2020-11-27 18:41:43 +08:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hslam/ftok"
|
|
|
|
"github.com/hslam/msg"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
key, err := ftok.Ftok("/tmp", 0x22)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
msgid, err := msg.Get(key, msg.IPC_CREAT|0600)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer msg.Remove(msgid)
|
2020-12-01 16:57:00 +08:00
|
|
|
err = msg.Send(msgid, 1, []byte("Hello World"), 0600)
|
2020-11-27 18:41:43 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
}
|
|
|
|
```
|
2020-11-28 23:10:51 +08:00
|
|
|
**msgrcv**
|
2020-11-27 18:41:43 +08:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hslam/ftok"
|
|
|
|
"github.com/hslam/msg"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
key, err := ftok.Ftok("/tmp", 0x22)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
msgid, err := msg.Get(key, 0600)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-01 16:57:00 +08:00
|
|
|
text, err := msg.Receive(msgid, 1, 0600)
|
2020-11-27 18:41:43 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-11-29 01:54:53 +08:00
|
|
|
fmt.Println(string(text))
|
2020-11-27 18:41:43 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Output
|
|
|
|
```
|
|
|
|
Hello World
|
|
|
|
```
|
|
|
|
|
|
|
|
### License
|
|
|
|
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
|
|
|
|
|
|
|
|
|
|
|
|
### Author
|
|
|
|
msg was written by Meng Huang.
|
|
|
|
|
|
|
|
|