fix:handle error and remove Redundant type conversion
Signed-off-by: jianfei.zhang <jianfei.zhang@daocloud.io>
This commit is contained in:
@@ -79,7 +79,7 @@ func toRealServerKey(rs *utilipvs.RealServer) *RealServerKey {
|
||||
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
|
||||
func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
if serv == nil {
|
||||
return fmt.Errorf("Failed to add virtual server, error: virtual server can't be nil")
|
||||
return fmt.Errorf("failed to add virtual server, error: virtual server can't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
f.Services[key] = serv
|
||||
@@ -91,7 +91,7 @@ func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
//UpdateVirtualServer is a fake implementation, it updates the VirtualServer in the cache store.
|
||||
func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
if serv == nil {
|
||||
return fmt.Errorf("Failed to update service, service can't be nil")
|
||||
return fmt.Errorf("failed to update service, service can't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
f.Services[key] = serv
|
||||
@@ -101,7 +101,7 @@ func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
//DeleteVirtualServer is a fake implementation, it simply deletes the VirtualServer from the cache store.
|
||||
func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
if serv == nil {
|
||||
return fmt.Errorf("Failed to delete service: service can't be nil")
|
||||
return fmt.Errorf("failed to delete service: service can't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
delete(f.Services, key)
|
||||
@@ -113,14 +113,14 @@ func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||
//GetVirtualServer is a fake implementation, it tries to find a specific VirtualServer from the cache store.
|
||||
func (f *FakeIPVS) GetVirtualServer(serv *utilipvs.VirtualServer) (*utilipvs.VirtualServer, error) {
|
||||
if serv == nil {
|
||||
return nil, fmt.Errorf("Failed to get service: service can't be nil")
|
||||
return nil, fmt.Errorf("failed to get service: service can't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
svc, found := f.Services[key]
|
||||
if found {
|
||||
return svc, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Not found serv: %v", key.String())
|
||||
return nil, fmt.Errorf("not found serv: %v", key.String())
|
||||
}
|
||||
|
||||
//GetVirtualServers is a fake implementation, it simply returns all VirtualServers in the cache store.
|
||||
@@ -143,11 +143,11 @@ func (f *FakeIPVS) Flush() error {
|
||||
//AddRealServer is a fake implementation, it simply creates a RealServer for a VirtualServer in the cache store.
|
||||
func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
|
||||
if serv == nil || dest == nil {
|
||||
return fmt.Errorf("Failed to add destination for service, neither service nor destination shouldn't be nil")
|
||||
return fmt.Errorf("failed to add destination for service, neither service nor destination shouldn't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
if _, ok := f.Services[key]; !ok {
|
||||
return fmt.Errorf("Failed to add destination for service %v, service not found", key.String())
|
||||
return fmt.Errorf("failed to add destination for service %v, service not found", key.String())
|
||||
}
|
||||
dests := f.Destinations[key]
|
||||
if dests == nil {
|
||||
@@ -161,11 +161,11 @@ func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.Re
|
||||
//GetRealServers is a fake implementation, it simply returns all RealServers in the cache store.
|
||||
func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.RealServer, error) {
|
||||
if serv == nil {
|
||||
return nil, fmt.Errorf("Failed to get destination for nil service")
|
||||
return nil, fmt.Errorf("failed to get destination for nil service")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
if _, ok := f.Services[key]; !ok {
|
||||
return nil, fmt.Errorf("Failed to get destinations for service %v, service not found", key.String())
|
||||
return nil, fmt.Errorf("failed to get destinations for service %v, service not found", key.String())
|
||||
}
|
||||
return f.Destinations[key], nil
|
||||
}
|
||||
@@ -173,11 +173,11 @@ func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.Rea
|
||||
//DeleteRealServer is a fake implementation, it deletes the real server in the cache store.
|
||||
func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
|
||||
if serv == nil || dest == nil {
|
||||
return fmt.Errorf("Failed to delete destination, neither service nor destination can't be nil")
|
||||
return fmt.Errorf("failed to delete destination, neither service nor destination can't be nil")
|
||||
}
|
||||
key := toServiceKey(serv)
|
||||
if _, ok := f.Services[key]; !ok {
|
||||
return fmt.Errorf("Failed to delete destination for service %v, service not found", key.String())
|
||||
return fmt.Errorf("failed to delete destination for service %v, service not found", key.String())
|
||||
}
|
||||
dests := f.Destinations[key]
|
||||
exist := false
|
||||
@@ -191,7 +191,7 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
|
||||
}
|
||||
// Not Found
|
||||
if !exist {
|
||||
return fmt.Errorf("Failed to delete real server for service %v, real server not found", key.String())
|
||||
return fmt.Errorf("failed to delete real server for service %v, real server not found", key.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user