-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: forever read + Feat: listen on unix socket
- Loading branch information
1 parent
78b145d
commit 82d1803
Showing
8 changed files
with
300 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package putxt | ||
|
||
import ( | ||
"time" | ||
|
||
"git.tcp.direct/kayos/common/pool" | ||
"github.com/yunginnanet/Rate5" | ||
) | ||
|
||
type TermDumpster struct { | ||
gzip bool | ||
maxSize int64 | ||
timeout time.Duration | ||
handler Handler | ||
log Logger | ||
Pool pool.BufferFactory | ||
*rate5.Limiter | ||
} | ||
|
||
func NewTermDumpster(handler Handler) *TermDumpster { | ||
td := &TermDumpster{ | ||
maxSize: 3 << 20, | ||
timeout: 5 * time.Second, | ||
Limiter: rate5.NewStrictLimiter(60, 5), | ||
handler: handler, | ||
log: dummyLogger{}, | ||
Pool: pool.NewBufferFactory(), | ||
} | ||
return td | ||
} | ||
|
||
func (td *TermDumpster) WithGzip() *TermDumpster { | ||
td.gzip = true | ||
return td | ||
} | ||
|
||
func (td *TermDumpster) WithMaxSize(size int64) *TermDumpster { | ||
td.maxSize = size | ||
return td | ||
} | ||
|
||
func (td *TermDumpster) WithTimeout(timeout time.Duration) *TermDumpster { | ||
td.timeout = timeout | ||
return td | ||
} | ||
|
||
func (td *TermDumpster) WithLogger(logger Logger) *TermDumpster { | ||
td.log = logger | ||
return td | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package putxt | ||
|
||
import "fmt" | ||
|
||
const ( | ||
MessageRatelimited = "RATELIMIT_REACHED" | ||
MessageSizeLimited = "MAX_SIZE_EXCEEDED" | ||
MessageBinaryData = "BINARY_DATA_REJECTED" | ||
MessageInternalError = "INTERNAL_ERROR" | ||
) | ||
|
||
type Logger interface { | ||
Printf(format string, v ...interface{}) | ||
} | ||
|
||
type dummyLogger struct{} | ||
|
||
func (dummyLogger) Printf(format string, v ...interface{}) { | ||
_, _ = fmt.Printf(format, v...) | ||
} |
Oops, something went wrong.