8000 remove NewRequestServerWithOptions · etherscan-io/sftp@2fc6848 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fc6848

Browse files
committed
remove NewRequestServerWithOptions
we can keep compatibility removing the error return value from RequestServerOption
1 parent 1f178f9 commit 2fc6848

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

request-server.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,24 @@ type RequestServer struct {
3232
handleCount int
3333
}
3434

35-
// NewRequestServer creates/allocates/returns new RequestServer.
36-
// Normally there will be one server per user-session.
37-
//
38-
// Deprecated: please use NewRequestServerWithOptions
39-
func NewRequestServer(rwc io.ReadWriteCloser, h Handlers) *RequestServer {
40-
rs, _ := NewRequestServerWithOptions(rwc, h)
41-
return rs
42-
}
43-
4435
// A RequestServerOption is a function which applies configuration to a RequestServer.
45-
type RequestServerOption func(*RequestServer) error
36+
type RequestServerOption func(*RequestServer)
4637

4738
// WithRSAllocator enable the allocator.
4839
// After processing a packet we keep in memory the allocated slices
4940
// and we reuse them for new packets.
5041
// The allocator is experimental
5142
func WithRSAllocator() RequestServerOption {
52-
return func(rs *RequestServer) error {
43+
return func(rs *RequestServer) {
5344
alloc := newAllocator()
5445
rs.pktMgr.alloc = alloc
5546
rs.conn.alloc = alloc
56-
return nil
5747
}
5848
}
5949

60-
// NewRequestServerWithOptions creates/allocates/returns new RequestServer adding the specified options
61-
// If options is nil or empty this is equivalent to NewRequestServer
62-
func NewRequestServerWithOptions(rwc io.ReadWriteCloser, h Handlers, options ...RequestServerOption) (*RequestServer, error) {
50+
// NewRequestServer creates/allocates/returns new RequestServer.
51+
// Normally there will be one server per user-session.
52+
func NewRequestServer(rwc io.ReadWriteCloser, h Handlers, options ...RequestServerOption) *RequestServer {
6353
svrConn := &serverConn{
6454
conn: conn{
6555
Reader: rwc,
@@ -74,11 +64,9 @@ func NewRequestServerWithOptions(rwc io.ReadWriteCloser, h Handlers, options ...
7464
}
7565

7666
for _, o := range options {
77-
if err := o(rs); err != nil {
78-
return nil, err
79-
}
67+
o(rs)
8068
}
81-
return rs, nil
69+
return rs
8270
}
8371

8472
// New Open packet/Request

request-server_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ func clientRequestServerPair(t *testing.T) *csPair {
4646
fd, err := l.Accept()
4747
assert.Nil(t, err)
4848
handlers := InMemHandler()
49+
var options []RequestServerOption
4950
if *testAllocator {
50-
options := []RequestServerOption{WithRSAllocator()}
51-
server, _ = NewRequestServerWithOptions(fd, handlers, options...)
52-
} else {
53-
server = NewRequestServer(fd, handlers)
51+
options = append(options, WithRSAllocator())
5452
}
53+
server = NewRequestServer(fd, handlers, options...)
5554
server.Serve()
5655
}()
5756
<-ready

0 commit comments

Comments
 (0)
0