mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-24 13:08:26 -05:00
fixed code smells: string literal repetition + cyclomatic complexity
This commit is contained in:
@@ -124,10 +124,6 @@ func NewService(options ...Option) (*Service, error) {
|
||||
// Start an rpc service. By default the package scope Start will run all default extensions to provide with a working
|
||||
// oCIS instance.
|
||||
func Start(o ...Option) error {
|
||||
// Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect
|
||||
// from the caller, the previous statement holds truth.
|
||||
|
||||
// prepare a new rpc Service struct.
|
||||
s, err := NewService(o...)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -171,10 +167,7 @@ func Start(o ...Option) error {
|
||||
s.cfg.Storage.Log = &shared.Log{}
|
||||
}
|
||||
|
||||
s.cfg.Storage.Log.Color = s.cfg.Commons.Color
|
||||
s.cfg.Storage.Log.Level = s.cfg.Commons.Level
|
||||
s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty
|
||||
s.cfg.Storage.Log.File = s.cfg.Commons.File
|
||||
propagateLoggingCommonsToStorages(s)
|
||||
|
||||
if err = rpc.Register(s); err != nil {
|
||||
if s != nil {
|
||||
@@ -188,16 +181,7 @@ func Start(o ...Option) error {
|
||||
s.Log.Fatal().Err(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
reason := strings.Builder{}
|
||||
if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
|
||||
reason.WriteString("runtime address already in use")
|
||||
}
|
||||
|
||||
fmt.Println(reason.String())
|
||||
}
|
||||
}()
|
||||
defer gracefulRecovery(s)
|
||||
|
||||
// prepare the set of services to run
|
||||
s.generateRunSet(s.cfg)
|
||||
@@ -222,6 +206,26 @@ func Start(o ...Option) error {
|
||||
return http.Serve(l, nil)
|
||||
}
|
||||
|
||||
func propagateLoggingCommonsToStorages(s *Service) {
|
||||
s.cfg.Storage.Log.Color = s.cfg.Commons.Color
|
||||
s.cfg.Storage.Log.Level = s.cfg.Commons.Level
|
||||
s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty
|
||||
s.cfg.Storage.Log.File = s.cfg.Commons.File
|
||||
}
|
||||
|
||||
func gracefulRecovery(s *Service) {
|
||||
func() {
|
||||
if r := recover(); r != nil {
|
||||
reason := strings.Builder{}
|
||||
if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
|
||||
reason.WriteString("runtime address already in use")
|
||||
}
|
||||
|
||||
fmt.Println(reason.String())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// scheduleServiceTokens adds service tokens to the service supervisor.
|
||||
func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) {
|
||||
for _, name := range runset {
|
||||
|
||||
Reference in New Issue
Block a user