Files

64 lines
1.1 KiB
Go
Raw Permalink Normal View History

2026-04-04 21:27:36 +02:00
package udpsender
import (
"bytes"
"fmt"
"io"
)
func getLinesChannel(f io.ReadCloser) <-chan string {
out := make(chan string, 1)
go func() {
defer f.Close()
defer close(out)
str := ""
for {
data := make([]byte, 8)
n, err := f.Read(data)
if err == io.EOF {
break
}
if err != nil {
fmt.Println("error reading file:", err)
return
}
data = data[:n]
if i := bytes.IndexByte(data, '\n'); i != -1 {
str += string(data[:i])
data = data[i+1:]
out <- str
str = ""
}
str += string(data)
}
if len(str) != 0 {
out <- str
}
}()
return out
}
//for line := range getLinesChannel(conn){
// fmt.Printf("read: %s\n",line)
// }
// var body []byte = nil
// var status response.StatusCode = response.StatusOK
// if handlerError != nil{
// status = handlerError.StatusCode
// body = []byte(handlerError.Message)
// }else{
// body = writer.Bytes()
// }
// headers.Replace("Content-Length", fmt.Sprintf("%d", len(body)))
// response.WriteStatusLine(conn,status)
// response.WriteHeaders(conn,headers)
// conn.Write(body)