ronantakizawa/codereview-bench huggingface dataset:
Repository: cloudwego/kitex
File: pkg/retry/retryer.go (Go)

Code before:
func (rc *Container) Dump() interface{} {
	rc.RLock()
	dm := make(map[string]interface{})
	dm["has_code_cfg"] = rc.hasCodeCfg
	rc.retryerMap.Range(func(key, value interface{}) bool {
		if r, ok := value.(Retryer); ok {
			dm[key.(string)] = r.Dump()
		}
		return true
	})
	if rc.msg != "" {
		dm["msg"] = rc.msg
	}
	rc.RUnlock()
	return dm
}

func (rc *Container) initRetryer(method string, p Policy) error {
	retryer, err := NewRetryer(p, rc.shouldResultRetry, rc.cbContainer)
	if err != nil {
		errMsg := fmt.Sprintf("new retryer[%s-%s] failed, err=%s, at %s", method, p.Type, err.Error(), time.Now())
		rc.msg = errMsg
		klog.Warnf(errMsg)
		return err
	}
	// NewRetryer can return nil if policy is nil
	if retryer != nil {
		rc.retryerMap.Store(method, retryer)
		if p.Enable {
			rc.msg = fmt.Sprintf("new retryer[%s-%s] at %s", method, retryer.Type(), time.Now())
		} else {
			rc.msg = fmt.Sprintf("disable retryer[%s-%s](enable=%t) %s", method, p.Type, p.Enable, time.Now())
		}
	} else {
		rc.msg = fmt.Sprintf("disable retryer[%s-%s](enable=%t) %s", method, p.Type, p.Enable, time.Now())
	}
	return nil
}

func (rc *Container) updateRetryer(rr *ShouldResultRetry) {
	rc.Lock()
	defer rc.Unlock()

	rc.shouldResultRetry = rr
	if rc.shouldResultRetry != nil {
		rc.retryerMap.Range(func(key, value interface{}) bool {
			if fr, ok := value.(*failureRetryer); ok {
				fr.setSpecifiedResultRetryIfNeeded(rc.shouldResultRetry)
			}
			return true
		})

Review comment (suggestion):
This comment should be deleted, because after this change, NewRetryer will always return a non-nil Retryer if no error happens. So should be the `else` branch.

Code after:
func (rc *Container) Dump() interface{} {
	rc.RLock()
	dm := make(map[string]interface{})
	dm["has_code_cfg"] = rc.hasCodeCfg
	rc.retryerMap.Range(func(key, value interface{}) bool {
		if r, ok := value.(Retryer); ok {
			dm[key.(string)] = r.Dump()
		}
		return true
	})
	if rc.msg != "" {
		dm["msg"] = rc.msg
	}
	rc.RUnlock()
	return dm
}

func (rc *Container) initRetryer(method string, p Policy) error {
	retryer, err := NewRetryer(p, rc.shouldResultRetry, rc.cbContainer)
	if err != nil {
		errMsg := fmt.Sprintf("new retryer[%s-%s] failed, err=%s, at %s", method, p.Type, err.Error(), time.Now())
		rc.msg = errMsg
		klog.Warnf(errMsg)
		return err
	}

	rc.retryerMap.Store(method, retryer)
	if p.Enable {
		rc.msg = fmt.Sprintf("new retryer[%s-%s] at %s", method, retryer.Type(), time.Now())
	} else {
		rc.msg = fmt.Sprintf("disable retryer[%s-%s](enable=%t) %s", method, p.Type, p.Enable, time.Now())
	}
	return nil
}

func (rc *Container) updateRetryer(rr *ShouldResultRetry) {
	rc.Lock()
	defer rc.Unlock()

	rc.shouldResultRetry = rr
	if rc.shouldResultRetry != nil {
		rc.retryerMap.Range(func(key, value interface{}) bool {
			if fr, ok := value.(*failureRetryer); ok {
				fr.setSpecifiedResultRetryIfNeeded(rc.shouldResultRetry)
			}
			return true
		})
	}
}
Repository: cloudwego/kitex
File: server/server.go (Go)

Code before:
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		return errors.New("handler is nil. please specify non-nil handler")
	}
	if s.svcMap[svcInfo.ServiceName] != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}
	s.Lock()
	svc := serviceinfo.NewService(svcInfo, handler)
	s.svcMap[svcInfo.ServiceName] = &svc
	s.Unlock()
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfoKey, diagnosis.WrapAsProbeFunc(s.svcMap[svcInfo.ServiceName].GetServiceInfo()))
	return nil
}

