mirror of
https://github.com/smallnest/rpcx.git
synced 2025-12-24 12:27:56 +08:00
add golangci-lint
This commit is contained in:
32
Makefile
32
Makefile
@@ -6,41 +6,17 @@ vet:
|
||||
go vet ./...
|
||||
|
||||
tools:
|
||||
go get honnef.co/go/tools/cmd/staticcheck
|
||||
go get honnef.co/go/tools/cmd/gosimple
|
||||
go get honnef.co/go/tools/cmd/unused
|
||||
go get github.com/gordonklaus/ineffassign
|
||||
go get github.com/fzipp/gocyclo
|
||||
go get github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||
go get github.com/golang/lint/golint
|
||||
go get github.com/alexkohler/prealloc
|
||||
go get github.com/axw/gocov/gocov
|
||||
go get github.com/matm/gocov-html
|
||||
|
||||
gometalinter:
|
||||
gometalinter --enable-all ./...
|
||||
golangci-lint:
|
||||
golangci-lint run -D errcheck --build-tags 'quic kcp ping'
|
||||
|
||||
lint:
|
||||
golint ./...
|
||||
|
||||
staticcheck:
|
||||
staticcheck -ignore "$(shell cat .checkignore)" ./...
|
||||
|
||||
gosimple:
|
||||
gosimple -ignore "$(shell cat .gosimpleignore)" ./...
|
||||
|
||||
unused:
|
||||
unused ./...
|
||||
|
||||
ineffassign:
|
||||
ineffassign .
|
||||
|
||||
gocyclo:
|
||||
gocyclo -over 20 $(shell find . -name "*.go" |egrep -v "_testutils/*|vendor/*|pb\.go|_test\.go")
|
||||
|
||||
prealloc:
|
||||
prealloc ./...
|
||||
|
||||
check: staticcheck gosimple ineffassign
|
||||
|
||||
doc:
|
||||
godoc -http=:6060
|
||||
|
||||
|
||||
@@ -531,7 +531,7 @@ func (client *Client) send(ctx context.Context, call *Call) {
|
||||
}
|
||||
|
||||
if client.Plugins != nil {
|
||||
client.Plugins.DoClientBeforeEncode(req)
|
||||
_ = client.Plugins.DoClientBeforeEncode(req)
|
||||
}
|
||||
|
||||
data := req.EncodeSlicePointer()
|
||||
@@ -565,7 +565,7 @@ func (client *Client) send(ctx context.Context, call *Call) {
|
||||
}
|
||||
|
||||
if client.option.IdleTimeout != 0 {
|
||||
client.Conn.SetDeadline(time.Now().Add(client.option.IdleTimeout))
|
||||
_ = client.Conn.SetDeadline(time.Now().Add(client.option.IdleTimeout))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -576,7 +576,7 @@ func (client *Client) input() {
|
||||
for err == nil {
|
||||
var res = protocol.NewMessage()
|
||||
if client.option.IdleTimeout != 0 {
|
||||
client.Conn.SetDeadline(time.Now().Add(client.option.IdleTimeout))
|
||||
_ = client.Conn.SetDeadline(time.Now().Add(client.option.IdleTimeout))
|
||||
}
|
||||
|
||||
err = res.Decode(client.r)
|
||||
@@ -584,7 +584,7 @@ func (client *Client) input() {
|
||||
break
|
||||
}
|
||||
if client.Plugins != nil {
|
||||
client.Plugins.DoClientAfterDecode(res)
|
||||
_ = client.Plugins.DoClientAfterDecode(res)
|
||||
}
|
||||
|
||||
seq := res.Seq()
|
||||
@@ -619,7 +619,7 @@ func (client *Client) input() {
|
||||
data := res.Payload
|
||||
codec := share.Codecs[res.SerializeType()]
|
||||
if codec != nil {
|
||||
codec.Decode(data, call.Reply)
|
||||
_ = codec.Decode(data, call.Reply)
|
||||
}
|
||||
}
|
||||
call.done()
|
||||
|
||||
@@ -44,9 +44,11 @@ func TestClient_IT(t *testing.T) {
|
||||
server.UsePool = false
|
||||
|
||||
s := server.NewServer()
|
||||
s.RegisterName("Arith", new(Arith), "")
|
||||
s.RegisterName("PBArith", new(PBArith), "")
|
||||
go s.Serve("tcp", "127.0.0.1:0")
|
||||
_ = s.RegisterName("Arith", new(Arith), "")
|
||||
_ = s.RegisterName("PBArith", new(PBArith), "")
|
||||
go func() {
|
||||
_ = s.Serve("tcp", "127.0.0.1:0")
|
||||
}()
|
||||
defer s.Close()
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
@@ -112,8 +114,10 @@ func TestClient_IT(t *testing.T) {
|
||||
|
||||
func TestClient_IT_Concurrency(t *testing.T) {
|
||||
s := server.NewServer()
|
||||
s.RegisterName("PBArith", new(PBArith), "")
|
||||
go s.Serve("tcp", "127.0.0.1:0")
|
||||
_ = s.RegisterName("PBArith", new(PBArith), "")
|
||||
go func() {
|
||||
_ = s.Serve("tcp", "127.0.0.1:0")
|
||||
}()
|
||||
defer s.Close()
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ func (c *Client) Connect(network, address string) error {
|
||||
|
||||
if err == nil && conn != nil {
|
||||
if c.option.IdleTimeout != 0 {
|
||||
conn.SetDeadline(time.Now().Add(c.option.IdleTimeout))
|
||||
_ = conn.SetDeadline(time.Now().Add(c.option.IdleTimeout))
|
||||
}
|
||||
|
||||
if c.Plugins != nil {
|
||||
@@ -95,8 +95,8 @@ func newDirectConn(c *Client, network, address string) (net.Conn, error) {
|
||||
}
|
||||
|
||||
if tc, ok := conn.(*net.TCPConn); ok {
|
||||
tc.SetKeepAlive(true)
|
||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||
_ = tc.SetKeepAlive(true)
|
||||
_ = tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
@@ -133,7 +133,11 @@ func newDirectHTTPConn(c *Client, network, address string) (net.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
io.WriteString(conn, "CONNECT "+path+" HTTP/1.0\n\n")
|
||||
_, err = io.WriteString(conn, "CONNECT "+path+" HTTP/1.0\n\n")
|
||||
if err != nil {
|
||||
log.Errorf("failed to make CONNECT: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Require successful HTTP response
|
||||
// before switching to RPC protocol.
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
type ConsulDiscovery struct {
|
||||
basePath string
|
||||
kv store.Store
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
@@ -71,7 +72,9 @@ func NewConsulDiscoveryStore(basePath string, kv store.Store) ServiceDiscovery {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
d.RetriesAfterWatchFailed = -1
|
||||
go d.watch()
|
||||
return d
|
||||
@@ -108,6 +111,8 @@ func (d *ConsulDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *ConsulDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -194,7 +199,9 @@ func (d *ConsulDiscovery) watch() {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
type EtcdDiscovery struct {
|
||||
basePath string
|
||||
kv store.Store
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
@@ -82,7 +83,9 @@ func NewEtcdDiscoveryStore(basePath string, kv store.Store) ServiceDiscovery {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
d.RetriesAfterWatchFailed = -1
|
||||
|
||||
go d.watch()
|
||||
@@ -116,6 +119,8 @@ func (d *EtcdDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *EtcdDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -217,7 +222,9 @@ func (d *EtcdDiscovery) watch() {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
type EtcdV3Discovery struct {
|
||||
basePath string
|
||||
kv store.Store
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
@@ -85,7 +86,9 @@ func NewEtcdV3DiscoveryStore(basePath string, kv store.Store) ServiceDiscovery {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
d.RetriesAfterWatchFailed = -1
|
||||
|
||||
go d.watch()
|
||||
@@ -119,6 +122,9 @@ func (d *EtcdV3Discovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *EtcdV3Discovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -225,7 +231,9 @@ rewatch:
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
@@ -246,7 +254,7 @@ rewatch:
|
||||
}
|
||||
}
|
||||
|
||||
log.Warn("chan is closed and will rewatch")
|
||||
// log.Warn("chan is closed and will rewatch")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ type MDNSDiscovery struct {
|
||||
WatchInterval time.Duration
|
||||
domain string
|
||||
service string
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
|
||||
@@ -44,7 +45,9 @@ func NewMDNSDiscovery(service string, timeout time.Duration, watchInterval time.
|
||||
d.stopCh = make(chan struct{})
|
||||
|
||||
var err error
|
||||
d.pairsMu.Lock()
|
||||
d.pairs, err = d.browse()
|
||||
d.pairsMu.Unlock()
|
||||
if err != nil {
|
||||
log.Warnf("failed to browse services: %v", err)
|
||||
}
|
||||
@@ -72,6 +75,9 @@ func (d *MDNSDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *MDNSDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -113,7 +119,9 @@ func (d *MDNSDiscovery) watch() {
|
||||
case <-t.C:
|
||||
pairs, err := d.browse()
|
||||
if err == nil {
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -10,8 +10,9 @@ import (
|
||||
// MultipleServersDiscovery is a multiple servers service discovery.
|
||||
// It always returns the current servers and uses can change servers dynamically.
|
||||
type MultipleServersDiscovery struct {
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
@@ -34,6 +35,9 @@ func (d *MultipleServersDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the configured server
|
||||
func (d *MultipleServersDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -81,6 +85,10 @@ func (d *MultipleServersDiscovery) Update(pairs []*KVPair) {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
}
|
||||
|
||||
func (d *MultipleServersDiscovery) Close() {
|
||||
|
||||
@@ -26,9 +26,10 @@ type NacosDiscovery struct {
|
||||
|
||||
namingClient naming_client.INamingClient
|
||||
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
|
||||
filter ServiceDiscoveryFilter
|
||||
RetriesAfterWatchFailed int
|
||||
@@ -97,7 +98,9 @@ func (d *NacosDiscovery) fetch() {
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
}
|
||||
|
||||
// NewNacosDiscoveryTemplate returns a new NacosDiscovery template.
|
||||
@@ -121,6 +124,9 @@ func (d *NacosDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *NacosDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.RLock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -167,7 +173,9 @@ func (d *NacosDiscovery) watch() {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
type RedisDiscovery struct {
|
||||
basePath string
|
||||
kv store.Store
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
@@ -85,7 +86,9 @@ func NewRedisDiscoveryStore(basePath string, kv store.Store) ServiceDiscovery {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
d.RetriesAfterWatchFailed = -1
|
||||
|
||||
go d.watch()
|
||||
@@ -119,6 +122,9 @@ func (d *RedisDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *RedisDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.Lock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -224,7 +230,9 @@ func (d *RedisDiscovery) watch() {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -383,7 +383,7 @@ func splitNetworkAndAddress(server string) (string, string) {
|
||||
return ss[0], ss[1]
|
||||
}
|
||||
|
||||
func setServerTimeout(ctx context.Context) {
|
||||
func setServerTimeout(ctx context.Context) context.Context {
|
||||
if deadline, ok := ctx.Deadline(); ok {
|
||||
metadata := ctx.Value(share.ReqMetaDataKey)
|
||||
if metadata == nil {
|
||||
@@ -393,6 +393,8 @@ func setServerTimeout(ctx context.Context) {
|
||||
m := metadata.(map[string]string)
|
||||
m[share.ServerTimeout] = fmt.Sprintf("%d", time.Since(deadline).Milliseconds())
|
||||
}
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
// Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.
|
||||
@@ -412,7 +414,7 @@ func (c *xClient) Go(ctx context.Context, serviceMethod string, args interface{}
|
||||
m[share.AuthKey] = c.auth
|
||||
}
|
||||
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
_, client, err := c.selectClient(ctx, c.servicePath, serviceMethod, args)
|
||||
if err != nil {
|
||||
@@ -437,7 +439,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
m := metadata.(map[string]string)
|
||||
m[share.AuthKey] = c.auth
|
||||
}
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
var err error
|
||||
k, client, err := c.selectClient(ctx, c.servicePath, serviceMethod, args)
|
||||
@@ -614,7 +616,7 @@ func (c *xClient) SendRaw(ctx context.Context, r *protocol.Message) (map[string]
|
||||
m[share.AuthKey] = c.auth
|
||||
}
|
||||
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
var err error
|
||||
k, client, err := c.selectClient(ctx, r.ServicePath, r.ServiceMethod, r.Payload)
|
||||
@@ -732,7 +734,7 @@ func (c *xClient) Broadcast(ctx context.Context, serviceMethod string, args inte
|
||||
m[share.AuthKey] = c.auth
|
||||
}
|
||||
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
var clients = make(map[string]RPCClient)
|
||||
c.mu.Lock()
|
||||
@@ -805,7 +807,7 @@ func (c *xClient) Fork(ctx context.Context, serviceMethod string, args interface
|
||||
m[share.AuthKey] = c.auth
|
||||
}
|
||||
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
var clients = make(map[string]RPCClient)
|
||||
c.mu.Lock()
|
||||
@@ -894,7 +896,7 @@ func (c *xClient) SendFile(ctx context.Context, fileName string, rateInBytesPerS
|
||||
FileSize: fi.Size(),
|
||||
}
|
||||
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
reply := &share.FileTransferReply{}
|
||||
err = c.Call(ctx, "TransferFile", args, reply)
|
||||
@@ -955,7 +957,7 @@ loop:
|
||||
}
|
||||
|
||||
func (c *xClient) DownloadFile(ctx context.Context, requestFileName string, saveTo io.Writer) error {
|
||||
setServerTimeout(ctx)
|
||||
ctx = setServerTimeout(ctx)
|
||||
|
||||
args := share.DownloadFileArgs{
|
||||
FileName: requestFileName,
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
type ZookeeperDiscovery struct {
|
||||
basePath string
|
||||
kv store.Store
|
||||
pairsMu sync.RWMutex
|
||||
pairs []*KVPair
|
||||
chans []chan []*KVPair
|
||||
mu sync.Mutex
|
||||
@@ -73,7 +74,9 @@ func NewZookeeperDiscoveryWithStore(basePath string, kv store.Store) ServiceDisc
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
d.RetriesAfterWatchFailed = -1
|
||||
go d.watch()
|
||||
|
||||
@@ -111,6 +114,9 @@ func (d *ZookeeperDiscovery) SetFilter(filter ServiceDiscoveryFilter) {
|
||||
|
||||
// GetServices returns the servers
|
||||
func (d *ZookeeperDiscovery) GetServices() []*KVPair {
|
||||
d.pairsMu.Lock()
|
||||
defer d.pairsMu.RUnlock()
|
||||
|
||||
return d.pairs
|
||||
}
|
||||
|
||||
@@ -199,7 +205,9 @@ func (d *ZookeeperDiscovery) watch() {
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
d.pairsMu.Lock()
|
||||
d.pairs = pairs
|
||||
d.pairsMu.Unlock()
|
||||
|
||||
d.mu.Lock()
|
||||
for _, ch := range d.chans {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"reflect"
|
||||
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
pb "github.com/golang/protobuf/proto"
|
||||
"github.com/vmihailenco/msgpack"
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
)
|
||||
|
||||
@@ -13,44 +13,44 @@ type defaultLogger struct {
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Debug(v ...interface{}) {
|
||||
l.Output(calldepth, header("DEBUG", fmt.Sprint(v...)))
|
||||
_ = l.Output(calldepth, header("DEBUG", fmt.Sprint(v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Debugf(format string, v ...interface{}) {
|
||||
l.Output(calldepth, header("DEBUG", fmt.Sprintf(format, v...)))
|
||||
_ = l.Output(calldepth, header("DEBUG", fmt.Sprintf(format, v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Info(v ...interface{}) {
|
||||
l.Output(calldepth, header(color.GreenString("INFO "), fmt.Sprint(v...)))
|
||||
_ = l.Output(calldepth, header(color.GreenString("INFO "), fmt.Sprint(v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Infof(format string, v ...interface{}) {
|
||||
l.Output(calldepth, header(color.GreenString("INFO "), fmt.Sprintf(format, v...)))
|
||||
_ = l.Output(calldepth, header(color.GreenString("INFO "), fmt.Sprintf(format, v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Warn(v ...interface{}) {
|
||||
l.Output(calldepth, header(color.YellowString("WARN "), fmt.Sprint(v...)))
|
||||
_ = l.Output(calldepth, header(color.YellowString("WARN "), fmt.Sprint(v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Warnf(format string, v ...interface{}) {
|
||||
l.Output(calldepth, header(color.YellowString("WARN "), fmt.Sprintf(format, v...)))
|
||||
_ = l.Output(calldepth, header(color.YellowString("WARN "), fmt.Sprintf(format, v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Error(v ...interface{}) {
|
||||
l.Output(calldepth, header(color.RedString("ERROR"), fmt.Sprint(v...)))
|
||||
_ = l.Output(calldepth, header(color.RedString("ERROR"), fmt.Sprint(v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Errorf(format string, v ...interface{}) {
|
||||
l.Output(calldepth, header(color.RedString("ERROR"), fmt.Sprintf(format, v...)))
|
||||
_ = l.Output(calldepth, header(color.RedString("ERROR"), fmt.Sprintf(format, v...)))
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Fatal(v ...interface{}) {
|
||||
l.Output(calldepth, header(color.MagentaString("FATAL"), fmt.Sprint(v...)))
|
||||
_ = l.Output(calldepth, header(color.MagentaString("FATAL"), fmt.Sprint(v...)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Fatalf(format string, v ...interface{}) {
|
||||
l.Output(calldepth, header(color.MagentaString("FATAL"), fmt.Sprintf(format, v...)))
|
||||
_ = l.Output(calldepth, header(color.MagentaString("FATAL"), fmt.Sprintf(format, v...)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ func (c *SnappyCompressor) Zip(data []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
writer := snappy.NewWriter(&buffer)
|
||||
writer := snappy.NewBufferedWriter(&buffer)
|
||||
_, err := writer.Write(data)
|
||||
if err != nil {
|
||||
writer.Close()
|
||||
|
||||
@@ -55,7 +55,7 @@ type (s *{{$name}}) {{.Name}}(ctx context.Context, arg *{{.ReqName}}, reply *{{.
|
||||
func (si ServiceInfo) String() string {
|
||||
tpl := template.Must(template.New("service").Parse(siTemplate))
|
||||
var buf bytes.Buffer
|
||||
tpl.Execute(&buf, si)
|
||||
_ = tpl.Execute(&buf, si)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ func (s *Server) EnableFileTransfer(serviceName string, fileTransfer *FileTransf
|
||||
if serviceName == "" {
|
||||
serviceName = share.SendFileServiceName
|
||||
}
|
||||
fileTransfer.Start()
|
||||
s.RegisterName(serviceName, fileTransfer.service, "")
|
||||
_ = fileTransfer.Start()
|
||||
_ = s.RegisterName(serviceName, fileTransfer.service, "")
|
||||
}
|
||||
|
||||
func (s *FileTransferService) TransferFile(ctx context.Context, args *share.FileTransferArgs, reply *share.FileTransferReply) error {
|
||||
|
||||
@@ -826,12 +826,10 @@ func (s *Server) startProcess() (int, error) {
|
||||
|
||||
// Pass on the environment and replace the old count key with the new one.
|
||||
var env []string
|
||||
for _, v := range os.Environ() {
|
||||
env = append(env, v)
|
||||
}
|
||||
env = append(env, os.Environ()...)
|
||||
|
||||
var originalWD, _ = os.Getwd()
|
||||
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr})
|
||||
allFiles := []*os.File{os.Stdin, os.Stdout, os.Stderr}
|
||||
process, err := os.StartProcess(argv0, os.Args, &os.ProcAttr{
|
||||
Dir: originalWD,
|
||||
Env: env,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
metrics "github.com/rcrowley/go-metrics"
|
||||
"github.com/rpcxio/libkv"
|
||||
"github.com/rpcxio/libkv/store"
|
||||
@@ -108,7 +109,7 @@ func (p *ConsulRegisterPlugin) Start() error {
|
||||
for key, value := range extra {
|
||||
v.Set(key, value)
|
||||
}
|
||||
p.kv.Put(nodePath, []byte(v.Encode()), &store.WriteOptions{TTL: p.UpdateInterval * 2})
|
||||
_ = p.kv.Put(nodePath, []byte(v.Encode()), &store.WriteOptions{TTL: p.UpdateInterval * 2})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +143,7 @@ func (p *ConsulRegisterPlugin) Stop() error {
|
||||
continue
|
||||
}
|
||||
if exist {
|
||||
p.kv.Delete(nodePath)
|
||||
_ = p.kv.Delete(nodePath)
|
||||
log.Infof("delete path %s", nodePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ type teeConn struct {
|
||||
func (t *teeConn) Read(p []byte) (n int, err error) {
|
||||
n, err = t.Conn.Read(p)
|
||||
if n > 0 && t.w != nil {
|
||||
if _, err := t.w.Write(p[:n]); err != nil {
|
||||
// return n, err //discard error
|
||||
}
|
||||
t.w.Write(p[:n])
|
||||
// if _, err := t.w.Write(p[:n]); err != nil {
|
||||
// return n, err //discard error
|
||||
// }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
|
||||
}
|
||||
return v
|
||||
case *ast.StructType:
|
||||
if isExported(v.name) {
|
||||
//fmt.Printf("@@@@%s: %s\n", v.name, pretty.Sprint(n.Fields))
|
||||
//v.StructNames = append(v.StructNames, v.name)
|
||||
}
|
||||
// if isExported(v.name) {
|
||||
//fmt.Printf("@@@@%s: %s\n", v.name, pretty.Sprint(n.Fields))
|
||||
//v.StructNames = append(v.StructNames, v.name)
|
||||
// }
|
||||
return nil
|
||||
case *ast.FuncDecl:
|
||||
if isExported(v.name) {
|
||||
|
||||
@@ -69,7 +69,7 @@ func main() {
|
||||
}
|
||||
|
||||
parsers = append(parsers, p)
|
||||
generate(parsers)
|
||||
_ = generate(parsers)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
func TestLimitedPool_findPool(t *testing.T) {
|
||||
pool := NewLimitedPool(512, 4096)
|
||||
|
||||
type args struct {
|
||||
size int
|
||||
}
|
||||
tests := []struct {
|
||||
args int
|
||||
want int
|
||||
@@ -29,13 +26,13 @@ func TestLimitedPool_findPool(t *testing.T) {
|
||||
got := pool.findPool(tt.args)
|
||||
if got == nil {
|
||||
if tt.want > 0 {
|
||||
fmt.Errorf("expect %d pool but got nil", tt.want)
|
||||
fmt.Printf("expect %d pool but got nil", tt.want)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if got.size != tt.want {
|
||||
fmt.Errorf("expect %d pool but got %d pool", tt.want, got.size)
|
||||
fmt.Printf("expect %d pool but got %d pool", tt.want, got.size)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -44,9 +41,6 @@ func TestLimitedPool_findPool(t *testing.T) {
|
||||
func TestLimitedPool_findPutPool(t *testing.T) {
|
||||
pool := NewLimitedPool(512, 4096)
|
||||
|
||||
type args struct {
|
||||
size int
|
||||
}
|
||||
tests := []struct {
|
||||
args int
|
||||
want int
|
||||
@@ -65,13 +59,13 @@ func TestLimitedPool_findPutPool(t *testing.T) {
|
||||
got := pool.findPutPool(tt.args)
|
||||
if got == nil {
|
||||
if tt.want > 0 {
|
||||
fmt.Errorf("expect %d pool but got nil", tt.want)
|
||||
fmt.Printf("expect %d pool but got nil", tt.want)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if got.size != tt.want {
|
||||
fmt.Errorf("expect %d pool but got %d pool", tt.want, got.size)
|
||||
fmt.Printf("expect %d pool but got %d pool", tt.want, got.size)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user