我的第一个比较实用的GO语言程序

前端之家收集整理的这篇文章主要介绍了我的第一个比较实用的GO语言程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

@H_403_3@@H_403_3@

我们的代码当中有很多很多如下的代码:@H_403_3@@H_403_3@

UarrMain[0] := AsMainType(edLayer,myStr,'Layer','结构层名称');@H_403_3@@H_403_3@

UarrMain[1] := AsMainType(edKind,'Kind','稳定剂种类');@H_403_3@@H_403_3@

.......@H_403_3@@H_403_3@

UArrSub[0] := AsSubType(myInt,True,'seqnum','序号');@H_403_3@@H_403_3@

UArrSub[1] := AsSubType(myStr,False,'BoxNumber','试验盒号');@H_403_3@@H_403_3@

UArrSub[2] := AsSubType(myFloat,'BoxWeigth','盒的质量');
@H_403_3@@H_403_3@

.....

我现在需要提取第三个,第四个参数。@H_403_3@@H_403_3@

放上来,下次电脑坏就不用重新写了。工作当中用到的,可以减轻工作量。@H_403_3@

一边学一边写的,比较手生,翻了很多次文档才写出来。 关键是正则,当然没有考虑所有的情况。@H_403_3@
这门语言对GUI支持的不好,因为是面向服务器的开发。就胡乱弄了个B/S的,代码如下:
 
 
  1. packagemain@H_403_3@@H_403_3@
  2. import@H_403_3@
  3. (@H_403_3@
  4. "io"@H_403_3@@H_403_3@@H_403_3@
  5. "fmt"@H_403_3@@H_403_3@@H_403_3@
  6. "regexp"@H_403_3@@H_403_3@@H_403_3@
  7. "strings"@H_403_3@@H_403_3@@H_403_3@
  8. "net/http"@H_403_3@@H_403_3@@H_403_3@
  9. )@H_403_3@
  10. @H_403_3@
  11. const@H_403_3@(@H_403_3@@H_403_3@
  12. sql="EXECsys.sp_addextendedproperty@name=N'MS_Description',@value=N'AAAA',@level0type=N'SCHEMA',@level0name=N'dbo',@level1type=N'TABLE',@level1name=N'CCCC',@level2type=N'COLUMN',@level2name=N'BBBB'"@H_403_3@@H_403_3@@H_403_3@
  13. sql2="EXECsys.sp_addextendedproperty@name=N'MS_Description',@level1name=N'CCCC'"@H_403_3@@H_403_3@@H_403_3@
  14. html=@H_403_3@
  15. `<html>@H_403_3@
  16. <head><title>提取<a/title></head>@H_403_3@
  17. <body><formmethod='post'@H_403_3@>@H_403_3@@H_403_3@
  18. TableName:<inputtype="text"@H_403_3@name=@H_403_3@"tablename"@H_403_3@></input>qs_Table中的TableName,比如TestRecordC21<br></br>@H_403_3@@H_403_3@
  19. 表格名称:<inputtype="text"@H_403_3@name=@H_403_3@"tablename2"@H_403_3@></input>比如石料试验记录<br></br>@H_403_3@@H_403_3@
  20. <textarearows="20"@H_403_3@cols=@H_403_3@"120"@H_403_3@name=@H_403_3@"target"@H_403_3@></textarea><br></br>@H_403_3@@H_403_3@
  21. <inputtype="submit"@H_403_3@value=@H_403_3@"Submit"@H_403_3@></input>@H_403_3@@H_403_3@
  22. %s@H_403_3@
  23. </form>@H_403_3@
  24. </body>@H_403_3@
  25. </html>`@H_403_3@
  26. )@H_403_3@
  27. @H_403_3@
  28. funcmySearch(strstring)(resultstring){@H_403_3@
  29. result=""@H_403_3@@H_403_3@@H_403_3@
  30. regSub:=regexp.MustCompile(`(?i)AsSubType\s*\(\w+\s*\,\s*(True|False)\s*\,\s*\'\s*(\w+)\s*\'\s*\,\s*\'\s*(.*?)\s*\'@H_403_3@`)@H_403_3@@H_403_3@
  31. regMain:=regexp.MustCompile(`(?i)AsMainType\s*\(\w+\s*\,\s*(\w+)\s*\,\s*\'\s*(.*?)\s*\'@H_403_3@`)@H_403_3@@H_403_3@
  32. @H_403_3@
  33. resultSub:=regSub.FindAllStringSubmatch(str,-1)@H_403_3@
  34. resultMain:=regMain.FindAllStringSubmatch(str,-1)@H_403_3@
  35. @H_403_3@
  36. for@H_403_3@_,V:=rangeresultSub{@H_403_3@@H_403_3@
  37. result=result+strings.Replace(strings.Replace(sql,"AAAA"@H_403_3@,V[3],-1),@H_403_3@"BBBB"@H_403_3@,V[2],-1)+@H_403_3@@H_403_3@
  38. "<br></br>"@H_403_3@+@H_403_3@"GO"@H_403_3@+@H_403_3@"<br></br>"@H_403_3@@H_403_3@@H_403_3@
  39. }@H_403_3@
  40. @H_403_3@
  41. for@H_403_3@_,V:=rangeresultMain{@H_403_3@@H_403_3@
  42. result=result+strings.Replace(strings.Replace(sql,-1)+@H_403_3@@H_403_3@
  43. "<br></br>"@H_403_3@+@H_403_3@"GO"@H_403_3@+@H_403_3@"<br></br>"@H_403_3@@H_403_3@@H_403_3@
  44. }@H_403_3@
  45. @H_403_3@
  46. return@H_403_3@@H_403_3@@H_403_3@
  47. }@H_403_3@
  48. @H_403_3@
  49. funcAnalyze(whttp.ResponseWriter,r*http.Request){@H_403_3@
  50. if@H_403_3@r.Method==@H_403_3@"GET"@H_403_3@{@H_403_3@@H_403_3@
  51. io.WriteString(w,strings.Replace(html,"%s"@H_403_3@,@H_403_3@""@H_403_3@,-1))@H_403_3@@H_403_3@
  52. return@H_403_3@@H_403_3@@H_403_3@
  53. }@H_403_3@
  54. @H_403_3@
  55. if@H_403_3@r.Method==@H_403_3@"POST"@H_403_3@{@H_403_3@@H_403_3@
  56. str:=r.FormValue("target"@H_403_3@)@H_403_3@@H_403_3@
  57. tablename:=r.FormValue("tablename"@H_403_3@)@H_403_3@@H_403_3@
  58. tablename2:=r.FormValue("tablename2"@H_403_3@)@H_403_3@@H_403_3@
  59. if@H_403_3@tablename==@H_403_3@""@H_403_3@{@H_403_3@@H_403_3@
  60. io.WriteString(w,@H_403_3@"<divborder='1'>"@H_403_3@+@H_403_3@@H_403_3@
  61. "TableName没有填写"@H_403_3@+@H_403_3@"</div>"@H_403_3@,-1))@H_403_3@@H_403_3@
  62. return@H_403_3@@H_403_3@@H_403_3@
  63. }@H_403_3@
  64. if@H_403_3@tablename2==@H_403_3@""@H_403_3@{@H_403_3@@H_403_3@
  65. io.WriteString(w,@H_403_3@"<divborder='1'>"@H_403_3@+@H_403_3@@H_403_3@
  66. "表格名称没有填写"@H_403_3@+@H_403_3@"</div>"@H_403_3@,-1))@H_403_3@@H_403_3@
  67. return@H_403_3@@H_403_3@@H_403_3@
  68. }@H_403_3@
  69. if@H_403_3@str==@H_403_3@""@H_403_3@{@H_403_3@@H_403_3@
  70. io.WriteString(w,@H_403_3@"<divborder='1'>"@H_403_3@+@H_403_3@@H_403_3@
  71. "查找内容没有填写"@H_403_3@+@H_403_3@"</div>"@H_403_3@,-1))@H_403_3@@H_403_3@
  72. return@H_403_3@@H_403_3@@H_403_3@
  73. }@H_403_3@
  74. @H_403_3@
  75. sqlCMD:=strings.Replace(html,@H_403_3@"<divborder='1'>"@H_403_3@+@H_403_3@@H_403_3@
  76. strings.Replace(mySearch(str),"CCCC"@H_403_3@,tablename,-1)+@H_403_3@"</div>"@H_403_3@,-1)@H_403_3@@H_403_3@
  77. sqlCMD=sqlCMD+strings.Replace(strings.Replace(sql2,tablename2,@H_403_3@"CCCC"@H_403_3@,-1)@H_403_3@@H_403_3@
  78. io.WriteString(w,sqlCMD)@H_403_3@
  79. }@H_403_3@
  80. }@H_403_3@
  81. @H_403_3@
  82. funcmain(){@H_403_3@
  83. fmt.Println("Openhttp://localhost:8888/extract"@H_403_3@)@H_403_3@@H_403_3@
  84. http.HandleFunc("/extract"@H_403_3@,Analyze)@H_403_3@@H_403_3@
  85. err:=http.ListenAndServe(":8888"@H_403_3@,nil)@H_403_3@@H_403_3@
  86. if@H_403_3@err!=nil{@H_403_3@@H_403_3@
  87. fmt.Println(err.Error())@H_403_3@
  88. }@H_403_3@
  89. }@H_403_3@

猜你在找的正则表达式相关文章