func (s *server) GetServices() map[string]*serviceinfo.Service {
	return s.svcMap
}

// Run runs the server.
func (s *server) Run() (err error) {
	if err = s.check(); err != nil {
		return err
	}
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}

	s.fillMoreServiceInfo(s.opt.RemoteOpt.Address)
	s.richRemoteOption()
	transHdlr, err := s.newSvrTransHandler()
	if err != nil {
		return err
	}
	s.Lock()
	s.svr, err = remotesvr.NewServer(s.opt.RemoteOpt, s.eps, transHdlr)
	s.Unlock()
	if err != nil {
		return err
	}

	// start profiler
	if s.opt.RemoteOpt.Profiler != nil {
		gofunc.GoFunc(context.Background(), func() {
			klog.Info("KITEX: server starting profiler")
			err := s.opt.RemoteOpt.Profiler.Run(context.Background())
			if err != nil {

Review comment (suggestion):
You also need to pass the whole s.svcMap into `diagnosis.RegisterProbeFunc`, and modify codes in internal repo.

Code after:
	if s.isRun {
		panic("service cannot be registered while server is running")
	}
	if svcInfo == nil {
		panic("svcInfo is nil. please specify non-nil svcInfo")
	}
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		panic("handler is nil. please specify non-nil handler")
	}
	if s.svcs.getService(svcInfo.ServiceName) != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}

	s.svcs.addService(svcInfo, handler)
	return nil
}

func (s *server) GetServiceInfos() map[string]*serviceinfo.ServiceInfo {
	return s.svcs.getSvcInfoMap()
}

// Run runs the server.
func (s *server) Run() (err error) {
	s.Lock()
	s.isRun = true
	s.Unlock()
	if err = s.check(); err != nil {
		return err
	}
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfosKey, diagnosis.WrapAsProbeFunc(s.svcs.getSvcInfoMap()))
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}

	s.fillMoreServiceInfo(s.opt.RemoteOpt.Address)
	s.richRemoteOption()
	transHdlr, err := s.newSvrTransHandler()
	if err != nil {
		return err
	}
	s.Lock()
	s.svr, err = remotesvr.NewServer(s.opt.RemoteOpt, s.eps, transHdlr)
	s.Unlock()
	if err != nil {
		return err
	}
Repository: cloudwego/kitex
File: server/server.go (Go)

Code before:
}

func (s *server) buildInvokeChain() {
	innerHandlerEp := s.invokeHandleEndpoint()
	s.eps = endpoint.Chain(s.mws...)(innerHandlerEp)
}

// RegisterService should not be called by users directly.
func (s *server) RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}) error {
	if svcInfo == nil {
		return errors.New("svcInfo is nil. please specify non-nil svcInfo")
	}
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		return errors.New("handler is nil. please specify non-nil handler")
	}
	if s.svcMap[svcInfo.ServiceName] != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}
	s.Lock()
	svc := serviceinfo.NewService(svcInfo, handler)
	s.svcMap[svcInfo.ServiceName] = &svc
	s.Unlock()
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfoKey, diagnosis.WrapAsProbeFunc(s.svcMap[svcInfo.ServiceName].GetServiceInfo()))
	return nil
}

func (s *server) GetServices() map[string]*serviceinfo.Service {
	return s.svcMap
}

