Skip to content

Commit

Permalink
Extract variable to function
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Apr 30, 2022
1 parent 9ac054e commit 8b3a376
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 79 deletions.
1 change: 0 additions & 1 deletion data/address_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package data
// 注1:台湾省、香港特别行政区和澳门特别行政区暂缺地市和区县信息
// 注2:每月发布的区划变更表是根据区划变更地的统计人员在统计信息系统更新后的情况所绘制,与区划变更文件发布的时间有一定的延迟性,但在每年的最后一次发布变更情况后与区划全年变更文件保持一致。
// Data Source: http://www.mca.gov.cn/article/sj/xzqh/

func AddressCode() map[uint32]string {
return map[uint32]string{
110000: "北京市",
Expand Down
28 changes: 15 additions & 13 deletions data/chinese_zodiac.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
package data

// ChineseZodiac 生肖信息
var ChineseZodiac = [12]string{
"子鼠",
"丑牛",
"寅虎",
"卯兔",
"辰龙",
"巳蛇",
"午马",
"未羊",
"申猴",
"酉鸡",
"戌狗",
"亥猪",
func ChineseZodiac() [12]string {
return [12]string{
"子鼠",
"丑牛",
"寅虎",
"卯兔",
"辰龙",
"巳蛇",
"午马",
"未羊",
"申猴",
"酉鸡",
"戌狗",
"亥猪",
}
}
124 changes: 63 additions & 61 deletions data/constellation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,67 @@
package data

// Constellation 星座信息
var Constellation = [13]map[string]string{
1: {
"name": "水瓶座",
"start_date": "01-20",
"end_date": "02-18",
},
2: {
"name": "双鱼座",
"start_date": "02-19",
"end_date": "03-20",
},
3: {
"name": "白羊座",
"start_date": "03-21",
"end_date": "04-19",
},
4: {
"name": "金牛座",
"start_date": "04-20",
"end_date": "05-20",
},
5: {
"name": "双子座",
"start_date": "05-21",
"end_date": "06-21",
},
6: {
"name": "巨蟹座",
"start_date": "06-22",
"end_date": "07-22",
},
7: {
"name": "狮子座",
"start_date": "07-23",
"end_date": "08-22",
},
8: {
"name": "处女座",
"start_date": "08-23",
"end_date": "09-22",
},
9: {
"name": "天秤座",
"start_date": "09-23",
"end_date": "10-23",
},
10: {
"name": "天蝎座",
"start_date": "10-24",
"end_date": "11-22",
},
11: {
"name": "射手座",
"start_date": "11-23",
"end_date": "12-21",
},
12: {
"name": "摩羯座",
"start_date": "12-22",
"end_date": "01-19",
},
func Constellation() [13]map[string]string {
return [13]map[string]string{
1: {
"name": "水瓶座",
"start_date": "01-20",
"end_date": "02-18",
},
2: {
"name": "双鱼座",
"start_date": "02-19",
"end_date": "03-20",
},
3: {
"name": "白羊座",
"start_date": "03-21",
"end_date": "04-19",
},
4: {
"name": "金牛座",
"start_date": "04-20",
"end_date": "05-20",
},
5: {
"name": "双子座",
"start_date": "05-21",
"end_date": "06-21",
},
6: {
"name": "巨蟹座",
"start_date": "06-22",
"end_date": "07-22",
},
7: {
"name": "狮子座",
"start_date": "07-23",
"end_date": "08-22",
},
8: {
"name": "处女座",
"start_date": "08-23",
"end_date": "09-22",
},
9: {
"name": "天秤座",
"start_date": "09-23",
"end_date": "10-23",
},
10: {
"name": "天蝎座",
"start_date": "10-24",
"end_date": "11-22",
},
11: {
"name": "射手座",
"start_date": "11-23",
"end_date": "12-21",
},
12: {
"name": "摩羯座",
"start_date": "12-22",
"end_date": "01-19",
},
}
}
8 changes: 4 additions & 4 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ func getAddress(addressCode string, birthdayCode string, strict bool) string {
func getConstellation(birthdayCode string) string {
month, _ := strconv.Atoi(substr(birthdayCode, 4, 6))
day, _ := strconv.Atoi(substr(birthdayCode, 6, 8))
startDate := data.Constellation[month]["start_date"]
startDate := data.Constellation()[month]["start_date"]
startDay, _ := strconv.Atoi(strings.Split(startDate, "-")[1])
if day >= startDay {
return data.Constellation[month]["name"]
return data.Constellation()[month]["name"]
}

tmpMonth := month - 1
if month == 1 {
tmpMonth = 12
}

return data.Constellation[tmpMonth]["name"]
return data.Constellation()[tmpMonth]["name"]
}

// 获取生肖信息
Expand All @@ -116,7 +116,7 @@ func getChineseZodiac(birthdayCode string) string {
end := cast.ToInt(substr(birthdayCode, 0, 4))
key := (end - start) % 12

return data.ChineseZodiac[key]
return data.ChineseZodiac()[key]
}

// substr 截取字符串
Expand Down

0 comments on commit 8b3a376

Please sign in to comment.