input Getenvs to FlagXYZ

This commit is contained in:
bel
2023-03-25 10:58:13 -06:00
parent ae1e32391c
commit a1a12b1873
9 changed files with 45 additions and 20 deletions

View File

@@ -8,6 +8,10 @@ import (
"strconv"
)
var (
FlagDebug = os.Getenv("DEBUG") == "true"
)
type UDP struct {
conn net.PacketConn
c chan []byte
@@ -29,14 +33,13 @@ func NewUDP(ctx context.Context, port int) UDP {
}
func (udp UDP) listen() {
debugging := os.Getenv("DEBUG") == "true"
for udp.ctx.Err() == nil {
buff := make([]byte, 256)
n, _, err := udp.conn.ReadFrom(buff)
if err != nil && udp.ctx.Err() == nil {
panic(err)
}
if debugging {
if FlagDebug {
log.Printf("raw.UDP.Read() => %s", buff[:n])
}
select {