Skip to content

Commit 8b3a376

Browse files
committed
Extract variable to function
1 parent 9ac054e commit 8b3a376

File tree

4 files changed

+82
-79
lines changed

4 files changed

+82
-79
lines changed

data/address_code.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package data
99
// 注1:台湾省、香港特别行政区和澳门特别行政区暂缺地市和区县信息
1010
// 注2:每月发布的区划变更表是根据区划变更地的统计人员在统计信息系统更新后的情况所绘制,与区划变更文件发布的时间有一定的延迟性,但在每年的最后一次发布变更情况后与区划全年变更文件保持一致。
1111
// Data Source: http://www.mca.gov.cn/article/sj/xzqh/
12-
1312
func AddressCode() map[uint32]string {
1413
return map[uint32]string{
1514
110000: "北京市",

data/chinese_zodiac.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
package data
66

77
// ChineseZodiac 生肖信息
8-
var ChineseZodiac = [12]string{
9-
"子鼠",
10-
"丑牛",
11-
"寅虎",
12-
"卯兔",
13-
"辰龙",
14-
"巳蛇",
15-
"午马",
16-
"未羊",
17-
"申猴",
18-
"酉鸡",
19-
"戌狗",
20-
"亥猪",
8+
func ChineseZodiac() [12]string {
9+
return [12]string{
10+
"子鼠",
11+
"丑牛",
12+
"寅虎",
13+
"卯兔",
14+
"辰龙",
15+
"巳蛇",
16+
"午马",
17+
"未羊",
18+
"申猴",
19+
"酉鸡",
20+
"戌狗",
21+
"亥猪",
22+
}
2123
}

data/constellation.go

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,67 @@
55
package data
66

77
// Constellation 星座信息
8-
var Constellation = [13]map[string]string{
9-
1: {
10-
"name": "水瓶座",
11-
"start_date": "01-20",
12-
"end_date": "02-18",
13-
},
14-
2: {
15-
"name": "双鱼座",
16-
"start_date": "02-19",
17-
"end_date": "03-20",
18-
},
19-
3: {
20-
"name": "白羊座",
21-
"start_date": "03-21",
22-
"end_date": "04-19",
23-
},
24-
4: {
25-
"name": "金牛座",
26-
"start_date": "04-20",
27-
"end_date": "05-20",
28-
},
29-
5: {
30-
"name": "双子座",
31-
"start_date": "05-21",
32-
"end_date": "06-21",
33-
},
34-
6: {
35-
"name": "巨蟹座",
36-
"start_date": "06-22",
37-
"end_date": "07-22",
38-
},
39-
7: {
40-
"name": "狮子座",
41-
"start_date": "07-23",
42-
"end_date": "08-22",
43-
},
44-
8: {
45-
"name": "处女座",
46-
"start_date": "08-23",
47-
"end_date": "09-22",
48-
},
49-
9: {
50-
"name": "天秤座",
51-
"start_date": "09-23",
52-
"end_date": "10-23",
53-
},
54-
10: {
55-
"name": "天蝎座",
56-
"start_date": "10-24",
57-
"end_date": "11-22",
58-
},
59-
11: {
60-
"name": "射手座",
61-
"start_date": "11-23",
62-
"end_date": "12-21",
63-
},
64-
12: {
65-
"name": "摩羯座",
66-
"start_date": "12-22",
67-
"end_date": "01-19",
68-
},
8+
func Constellation() [13]map[string]string {
9+
return [13]map[string]string{
10+
1: {
11+
"name": "水瓶座",
12+
"start_date": "01-20",
13+
"end_date": "02-18",
14+
},
15+
2: {
16+
"name": "双鱼座",
17+
"start_date": "02-19",
18+
"end_date": "03-20",
19+
},
20+
3: {
21+
"name": "白羊座",
22+
"start_date": "03-21",
23+
"end_date": "04-19",
24+
},
25+
4: {
26+
"name": "金牛座",
27+
"start_date": "04-20",
28+
"end_date": "05-20",
29+
},
30+
5: {
31+
"name": "双子座",
32+
"start_date": "05-21",
33+
"end_date": "06-21",
34+
},
35+
6: {
36+
"name": "巨蟹座",
37+
"start_date": "06-22",
38+
"end_date": "07-22",
39+
},
40+
7: {
41+
"name": "狮子座",
42+
"start_date": "07-23",
43+
"end_date": "08-22",
44+
},
45+
8: {
46+
"name": "处女座",
47+
"start_date": "08-23",
48+
"end_date": "09-22",
49+
},
50+
9: {
51+
"name": "天秤座",
52+
"start_date": "09-23",
53+
"end_date": "10-23",
54+
},
55+
10: {
56+
"name": "天蝎座",
57+
"start_date": "10-24",
58+
"end_date": "11-22",
59+
},
60+
11: {
61+
"name": "射手座",
62+
"start_date": "11-23",
63+
"end_date": "12-21",
64+
},
65+
12: {
66+
"name": "摩羯座",
67+
"start_date": "12-22",
68+
"end_date": "01-19",
69+
},
70+
}
6971
}

helper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ func getAddress(addressCode string, birthdayCode string, strict bool) string {
9595
func getConstellation(birthdayCode string) string {
9696
month, _ := strconv.Atoi(substr(birthdayCode, 4, 6))
9797
day, _ := strconv.Atoi(substr(birthdayCode, 6, 8))
98-
startDate := data.Constellation[month]["start_date"]
98+
startDate := data.Constellation()[month]["start_date"]
9999
startDay, _ := strconv.Atoi(strings.Split(startDate, "-")[1])
100100
if day >= startDay {
101-
return data.Constellation[month]["name"]
101+
return data.Constellation()[month]["name"]
102102
}
103103

104104
tmpMonth := month - 1
105105
if month == 1 {
106106
tmpMonth = 12
107107
}
108108

109-
return data.Constellation[tmpMonth]["name"]
109+
return data.Constellation()[tmpMonth]["name"]
110110
}
111111

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

119-
return data.ChineseZodiac[key]
119+
return data.ChineseZodiac()[key]
120120
}
121121

122122
// substr 截取字符串

0 commit comments

Comments
 (0)