// Run runs the server.
func (s *server) Run() (err error) {
	if err = s.check(); err != nil {
		return err
	}
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}

	s.fillMoreServiceInfo(s.opt.RemoteOpt.Address)
	s.richRemoteOption()
	transHdlr, err := s.newSvrTransHandler()
	if err != nil {
		return err
	}
	s.Lock()

Review comment (suggestion):
To avoid user call Run without calling RegisterService, this judgement is necessary and you can use `if len(s.svcMap) = 0 ` to replace it.

Code after:
	}
}

func (s *server) buildInvokeChain() {
	innerHandlerEp := s.invokeHandleEndpoint()
	s.eps = endpoint.Chain(s.mws...)(innerHandlerEp)
}

// RegisterService should not be called by users directly.
func (s *server) RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}) error {
	s.Lock()
	defer s.Unlock()
	if s.isRun {
		panic("service cannot be registered while server is running")
	}
	if svcInfo == nil {
		panic("svcInfo is nil. please specify non-nil svcInfo")
	}
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		panic("handler is nil. please specify non-nil handler")
	}
	if s.svcs.getService(svcInfo.ServiceName) != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}

	s.svcs.addService(svcInfo, handler)
	return nil
}

func (s *server) GetServiceInfos() map[string]*serviceinfo.ServiceInfo {
	return s.svcs.getSvcInfoMap()
}

// Run runs the server.
func (s *server) Run() (err error) {
	s.Lock()
	s.isRun = true
	s.Unlock()
	if err = s.check(); err != nil {
		return err
	}
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfosKey, diagnosis.WrapAsProbeFunc(s.svcs.getSvcInfoMap()))
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}
Repository: cloudwego/kitex
File: server/server.go (Go)

Code before:
	if svcInfo == nil {
		panic("svcInfo is nil. please specify non-nil svcInfo")
	}
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		panic("handler is nil. please specify non-nil handler")
	}
	if s.svcs.getService(svcInfo.ServiceName) != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}

	s.Lock()
	defer s.Unlock()
	s.svcs.addService(svcInfo, handler)
	return nil
}

func (s *server) GetServiceInfos() map[string]*serviceinfo.ServiceInfo {
	return s.svcs.getSvcInfoMap()
}

