-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.go
More file actions
127 lines (108 loc) · 2.31 KB
/
Copy pathreader.go
File metadata and controls
127 lines (108 loc) · 2.31 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package apiDocPrinter
import (
"os"
"bufio"
"strings"
"fmt"
"encoding/json"
)
/**
author : LinGuanHong
github : https://github.com/af913337456
blog : http://www.cnblogs.com/linguanh
time : 12:41
*/
func ReadCodeFile(fileName string) []Temp1Obj {
file,err := os.OpenFile(fileName,os.O_RDONLY,0777)
if err != nil {
panic(err)
}
var item Temp1Obj
reader := bufio.NewReader(file)
begin := false
objList := []Temp1Obj{}
endLine := ""
for {
var line = ""
if endLine != "" {
line = endLine
}else{
byt, _, err := reader.ReadLine()
if err != nil {
// 读完一个文件
break
}
line = string(byt)
}
if line == "" {
continue
}
line = strings.TrimSpace(line)
if begin {
fmt.Println(line)
if line == "*/" {
begin = false
bys,_ := json.Marshal(item)
fmt.Println(string(bys))
objList = append(objList,item)
endLine = ""
item = Temp1Obj{}
}else{
tag,val := ParseTag(line)
switch tag {
case NameTag:
item.Name = getVal(val,reader)
break
case RouterTag:
item.Router = getVal(val,reader)
break
case HttpTag:
item.ReqWay = getVal(val,reader)
break
case FormatTag:
item.Format = getVal(val,reader)
break
case TokenTag:
item.Token = getVal(val,reader)
break
case EndTag:
break
case InputJsonTag:
endLine,item.JsonInputLines = GetContents(InputJsonTag,reader)
break
case InputXmlTag:
endLine,item.XmlInputLines = GetContents(InputXmlTag,reader)
break
case InputTextTag:
endLine,item.TextInputLines = GetContents(InputTextTag,reader)
break
case InputDesTag:
endLine,item.InputDesLines = GetContents(InputDesTag,reader)
break
case OutputJsonTag:
endLine,item.JsonOutputLines = GetContents(OutputJsonTag,reader)
break
case OutputXmlTag:
endLine,item.XmlOutputLines = GetContents(OutputXmlTag,reader)
break
case OutputTextTag:
endLine,item.TextOutputLines = GetContents(OutputTextTag,reader)
break
case OutputDesTag:
endLine,item.OutputDesLines = GetContents(OutputDesTag,reader)
break
default:
}
}
continue
}
if line == "/*" || line == "/**" {
// 开始
begin = true
item = Temp1Obj{}
}else{
begin = false
}
}
return objList
}