Skip to content

Commit

Permalink
add: add auto newline config
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzix committed Feb 23, 2018
1 parent a6c8690 commit 738ef3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions server/models/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type UdpConf struct {
}

type ReaderConf struct {
Interval int `toml:"interval"`
ReadBuffer int `toml:"read_buffer"`
ReadChan int `toml:"read_chan"`
Interval int `toml:"interval"`
ReadBuffer int `toml:"read_buffer"`
ReadChan int `toml:"read_chan"`
AutoNewline bool `toml:"auto_newline"`
}

type SenderConf struct {
Expand Down Expand Up @@ -50,6 +51,8 @@ interval = 60
read_buffer = 1048576
# channel 容量(理论上channel容量越大 缓冲性能越好但会消耗更多的内存)
read_chan = 10000
# 每行结尾是否追加换行符
auto_newline = false
#发送服务器配置
[sender]
Expand Down
7 changes: 5 additions & 2 deletions server/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ func (reader *Reader) WriteContent(filename, content string) {
//关闭文件,删除file descriptor
go func() {
select {
case <-time.After(time.Duration(ServerConf.Reader.Interval) * 60 * time.Second):
case <-time.After(time.Duration(ServerConf.Reader.Interval) * time.Minute):
reader.files[filename].Close()
delete(reader.files, filename)
}
}()
}
file := reader.files[filename]
// file.WriteString(content + "\n")
if ServerConf.Reader.AutoNewline{
file.WriteString(content + "\n")
return
}
file.WriteString(content)
}

Expand Down

0 comments on commit 738ef3e

Please sign in to comment.