1
0
mirror of https://github.com/hslam/msg.git synced 2025-04-25 13:48:50 +08:00
hslam_msg/README.md

88 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2020-11-27 18:32:27 +08:00
# msg
2020-11-27 18:41:43 +08:00
[![PkgGoDev](https://pkg.go.dev/badge/github.com/hslam/msg)](https://pkg.go.dev/github.com/hslam/msg)
2020-12-18 13:03:35 +08:00
[![Build Status](https://github.com/hslam/msg/workflows/build/badge.svg)](https://github.com/hslam/msg/actions)
2020-11-27 18:41:43 +08:00
[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/msg)](https://goreportcard.com/report/github.com/hslam/msg)
[![LICENSE](https://img.shields.io/github/license/hslam/msg.svg?style=flat-square)](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.