From cec59a573e2179c1b22812b735faab0a3cd0cf2e Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 5 Dec 2023 15:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E5=85=AC=E9=87=8C?= =?UTF-8?q?=E6=A0=87=E7=BB=91=E5=AE=9A=E9=80=BB=E8=BE=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/physical_section.go | 11 +++++++---- repository/turnout.go | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/repository/physical_section.go b/repository/physical_section.go index 2f8277a..9f1b124 100644 --- a/repository/physical_section.go +++ b/repository/physical_section.go @@ -1,8 +1,8 @@ package repository import ( - "errors" "fmt" + "joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/util/number" ) @@ -106,7 +106,7 @@ func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort) _, isSectionPort := devicePort.(*PhysicalSectionPort) _, isTurnoutPort := devicePort.(*TurnoutPort) if !isSectionPort && !isTurnoutPort { - return errors.New(fmt.Sprintf("物理区段不能与[%s]类型的设备端口关联", devicePort.Device().Type())) + return fmt.Errorf("物理区段不能与[%s]类型的设备端口关联", devicePort.Device().Type()) } switch port { case proto.Port_A: @@ -114,20 +114,23 @@ func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort) case proto.Port_B: s.bRelation = devicePort default: - return errors.New(fmt.Sprintf("物理区段无端口[%s]", port)) + return fmt.Errorf("物理区段无端口[%s]", port) } return nil } // 绑定区段边界公里标。(仅限非道岔物理区段调用) func (s *PhysicalSection) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error { + if km == nil { + return nil + } switch port { case proto.Port_A: s.aKm = km case proto.Port_B: s.bKm = km default: - return errors.New(fmt.Sprintf("区段无端口[%s]", port)) + return fmt.Errorf("区段无端口[%s]", port) } return nil } diff --git a/repository/turnout.go b/repository/turnout.go index dc2416c..e214c72 100644 --- a/repository/turnout.go +++ b/repository/turnout.go @@ -1,7 +1,6 @@ package repository import ( - "errors" "fmt" "joylink.club/rtsssimulation/repository/model/proto" @@ -110,7 +109,7 @@ func (t *Turnout) bindDevicePort(port proto.Port, devicePort DevicePort) error { _, isSectionPort := devicePort.(*PhysicalSectionPort) _, isTurnoutPort := devicePort.(*TurnoutPort) if !isSectionPort && !isTurnoutPort { - return errors.New(fmt.Sprintf("道岔不能与[%s]类型的设备端口关联", devicePort.Device().Type())) + return fmt.Errorf("道岔不能与[%s]类型的设备端口关联", devicePort.Device().Type()) } switch port { case proto.Port_A: @@ -120,7 +119,7 @@ func (t *Turnout) bindDevicePort(port proto.Port, devicePort DevicePort) error { case proto.Port_C: t.cDevicePort = devicePort default: - return errors.New(fmt.Sprintf("道岔无端口[%s]", port)) + return fmt.Errorf("道岔无端口[%s]", port) } return nil } @@ -137,6 +136,9 @@ func (t *Turnout) bindLinkPort(port proto.Port, linkPort *LinkPort) { } func (t *Turnout) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error { + if km == nil { + return nil + } switch port { case proto.Port_A: t.aKm = km @@ -145,7 +147,7 @@ func (t *Turnout) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error { case proto.Port_C: t.cKm = km default: - return errors.New(fmt.Sprintf("道岔无端口[%s]", port)) + return fmt.Errorf("道岔无端口[%s]", port) } return nil }