From 8aae853b0b834e2b1254d36fb141e397599e6ad5 Mon Sep 17 00:00:00 2001 From: Saimon Shaplygin Date: Sun, 7 Jan 2024 20:18:52 +0100 Subject: [PATCH] fix --- inn/models.go | 1 - ogrn/models.go | 12 +++++++++--- ogrnip/ogrnip.go | 2 +- utils/helpers.go | 3 +-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/inn/models.go b/inn/models.go index 4447e41..33bff18 100644 --- a/inn/models.go +++ b/inn/models.go @@ -105,7 +105,6 @@ func GenerateCheckSums(innType INNType, nums []int) CheckSums { nums = append(nums, f(nums)) } - fmt.Println(nums[len(nums)+shiftIdx:]) return nums[len(nums)+shiftIdx:] } diff --git a/ogrn/models.go b/ogrn/models.go index 395d413..e5635da 100644 --- a/ogrn/models.go +++ b/ogrn/models.go @@ -167,8 +167,15 @@ const ( ) func ParseOGRN(requiredType OGRNType, ogrn string) (*OGRNStruct, error) { - if ((requiredType == Legal || requiredType == Government) && len(ogrn) != legalLength) || - (requiredType == Physical && len(ogrn) != physicalLength) { + if requiredType != Physical && len(ogrn) != legalLength { + return nil, &models.CommonError{ + Method: packageName, + Err: models.ErrInvalidLength, + } + } + + if requiredType == Physical && len(ogrn) != physicalLength { + fmt.Println(requiredType, len(ogrn)) return nil, &models.CommonError{ Method: packageName, Err: models.ErrInvalidLength, @@ -277,7 +284,6 @@ func (o *OGRNStruct) makeSliceInts() []int { utils.FillSlice(o.yearsNumbers.Ints(), res, 2) utils.FillSlice(o.region.Ints(), res, 4) - fmt.Println("fillSlice", o.serialNumbers.Ints(), res) utils.FillSlice(o.serialNumbers.Ints(), res, n-2) return res diff --git a/ogrnip/ogrnip.go b/ogrnip/ogrnip.go index 6ba7011..7cb260f 100644 --- a/ogrnip/ogrnip.go +++ b/ogrnip/ogrnip.go @@ -9,7 +9,7 @@ import ( // Validate check to valid OGRNIP format // example: input format is 304500116000157 func Validate(ogrnip string) (bool, error) { - ogrnData, err := ogrn.ParseOGRN(ogrn.Legal, ogrnip) + ogrnData, err := ogrn.ParseOGRN(ogrn.Physical, ogrnip) if err != nil { return false, fmt.Errorf("parse %s model: %w", packageName, err) } diff --git a/utils/helpers.go b/utils/helpers.go index a852c84..cef0a99 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -31,8 +31,7 @@ func Random(min, max int) int { randomNumber, err := rand.Int(rand.Reader, big.NewInt(int64(max-min+1))) if err != nil { - fmt.Println("Error generating random number:", err) - return 0 + panic(fmt.Errorf("generate random number: %w", err)) } return int(randomNumber.Int64()) + min