当前位置:网站首页>On the escape of inequality value
On the escape of inequality value
2022-06-26 18:45:00 【51CTO】
Recently I met a need , Front end filling inequality , The back end needs to be stored , It is necessary to translate the inequality into the form of interval , Let's share some general solutions , For reference only .
One 、 Agree with the front end on the data format to be transmitted
The front page display is like this

The parameter transfer format agreed with the front end is
utilize @ Symbols separate symbols from version numbers , This symbol can also be used for subsequent stock in , There are multiple rules that can be passed to a string array , You can also pass comma separated strings
Two 、 Verify before warehousing
// Check the maximum and minimum version numbers of multiple rules
versionRangeList :
=
strings
.
Split(
body
.
VersionRange,
",")
switch
len(
versionRangeList) {
case
1:
version :
=
strings
.
Split(
versionRangeList[
0],
"@")
switch
version[
0] {
case
GT,
GE,
LT,
LE,
EQ,
NE:
// Normal rule
default:
return
tracerr
.
NewError(
" The rules are illegal , Parameter transfer exception :"
+
versionRangeList[
0])
}
case
2:
version1 :
=
strings
.
Split(
versionRangeList[
0],
"@")
version2 :
=
strings
.
Split(
versionRangeList[
1],
"@")
switch
version1[
0] {
case
GT,
GE:
if
version1[
1]
>=
version2[
1]
|| (
version2[
0]
!=
LT
&&
version2[
0]
!=
LE) {
return
tracerr
.
NewError(
" The rules are illegal , The minimum version number is not less than the maximum version number ")
}
case
LT,
LE:
if
version1[
1]
<=
version2[
1]
|| (
version2[
0]
!=
GT
&&
version2[
0]
!=
GE) {
return
tracerr
.
NewError(
" The rules are illegal , The minimum version number is not less than the maximum version number ")
}
default:
return
tracerr
.
NewError(
" The rules are illegal , Multiple rules can only be selected :gt,ge,lt,le")
}
default:
return
tracerr
.
NewError(
" The rules are illegal , The number of rules is abnormal , The number of rules is :"
+
strconv
.
Itoa(
len(
versionRangeList)))
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
3、 ... and 、 Escape to interval
Because it is necessary to convert inequality into interval form and transmit it to other modules , So I chose to create one map, Establish the corresponding relationship between inequality and interval scheme
// Inequality constant
const (
GT
=
"gt"
// Greater than
GE
=
"ge"
// Greater than or equal to
LT
=
"lt"
// Less than
LE
=
"le"
// Less than or equal to
EQ
=
"eq"
// be equal to
NE
=
"ne"
// It's not equal to
)
func
RuleReversal(
versionRange []
string) (
reversalResult
string) {
// Reverse the rules Map
ruleReversalMap :
=
map[
string]
string{
GT:
"(,Ver]",
GE:
"(,Ver)",
LT:
"[Ver,)",
LE:
"(Ver,)",
EQ:
"(,Ver),(Ver,)",
NE:
"[Ver]",
}
switch
len(
versionRange) {
case
1:
version :
=
strings
.
Split(
versionRange[
0],
"@")
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version[
0]],
"Ver",
version[
1])
case
2:
version1 :
=
strings
.
Split(
versionRange[
0],
"@")
version2 :
=
strings
.
Split(
versionRange[
1],
"@")
switch
version1[
0] {
case
GT,
GE:
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version1[
0]],
"Ver",
version1[
1])
+
","
+
strings
.
ReplaceAll(
ruleReversalMap[
version2[
0]],
"Ver",
version2[
1])
case
LT,
LE:
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version1[
0]],
"Ver",
version1[
1])
+
","
+
strings
.
ReplaceAll(
ruleReversalMap[
version2[
0]],
"Ver",
version2[
1])
default:
tracerr
.
Print(
errors
.
New(
" The rules are illegal , Version inequality exception :"
+
version1[
0]))
return
""
}
default:
tracerr
.
Print(
errors
.
New(
" The rules are illegal , The number of rules is abnormal , The number of rules is :"
+
strconv
.
Itoa(
len(
versionRange))))
return
""
}
return
reversalResult
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
utilize @ Symbols separate symbols from version numbers , Remove the separated inequality symbols map Get the corresponding interval format in , Then, the separated version number is matched to the... In the obtained interval format Ver Replace it .
边栏推荐
- Feign远程调用
- GDB installation
- Interview key points that must be mastered index and affairs (with B-tree and b+ tree)
- Temporarily turn off MySQL cache
- Xlua get button registration click event of ugui
- [kubernetes] kubernetes principle analysis and practical application (under update)
- 【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
- Project practice 5: build elk log collection system
- Redis Basics
- Tag dynamic programming - preliminary knowledge for question brushing -2 0-1 knapsack theory foundation and two-dimensional array solution template
猜你喜欢

Convex hull problem

50 lines of code to crawl TOP500 books and import TXT documents

Solidity - 合约继承子合约包含构造函数时报错 及 一个合约调用另一合约view函数收取gas费用

Deep learning: numpy

Decompilation of zero time technology smart contract security series articles

Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems

最小生成树、最短路径、拓扑排序、关键路径

stm32和电机开发(直流有刷电机和步进电机)

Pinda general permission system (day 3~day 4)

Take you to resolve hash conflicts and implement a simple hash table,
随机推荐
Summary of knowledge points
Soft test preparation multimedia system
手机影像内卷几时休?
(multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition
Some basic mistakes
wm_concat()和group_concat()函数
Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
知识点总结
Redis单点登陆系统+投票系统
图像二值化处理
Why don't I recommend going to sap training institution for training?
Decompilation of zero time technology smart contract security series articles
最小生成树、最短路径、拓扑排序、关键路径
如何创建并强制使用索引
Wechat applet uniapp left slide delete with Delete Icon
【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
软考备战多媒体系统
Take you to resolve hash conflicts and implement a simple hash table,
知識點總結
Boyun, standing at the forefront of China's container industry