您的位置 首页 golang

golang中的表达式解析-expression4go 简单的EL

上一篇介绍了 golang中的日志组件 loggo, ,今天来推荐一款在golang中的简单的EL解析器 expression4go

该组件主要进行 expression 文字表达式的计算解析,通过文字的表达式来动态的进行公式或者脚本的变量计算。

给个例子比如

 context.AddPropertyAccessor(MapAccessor{})
m["name"] = "expression4go"
m["age"] = 1

//
// Map 1 := make(map[string]interface{})
//m["map"] = map1
//map1["name"] = "davidliu"
//map1["age"] = 10

context.SetVariables(m)
parser := SpelExpressionParser{}
expressionString := "#{name}"
//expressionString := "#name=='lisi'"
//expressionString := "#name" //返回lisi
valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)

fmt.Println(valueContext)  

分为三步

定义表达式

expressionString := “#{name}”

准备上下文

m[“name”] = “expression4go”

m[“age”] = 1

context.SetVariables(m)

获取表达式值

valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)

在这里通过文本直接进行动态的计算

支持 Struct ,Map,Array,Slice的计算

 context.AddPropertyAccessor(MapAccessor{})
m1 := make(map[string]interface{})
m["name"] = "expression4go"
m["age"] = 1
//切片
//orders := make([]Order, 2)
//数组
orders := [2]Order{}
orders[0] = Order{name: "expression4go-1", num: 12}
orders[1] = Order{name: "expression4go-2", num: 24}
m1["code"] = orders
m["order"] = m1
context.SetVariables(m)
expressionString := "${order.code[0].name}"
valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
fmt.Println("结果为", valueContext)  

项目地址 https:// GitHub .com/gohutool/expression4go

文章来源:智云一二三科技

文章标题:golang中的表达式解析-expression4go 简单的EL

文章地址:https://www.zhihuclub.com/96698.shtml

关于作者: 智云科技

热门文章

评论已关闭

34条评论

  1. CrossRef Medline Kaplan CP Acetylation by the enzyme N acetyltransferase is the dominant pathway for metabolizing aromatic amines and hydrazines Figure 22

  2. Analysis of ESR1 and ERBB2 by gene expression showed high sensitivity and specificity as compared with the IHC assay Appendix Figs A6B and A6C

  3. Sutherland RL, Green MD, Hall RE et al 1983 Tamoxifen induces accumulation of MCF 7 human mammary carcinoma cells in the G0 G1 phase of the cell cycle

  4. Hepatic steatosis is associated with higher incidence of liver metastasis in patients with metastatic breast cancer; an observational clinical study

  5. 56, 1466 1473 2015 It objectively correlates with functional outcome measures in detecting clinical decline 48, 49, 50, 51, reliably shows subclinical changes, and can even predict loss of ambulation 52, 53

  6. In the WITT 1 line, 7 xenografts were recovered from the GW2580 and 8 from the AZD7507 group Using IgG as an analyte, this novel sandwich immunosensor displayed a wide LR of 1 fg mL 100 ng mL, which was found to be two orders of magnitude higher than other previous works

  7. Short term estrogen therapy induced cellular changes in urothelium consistent with improved ability to fight off urinary tract infection, results from clinical and preclinical studies suggested

  8. Serious Use Alternative 2 erythromycin ethylsuccinate will increase the level or effect of amiodarone by affecting hepatic intestinal enzyme CYP3A4 metabolism

  9. Oral rehydration versus intravenous therapy for treating dehydration due to gastroenteritis in children a meta analysis of randomised controlled trials If you are being treated with any of the following medications, you should talk to your health care provider before taking elderberry

  10. Has thought, Well, 60 billions probiotics, this would have to that the help gives gut of mine the good balance

  11. If you decide to use known donor sperm at a fertility clinic, the clinic may require that the sample be tested and frozen even though it s not from a sperm bank

  12. WCRF AICR Systematic Literature Review Continuous Update Project Report acnes was the most common bacterium identified, being reported in seven of the nine studies, with a median range of 45

  13. In our study, no retinopathy findings including refractile crystals, retinal pigment epithelial changes or maculopathy was detected C Quantitative PCR for flanked and unrecombined DNA in i ОІ 1 fl fl, ОІ 1 fl fl, i ОІ 1 e3 e3, and ОІ 1 e3 e3 bladders of animals receiving 28 doses of tamoxifen

  14. Using reverse transcription PCR, the relative expression of mRNA for both estrogen receptor ER beta and transforming growth factor beta1 was determined in each patient group and quantified against a known reference standard

  15. By blocking the beta adrenergic receptor, these compounds blunt chronotropic, inotropic, and vasodilator responses of any beta adrenergic stimulation

  16. So far the parties havefailed to agree financial commitments and business strategy These episodes of AF may be subclinical, presenting initially with stroke Walkey 2014

  17. Following a 4- week treatmentfree period, findings in the testes, epididymides, and adrenal glands were not fully reversible at doses of 2 times the MRHDD of KYZATREX as compared to treatment with the excipients alone, including phytosterol esters MRTX849 has proved to be as effective as a K Ras G12C inhibitor by inhibiting GTP loading 16

  18. Shangqingzong, as a famous sect in the Northern Territory, why did he attack the other side The old beggar How To Lower Blood Sugar Without Med is keto ok for type 2 diabetes stared at Shangguanfu closely, this was the question that had been pressing in his heart Comments Prepared for the CMS Listening Session Regarding the National Coverage Determination Analysis for Aducanumab for Treatment of Alzheimer s Disease HRG Publication 2596 In comments prepared for the Centers for Medicare and Medicaid Services CMS listening session regarding the National Coverage Determination analysis for monoclonal antibodies directed against amyloid for the treatment of Alzheimer s disease, Public Citizen urged CMS to issue a National Coverage Determination that excludes aducanumab from coverage under the Medicare program because there is a lack of scientific evidence that aducanumab provides any meaningful clinical benefit in terms of cognitive function outcomes in Alzheimer s disease patients and the drug thus is not reasonable and necessary for treatment of such patients

  19. These major side effects are due to the generalized nature of the immunosuppression

  20. Diagnostic MRI usually is not indicated in staging most cases of newly diagnosed breast cancer but may aid in more accurate assessment of the breast lesion, chest wall invasion, or axillary node involvement

  21. WHSmith reserves the right to reject any voucher it deems, in its sole discretion, to have been forged, defaced or otherwise tampered with

  22. clarithromycin praziquantel nombre comercial colombia Worryingly, most of the unit sales being recognized in the quarter are older generation BlackBerry 7 devices Peltier MR, Verplaetse TL, Mineur YS, Gueorguieva R, Petrakis I, Cosgrove KP, Picciotto MR, McKee SA

  23. pilex diovan prescribing information He has set up a new advisory council to be chaired by an Aboriginal, Warren Mundine, a former national president of the Labor party

  24. Headaches With High Blood Pressure Medication, Maximum Dose Of Losartan Hctz Wikipedia What Type Of Blood Pressure Medication Is Most Aggressive

  25. The adenoviral type 5 and type 2 early region 1A E1A proteins were reported originally as an oncogene that could cooperate with other viral and cellular oncogenes to transform primary culture cells but not established cell lines, as distinct from the type 12 E1A, a potent oncogene that can transform established cell lines

网站地图