// Run runs the server.
func (s *server) Run() (err error) {
	if err = s.check(); err != nil {
		return err
	}
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfosKey, diagnosis.WrapAsProbeFunc(s.svcs.getSvcInfoMap()))
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}

	s.fillMoreServiceInfo(s.opt.RemoteOpt.Address)
	s.richRemoteOption()
	transHdlr, err := s.newSvrTransHandler()
	if err != nil {
		return err
	}
	s.Lock()
	s.svr, err = remotesvr.NewServer(s.opt.RemoteOpt, s.eps, transHdlr)
	s.Unlock()
	if err != nil {
		return err
	}

	// start profiler
	if s.opt.RemoteOpt.Profiler != nil {
		gofunc.GoFunc(context.Background(), func() {

Review comment (suggestion):
```golang
s.Lock()
s.isRun = true
s.Unlock()
```

Code after:
		panic("service cannot be registered while server is running")
	}
	if svcInfo == nil {
		panic("svcInfo is nil. please specify non-nil svcInfo")
	}
	if handler == nil || reflect.ValueOf(handler).IsNil() {
		panic("handler is nil. please specify non-nil handler")
	}
	if s.svcs.getService(svcInfo.ServiceName) != nil {
		panic(fmt.Sprintf("Service[%s] is already defined", svcInfo.ServiceName))
	}

	s.svcs.addService(svcInfo, handler)
	return nil
}

func (s *server) GetServiceInfos() map[string]*serviceinfo.ServiceInfo {
	return s.svcs.getSvcInfoMap()
}

// Run runs the server.
func (s *server) Run() (err error) {
	s.Lock()
	s.isRun = true
	s.Unlock()
	if err = s.check(); err != nil {
		return err
	}
	diagnosis.RegisterProbeFunc(s.opt.DebugService, diagnosis.ServiceInfosKey, diagnosis.WrapAsProbeFunc(s.svcs.getSvcInfoMap()))
	svrCfg := s.opt.RemoteOpt
	addr := svrCfg.Address // should not be nil
	if s.opt.Proxy != nil {
		svrCfg.Address, err = s.opt.Proxy.Replace(addr)
		if err != nil {
			return
		}
	}

	s.fillMoreServiceInfo(s.opt.RemoteOpt.Address)
	s.richRemoteOption()
	transHdlr, err := s.newSvrTransHandler()
	if err != nil {
		return err
	}
	s.Lock()
	s.svr, err = remotesvr.NewServer(s.opt.RemoteOpt, s.eps, transHdlr)
	s.Unlock()
	if err != nil {
		return err
	}
Repository: cloudwego/kitex
File: pkg/rpcinfo/remoteinfo/remoteInfo.go (Go)

Code before:
	"github.com/cloudwego/kitex/pkg/kerrors"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
)

// RemoteInfo implements a rpcinfo.EndpointInfo with mutable address and connection.
// It is typically used to represent server info on client side or client info on server side.
type RemoteInfo interface {
	rpcinfo.EndpointInfo
	SetServiceName(name string)
	SetTag(key, value string) error
	ForceSetTag(key, value string)

	// SetTagLock freezes a key of the tags and refuses further modification on its value.
	SetTagLock(key string)
	GetInstance() discovery.Instance
	SetInstance(ins discovery.Instance)

	// SetRemoteAddr tries to set the network address of the discovery.Instance hold by RemoteInfo.
	// The result indicates whether the modification is successful.
	SetRemoteAddr(addr net.Addr) (ok bool)
	ImmutableView() rpcinfo.EndpointInfo
}

// RemoteAddrSetter is used to set remote addr.
type RemoteAddrSetter interface {
	SetRemoteAddr(addr net.Addr) discovery.Instance
}

var (
	_              RemoteInfo = &remoteInfo{}
	remoteInfoPool sync.Pool
)

type remoteInfo struct {
	sync.RWMutex
	serviceName string
	method      string
	tags        map[string]string

	instance discovery.Instance
	tagLocks map[string]struct{}
}

func init() {
	remoteInfoPool.New = newRemoteInfo
}

func newRemoteInfo() interface{} {
	return &remoteInfo{
		tags:     make(map[string]string),
		tagLocks: make(map[string]struct{}),

Review comment (suggestion):
add comment for this method, why return discovery.Instance. it is better to rename, eg
`GetNewInstanceWithAddr() `

Code after:
	"github.com/cloudwego/kitex/pkg/kerrors"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
)

// RemoteInfo implements a rpcinfo.EndpointInfo with mutable address and connection.
// It is typically used to represent server info on client side or client info on server side.
type RemoteInfo interface {
	rpcinfo.EndpointInfo
	SetServiceName(name string)
	SetTag(key, value string) error
	ForceSetTag(key, value string)

	// SetTagLock freezes a key of the tags and refuses further modification on its value.
	SetTagLock(key string)
	GetInstance() discovery.Instance
	SetInstance(ins discovery.Instance)

	// SetRemoteAddr tries to set the network address of the discovery.Instance hold by RemoteInfo.
	// The result indicates whether the modification is successful.
	SetRemoteAddr(addr net.Addr) (ok bool)
	ImmutableView() rpcinfo.EndpointInfo
}

// RefreshableInstance declares an interface which can return an instance containing the new address.
type RefreshableInstance interface {
	RefreshInstanceWithAddr(addr net.Addr) (newInstance discovery.Instance)
}

var (
	_              RemoteInfo = &remoteInfo{}
	remoteInfoPool sync.Pool
)

type remoteInfo struct {
	sync.RWMutex
	serviceName string
	method      string
	tags        map[string]string

	instance discovery.Instance
	tagLocks map[string]struct{}
}

func init() {
	remoteInfoPool.New = newRemoteInfo
}

func newRemoteInfo() interface{} {
	return &remoteInfo{
		tags:     make(map[string]string),
		tagLocks: make(map[string]struct{}),
Repository: cloudwego/kitex
File: pkg/rpcinfo/invocation.go (Go)

Code before:
	}
	i.extra[key] = value
}

func (i *invocation) GetExtra(key string) interface{} {
	return i.extra[key]
}

// Reset implements the InvocationSetter interface.
func (i *invocation) Reset() {
	i.zero()
}

// Recycle reuses the invocation.
func (i *invocation) Recycle() {
	i.zero()
	invocationPool.Put(i)
}

func (i *invocation) zero() {
	i.seqID = 0
	i.packageName = ""
	i.serviceName = ""
	i.methodName = ""
	i.bizErr = nil
	i.extra = nil
}


Review comment (suggestion):
```go
if len(i.extra) > 0 {
    for {
        delete
    }
}
```

Code after:
	}
	i.extra[key] = value
}

