Skip to content

Commit 128ce13

Browse files
authored
Merge pull request #55 from hahwul/hahwul-dev
Hahwul dev
2 parents 7083806 + 1f45777 commit 128ce13

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
| Language | Framework | URL | Method | Param | Header | WS |
2323
|----------|-----------|-----|--------|-------|--------|----|
24-
| Go | Echo || | X | X | X |
24+
| Go | Echo ||| | X | X |
2525
| Python | Django || X | X | X | X |
2626
| Python | Flask || X | X | X | X |
2727
| Ruby | Rails ||||| X |

Diff for: spec/functional_test/fixtures/go_echo/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ func main() {
1212
return c.String(http.StatusOK, "Hello, World!")
1313
})
1414
e.GET("/pet", func(c echo.Context) error {
15+
_ = c.QueryParam("query")
16+
return c.String(http.StatusOK, "Hello, Pet!")
17+
})
18+
e.POST("/pet", func(c echo.Context) error {
19+
_ = c.Param("name")
20+
return c.String(http.StatusOK, "Hello, Pet!")
21+
})
22+
e.POST("/pet_form", func(c echo.Context) error {
23+
_ = c.FormValue("name")
1524
return c.String(http.StatusOK, "Hello, Pet!")
1625
})
1726
e.Static("/public", "public")

Diff for: spec/functional_test/testers/go_echo_spec.cr

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ require "../func_spec.cr"
22

33
extected_endpoints = [
44
Endpoint.new("/", "GET"),
5-
Endpoint.new("/pet", "GET"),
5+
Endpoint.new("/pet", "GET", [
6+
Param.new("query", "", "query"),
7+
]),
8+
Endpoint.new("/pet", "POST", [
9+
Param.new("name", "", "json"),
10+
]),
11+
Endpoint.new("/pet_form", "POST", [
12+
Param.new("name", "", "body"),
13+
]),
614
Endpoint.new("/public/secret.html", "GET"),
715
]
816

917
FunctionalTester.new("fixtures/go_echo/", {
1018
:techs => 1,
11-
:endpoints => 3,
19+
:endpoints => 5,
1220
}, extected_endpoints).test_all

Diff for: src/analyzer/analyzers/analyzer_go_echo.cr

+36-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@ class AnalyzerGoEcho < Analyzer
88
next if File.directory?(path)
99
if File.exists?(path) && File.extname(path) == ".go"
1010
File.open(path, "r", encoding: "utf-8", invalid: :skip) do |file|
11+
last_endpoint = Endpoint.new("", "")
1112
file.each_line do |line|
1213
if line.includes?(".GET(") || line.includes?(".POST(") || line.includes?(".PUT(") || line.includes?(".DELETE(")
1314
get_route_path(line).tap do |route_path|
1415
if route_path.size > 0
15-
result << Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
16+
new_endpoint = Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
17+
result << new_endpoint
18+
last_endpoint = new_endpoint
19+
end
20+
end
21+
end
22+
23+
if line.includes?("Param(") || line.includes?("FormValue(")
24+
get_param(line).tap do |param|
25+
if param.name.size > 0 && last_endpoint.method != ""
26+
last_endpoint.params << param
1627
end
1728
end
1829
end
@@ -30,7 +41,7 @@ class AnalyzerGoEcho < Analyzer
3041
end
3142

3243
public_dirs.each do |p_dir|
33-
full_path = (base_path + "/" + p_dir["file_path"]).gsub("//","/")
44+
full_path = (base_path + "/" + p_dir["file_path"]).gsub("//", "/")
3445
Dir.glob("#{full_path}/**/*") do |path|
3546
next if File.directory?(path)
3647
if File.exists?(path)
@@ -48,6 +59,29 @@ class AnalyzerGoEcho < Analyzer
4859
result
4960
end
5061

62+
def get_param(line : String) : Param
63+
param_type = "json"
64+
if line.includes?("QueryParam")
65+
param_type = "query"
66+
end
67+
if line.includes?("FormValue")
68+
param_type = "body"
69+
end
70+
71+
first = line.strip.split("(")
72+
if first.size > 1
73+
second = first[1].split(")")
74+
if second.size > 1
75+
param_name = second[0].gsub("\"", "")
76+
rtn = Param.new(param_name, "", param_type)
77+
78+
return rtn
79+
end
80+
end
81+
82+
Param.new("", "", "")
83+
end
84+
5185
def get_static_path(line : String) : Hash(String, String)
5286
first = line.strip.split("(")
5387
if first.size > 1

0 commit comments

Comments
 (0)