-
Notifications
You must be signed in to change notification settings - Fork 0
/
zpl.go
50 lines (39 loc) · 880 Bytes
/
zpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
)
func main() {
var (
address string
conn net.Conn
label string
labelBytes []byte
payloadBytes []byte
respBytes []byte
err error
)
flag.StringVar(&address, "address", "localhost:11382", "Address of zebra proxy printer")
flag.Parse()
if labelBytes, err = ioutil.ReadAll(os.Stdin); err != nil {
log.Fatal(err)
}
label = string(labelBytes)
if conn, err = net.Dial("tcp", address); err != nil {
log.Fatal(err)
}
defer conn.Close()
payloadBytes = []byte(fmt.Sprintf("%s\r\n\r\n", label))
if _, err = conn.Write(payloadBytes); err != nil {
log.Fatal(err)
}
if respBytes, err = ioutil.ReadAll(conn); err != nil {
log.Fatal(err)
}
fmt.Println(string(bytes.TrimSpace(respBytes)))
}