micro--go-micro
3e885308a0
Fixes #2988. Brings 'golangci-lint run ./...' to zero issues (was ~373): - errcheck: explicitly ignore fire-and-forget calls with '_ =' (and a small errcheck.exclude-functions list for response writes — json Encoder.Encode, http ResponseWriter.Write, fmt.Fprint*); genuine cases handled. - unused: remove dead code (unexported decls and dead test helpers) and the imports they orphaned. - staticcheck: ST1005 error strings, ST1016 receiver names, S1000/S1017/S1019/ S1023 simplifications, SA4004/SA4006/SA4010 dead code, SA1021 net.IP.Equal, SA6002 (store *[]byte in sync.Pool). - govet: fix a context leak (lostcancel) in internal/util/mdns and move t.Fatal/Fatalf out of goroutines (testinggoroutine) in tests. - ineffassign, unconvert: mechanical fixes. CI: the Lint workflow now runs a blocking full-tree 'golangci-lint run' on pushes and PRs (dropped only-new-issues now that the tree is clean). Verified: go build, go vet, test compilation, and unit tests for the behaviourally-touched packages all pass. Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL Co-authored-by: Claude <noreply@anthropic.com>
86 行
1.5 KiB
Go
86 行
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"go-micro.dev/v6/codec"
|
|
"go-micro.dev/v6/registry"
|
|
)
|
|
|
|
// isRegistered will check if the service has already been registered.
|
|
func (s *rpcServer) isRegistered() bool {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
return s.registered
|
|
}
|
|
|
|
// setStarted will set started state safely.
|
|
func (s *rpcServer) setStarted(b bool) {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
|
|
s.started = b
|
|
}
|
|
|
|
// isStarted will check if the service has already been started.
|
|
func (s *rpcServer) isStarted() bool {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
return s.started
|
|
}
|
|
|
|
// getWaitgroup returns the global waitgroup safely.
|
|
func (s *rpcServer) getWg() *sync.WaitGroup {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
return s.wg
|
|
}
|
|
|
|
// setOptsAddr will set the address in the service options safely.
|
|
func (s *rpcServer) setOptsAddr(addr string) {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
|
|
s.opts.Address = addr
|
|
}
|
|
|
|
func (s *rpcServer) getCachedService() *registry.Service {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
return s.rsvc
|
|
}
|
|
|
|
func (s *rpcServer) Options() Options {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
return s.opts
|
|
}
|
|
|
|
// swapAddr swaps the address found in the config and the transport address.
|
|
func (s *rpcServer) swapAddr(config Options, addr string) string {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
|
|
a := config.Address
|
|
s.opts.Address = addr
|
|
return a
|
|
}
|
|
|
|
func (s *rpcServer) newCodec(contentType string) (codec.NewCodec, error) {
|
|
if cf, ok := s.opts.Codecs[contentType]; ok {
|
|
return cf, nil
|
|
}
|
|
|
|
if cf, ok := DefaultCodecs[contentType]; ok {
|
|
return cf, nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("unsupported Content-Type: %s", contentType)
|
|
}
|