func (i *invocation) Extra(key string) interface{} {
	if i.extra == nil {
		return nil
	}
	return i.extra[key]
}

// Reset implements the InvocationSetter interface.
func (i *invocation) Reset() {
	i.zero()
}

// Recycle reuses the invocation.
func (i *invocation) Recycle() {
	i.zero()
	invocationPool.Put(i)
}

func (i *invocation) zero() {
	i.seqID = 0
	i.packageName = ""
	i.serviceName = ""
	i.methodName = ""
	i.bizErr = nil
	for key := range i.extra {
		delete(i.extra, key)
	}
}
Repository: cloudwego/kitex
File: pkg/retry/failure_retryer.go (Go)

Code before:
}

// Dump implements the Retryer interface.
func (r *failureRetryer) Dump() map[string]interface{} {
	r.RLock()
	defer r.RUnlock()
	dm := make(map[string]interface{})
	dm["enable"] = r.enable
	dm["failure_retry"] = r.policy
	if r.policy != nil {
		dm["specified_result_retry"] = map[string]bool{
			"error_retry": r.policy.IsErrorRetryNonNil(),
			"resp_retry":  r.policy.IsRespRetryNonNil(),
		}
	}
	if r.errMsg != "" {
		dm["errMsg"] = r.errMsg
	}
	return dm
}

func (r *failureRetryer) setSpecifiedResultRetryIfNeeded(rr *ShouldResultRetry) {
	if rr != nil {
		r.specifiedResultRetry = rr
	}
	if r.policy != nil && r.policy.ShouldResultRetry == nil {
		// The priority of FailurePolicy.ShouldResultRetry is higher, so only update it when it's nil
		r.policy.ShouldResultRetry = r.specifiedResultRetry
	}
}


Review comment (bug):
Old implemetation is inconsistent: a `FailurePolicy` with nil `ShouldResultRetry` will be overwritten, while non-nil `ShouldResultRetry` will not.

Code after:
}

// Dump implements the Retryer interface.
func (r *failureRetryer) Dump() map[string]interface{} {
	r.RLock()
	defer r.RUnlock()
	dm := make(map[string]interface{})
	dm["enable"] = r.enable
	dm["failure_retry"] = r.policy
	if r.policy != nil {
		dm["specified_result_retry"] = map[string]bool{
			"error_retry": r.policy.IsErrorRetryNonNil(),
			"resp_retry":  r.policy.IsRespRetryNonNil(),
		}
	}
	if r.errMsg != "" {
		dm["errMsg"] = r.errMsg
	}
	return dm
}

func (r *failureRetryer) setSpecifiedResultRetryIfNeeded(rr *ShouldResultRetry) {
	if rr != nil {
		// save the object specified by client.WithSpecifiedResultRetry(..)
		r.specifiedResultRetry = rr
	}
	if r.policy != nil && r.specifiedResultRetry != nil {
		// The priority of client.WithSpecifiedResultRetry(..) is higher, so always update it
		// NOTE: client.WithSpecifiedResultRetry(..) will always reject a nil object
		r.policy.ShouldResultRetry = r.specifiedResultRetry
	}
}
Repository: codenotary/immudb
File: pkg/gw/safeset_handler_test.go (Go)

