Skip to content

Commit

Permalink
去除 defaults 的常量
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Nov 27, 2023
1 parent 6b3e4df commit c4baef7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
KB
MB
GB

Day = 24 * time.Hour
)

// parseByteSize parse size with given unit information.
Expand Down Expand Up @@ -89,7 +91,7 @@ func parseTimeDuration(s string) (time.Duration, error) {
return 0, err
}

return time.Duration(days) * 24 * time.Hour, nil
return time.Duration(days) * Day, nil
}

return time.ParseDuration(s)
Expand Down
15 changes: 11 additions & 4 deletions rotate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ package rotate
import (
"os"
"time"

"github.com/FishGoddess/logit/defaults"
)

const (
MB = 1024 * 1024
Day = 24 * time.Hour
)

// config stores some fields of file.
Expand Down Expand Up @@ -46,11 +53,11 @@ type config struct {
// newDefaultConfig returns a default config.
func newDefaultConfig() config {
return config{
mode: 0644,
dirMode: 0755,
mode: defaults.FileMode,
dirMode: defaults.FileDirMode,
timeFormat: "20060102150405",
maxSize: 256 * 1024 * 1024, // 256 MB
maxAge: 90 * 24 * time.Hour, // 90 days
maxSize: 256 * MB,
maxAge: 90 * Day,
maxBackups: 100,
}
}
6 changes: 3 additions & 3 deletions writer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
// minBufferSize is the min size of buffer.
// A panic will happen if buffer size is smaller than it.
minBufferSize = 4
minBufferSize = 16
)

// bufferWriter is a writer having a buffer inside to reduce times of writing underlying writer.
Expand All @@ -49,8 +49,8 @@ type bufferWriter struct {
// Notice that bufferSize must be larger than minBufferSize or a panic will happen. See minBufferSize.
// The size we want to use is bufferSize, but we add more bytes to it for avoiding buffer growing up.
func newBufferWriter(writer io.Writer, bufferSize uint64) *bufferWriter {
if bufferSize <= minBufferSize {
panic(fmt.Errorf("bufferSize %d <= minBufferSize %d", bufferSize, minBufferSize))
if bufferSize < minBufferSize {
panic(fmt.Errorf("bufferSize %d < minBufferSize %d", bufferSize, minBufferSize))
}

return &bufferWriter{
Expand Down

0 comments on commit c4baef7

Please sign in to comment.