From 7429f1ae7780a6691201b7f12844b98345cfc17c Mon Sep 17 00:00:00 2001 From: yaozm Date: Fri, 29 Apr 2022 14:58:50 +0800 Subject: [PATCH 1/2] Optimize get timeline --- generator.go | 3 +-- helper.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/generator.go b/generator.go index d9b8bb5..d71c5f3 100644 --- a/generator.go +++ b/generator.go @@ -117,8 +117,7 @@ func generatorBirthdayCode(addressCode string, address string, birthday string) day := datePipeHandle(datePad(substr(birthday, 6, 8), "day"), "day") addressCodeInt := cast.ToInt(addressCode) - if _, ok := data.AddressCodeTimeline[addressCodeInt]; ok { - timeLine := data.AddressCodeTimeline[addressCodeInt] + if timeLine, ok := data.AddressCodeTimeline[addressCodeInt]; ok { for _, val := range timeLine { if val["address"] == address { if val["start_year"] != "" { diff --git a/helper.go b/helper.go index 5089a22..038a06d 100644 --- a/helper.go +++ b/helper.go @@ -43,7 +43,8 @@ func getAddressInfo(addressCode string, birthdayCode string, strict bool) map[st func getAddress(addressCode string, birthdayCode string, strict bool) string { address := "" addressCodeInt := cast.ToInt(addressCode) - if _, ok := data.AddressCodeTimeline[addressCodeInt]; !ok { + timeline, ok := data.AddressCodeTimeline[addressCodeInt] + if !ok { // 修复 \d\d\d\d01、\d\d\d\d02、\d\d\d\d11 和 \d\d\d\d20 的历史遗留问题 // 以上四种地址码,现实身份证真实存在,但民政部历年公布的官方地址码中可能没有查询到 // 如:440401 450111 等 @@ -66,7 +67,6 @@ func getAddress(addressCode string, birthdayCode string, strict bool) string { return address } - timeline := data.AddressCodeTimeline[addressCodeInt] year := cast.ToInt(substr(birthdayCode, 0, 4)) startYear := "0001" endYear := "9999" From 840a2da990fdab4eaa6dabf58c506e38d0b01b34 Mon Sep 17 00:00:00 2001 From: guanguans Date: Fri, 29 Apr 2022 07:07:08 +0000 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b96c4ca..b5c3f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to `guanguans/id-validator` will be documented in this file +## v1.1.11 - 2022-04-29 + +## What's Changed + +- Bump actions/cache from 2.1.7 to 3 by @dependabot in https://github.com/guanguans/id-validator/pull/21 +- Bump codecov/codecov-action from 2.1.0 to 3 by @dependabot in https://github.com/guanguans/id-validator/pull/22 + +**Full Changelog**: https://github.com/guanguans/id-validator/compare/v1.1.10...v1.1.11 + ## v1.1.10 - 2022-03-06 **Full Changelog**: https://github.com/guanguans/id-validator/compare/v1.1.9...v1.1.10