Code before:
package gw

import (
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"os"
	"strings"
	"testing"
	"time"

	immuclient "github.com/codenotary/immudb/pkg/client"
	"github.com/codenotary/immudb/pkg/server"
	"github.com/grpc-ecosystem/grpc-gateway/runtime"
	"github.com/lithammer/shortuuid"
)

func TestSafeset(t *testing.T) {
	op := server.DefaultOptions()
	op.Dir = "db_" + shortuuid.New()
	s := server.
		DefaultServer().WithOptions(op)
	go s.Start()
	time.Sleep(2 * time.Second)
	defer s.Stop()
	defer os.RemoveAll(op.Dir)

	ic, err := immuclient.NewImmuClient(immuclient.DefaultOptions())
	if err != nil {
		t.Errorf("unable to instantiate client: %s", err)
		return
	}
	mux := runtime.NewServeMux()
	ssh := NewSafesetHandler(mux, ic)

	tt := []struct {
		test           string
		payload        string
		wantStatus     int
		wantFieldName  string
		wantFieldValue interface{}
	}{
		{ //Pablo = UGFibG8=
			//Picasso = UGljYXNzbw==
			"Send corrent request",

Review comment (suggestion):
Is it worth using a 3rd party library for this? I am thinking maybe just using the current unix timestamp would be good enough.
Usually we try to avoid adding a new dependency, unless it is really worth it.

Code after:
package gw

import (
	"encoding/base64"
	"encoding/json"
	"math/rand"
	"net/http"
	"net/http/httptest"
	"os"
	"strconv"
	"strings"
	"testing"
	"time"

	immuclient "github.com/codenotary/immudb/pkg/client"
	immudb "github.com/codenotary/immudb/pkg/server"
	"github.com/grpc-ecosystem/grpc-gateway/runtime"
)

func generateRandomTCPPort() int {
	rand.Seed(time.Now().UnixNano())
	min := 1024
	max := 64000
	return rand.Intn(max - min + 1)
}

func TestSafeset(t *testing.T) {
	key := base64.StdEncoding.EncodeToString([]byte("Pablo"))
	value := base64.StdEncoding.EncodeToString([]byte("Picasso"))
	tcpPort := generateRandomTCPPort()
	op := immudb.DefaultOptions().WithPort(tcpPort).WithDir("db_" + strconv.FormatInt(int64(tcpPort), 10))
	s := immudb.DefaultServer().WithOptions(op)
	go s.Start()
	time.Sleep(2 * time.Second)
	defer func() {
		s.Stop()
		time.Sleep(2 * time.Second) //without the delay the db dir is deleted before all the data has been flushed to disk and results in crash.
		os.RemoveAll(op.Dir)
	}()

	ic, err := immuclient.NewImmuClient(immuclient.DefaultOptions().WithPort(tcpPort))
	if err != nil {
		t.Errorf("unable to instantiate client: %s", err)
		return
	}
Repository: codenotary/immudb
File: pkg/gw/service.go (Go)

Code before:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gw

// Service ...
type Service struct {
	ImmuGwServer ImmuGw
}

// Start - non-blocking start service
func (s Service) Start() {
	go s.Run()
}

// Stop - blocking stop service
func (s Service) Stop() {
	s.ImmuGwServer.Stop()
}

// Run - blocking run service
func (s Service) Run() {
	s.ImmuGwServer.Start()
}


Review comment (suggestion):
Service should implement a non blocking stop interface and actually it does. Probably go routine was useless.
Simply the comment should stay equal to original interface in daemon.go 

Code after:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gw

// Service ...
type Service struct {
	ImmuGwServer ImmuGw
}

// Start - non-blocking start service
func (s Service) Start() {
	go s.Run()
}

// Stop - non-blocking stop service
func (s Service) Stop() {
	s.ImmuGwServer.Stop()
}

// Run - blocking run service
func (s Service) Run() {
	s.ImmuGwServer.Start()
}