Initial commit
This commit is contained in:
63
cmd/udpsender/main.go
Normal file
63
cmd/udpsender/main.go
Normal file
@@ -0,0 +1,63 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user