1use super::{LanguageFrameworkDetector, TechnologyRule, FrameworkDetectionUtils};
2use crate::analyzer::{DetectedTechnology, DetectedLanguage, TechnologyCategory, LibraryType};
3use crate::error::Result;
4
5pub struct GoFrameworkDetector;
6
7impl LanguageFrameworkDetector for GoFrameworkDetector {
8 fn detect_frameworks(&self, language: &DetectedLanguage) -> Result<Vec<DetectedTechnology>> {
9 let rules = get_go_technology_rules();
10
11 let all_deps: Vec<String> = language.main_dependencies.iter()
13 .chain(language.dev_dependencies.iter())
14 .cloned()
15 .collect();
16
17 let technologies = FrameworkDetectionUtils::detect_technologies_by_dependencies(
18 &rules, &all_deps, language.confidence
19 );
20
21 Ok(technologies)
22 }
23
24 fn supported_languages(&self) -> Vec<&'static str> {
25 vec!["Go"]
26 }
27}
28
29fn get_go_technology_rules() -> Vec<TechnologyRule> {
31 vec![
32 TechnologyRule {
34 name: "Gin".to_string(),
35 category: TechnologyCategory::BackendFramework,
36 confidence: 0.95,
37 dependency_patterns: vec!["github.com/gin-gonic/gin".to_string(), "gin-gonic".to_string()],
38 requires: vec![],
39 conflicts_with: vec![],
40 is_primary_indicator: true,
41 alternative_names: vec!["gin-gonic".to_string()],
42 },
43 TechnologyRule {
44 name: "Echo".to_string(),
45 category: TechnologyCategory::BackendFramework,
46 confidence: 0.95,
47 dependency_patterns: vec!["github.com/labstack/echo".to_string(), "labstack/echo".to_string()],
48 requires: vec![],
49 conflicts_with: vec![],
50 is_primary_indicator: true,
51 alternative_names: vec!["labstack/echo".to_string()],
52 },
53 TechnologyRule {
54 name: "Fiber".to_string(),
55 category: TechnologyCategory::BackendFramework,
56 confidence: 0.95,
57 dependency_patterns: vec!["github.com/gofiber/fiber".to_string(), "gofiber".to_string()],
58 requires: vec![],
59 conflicts_with: vec![],
60 is_primary_indicator: true,
61 alternative_names: vec!["gofiber".to_string()],
62 },
63 TechnologyRule {
64 name: "Beego".to_string(),
65 category: TechnologyCategory::BackendFramework,
66 confidence: 0.95,
67 dependency_patterns: vec!["github.com/beego/beego".to_string(), "beego".to_string()],
68 requires: vec![],
69 conflicts_with: vec![],
70 is_primary_indicator: true,
71 alternative_names: vec![],
72 },
73 TechnologyRule {
74 name: "Chi".to_string(),
75 category: TechnologyCategory::BackendFramework,
76 confidence: 0.90,
77 dependency_patterns: vec!["github.com/go-chi/chi".to_string(), "go-chi".to_string()],
78 requires: vec![],
79 conflicts_with: vec![],
80 is_primary_indicator: true,
81 alternative_names: vec!["go-chi".to_string()],
82 },
83 TechnologyRule {
84 name: "Gorilla Mux".to_string(),
85 category: TechnologyCategory::BackendFramework,
86 confidence: 0.90,
87 dependency_patterns: vec!["github.com/gorilla/mux".to_string(), "gorilla/mux".to_string()],
88 requires: vec![],
89 conflicts_with: vec![],
90 is_primary_indicator: true,
91 alternative_names: vec!["mux".to_string(), "gorilla".to_string()],
92 },
93 TechnologyRule {
94 name: "Revel".to_string(),
95 category: TechnologyCategory::BackendFramework,
96 confidence: 0.90,
97 dependency_patterns: vec!["github.com/revel/revel".to_string(), "revel".to_string()],
98 requires: vec![],
99 conflicts_with: vec![],
100 is_primary_indicator: true,
101 alternative_names: vec![],
102 },
103 TechnologyRule {
104 name: "Buffalo".to_string(),
105 category: TechnologyCategory::BackendFramework,
106 confidence: 0.90,
107 dependency_patterns: vec!["github.com/gobuffalo/buffalo".to_string(), "gobuffalo".to_string()],
108 requires: vec![],
109 conflicts_with: vec![],
110 is_primary_indicator: true,
111 alternative_names: vec!["gobuffalo".to_string()],
112 },
113 TechnologyRule {
114 name: "Iris".to_string(),
115 category: TechnologyCategory::BackendFramework,
116 confidence: 0.90,
117 dependency_patterns: vec!["github.com/kataras/iris".to_string(), "kataras/iris".to_string()],
118 requires: vec![],
119 conflicts_with: vec![],
120 is_primary_indicator: true,
121 alternative_names: vec![],
122 },
123 TechnologyRule {
124 name: "FastHTTP".to_string(),
125 category: TechnologyCategory::BackendFramework,
126 confidence: 0.95,
127 dependency_patterns: vec!["github.com/valyala/fasthttp".to_string(), "fasthttp".to_string()],
128 requires: vec![],
129 conflicts_with: vec![],
130 is_primary_indicator: true,
131 alternative_names: vec!["valyala/fasthttp".to_string()],
132 },
133 TechnologyRule {
134 name: "Hertz".to_string(),
135 category: TechnologyCategory::BackendFramework,
136 confidence: 0.95,
137 dependency_patterns: vec!["github.com/cloudwego/hertz".to_string(), "cloudwego/hertz".to_string()],
138 requires: vec![],
139 conflicts_with: vec![],
140 is_primary_indicator: true,
141 alternative_names: vec!["cloudwego".to_string()],
142 },
143
144 TechnologyRule {
146 name: "GORM".to_string(),
147 category: TechnologyCategory::Database,
148 confidence: 0.90,
149 dependency_patterns: vec!["gorm.io/gorm".to_string(), "gorm".to_string()],
150 requires: vec![],
151 conflicts_with: vec![],
152 is_primary_indicator: false,
153 alternative_names: vec![],
154 },
155 TechnologyRule {
156 name: "Ent".to_string(),
157 category: TechnologyCategory::Database,
158 confidence: 0.90,
159 dependency_patterns: vec!["entgo.io/ent".to_string(), "facebook/ent".to_string()],
160 requires: vec![],
161 conflicts_with: vec![],
162 is_primary_indicator: false,
163 alternative_names: vec!["entgo".to_string()],
164 },
165 TechnologyRule {
166 name: "Xorm".to_string(),
167 category: TechnologyCategory::Database,
168 confidence: 0.85,
169 dependency_patterns: vec!["xorm.io/xorm".to_string(), "xorm".to_string()],
170 requires: vec![],
171 conflicts_with: vec![],
172 is_primary_indicator: false,
173 alternative_names: vec![],
174 },
175
176 TechnologyRule {
178 name: "Go Kit".to_string(),
179 category: TechnologyCategory::Library(LibraryType::Utility),
180 confidence: 0.90,
181 dependency_patterns: vec!["github.com/go-kit/kit".to_string(), "go-kit".to_string()],
182 requires: vec![],
183 conflicts_with: vec![],
184 is_primary_indicator: false,
185 alternative_names: vec!["kit".to_string()],
186 },
187 TechnologyRule {
188 name: "Kratos".to_string(),
189 category: TechnologyCategory::BackendFramework,
190 confidence: 0.90,
191 dependency_patterns: vec!["github.com/go-kratos/kratos".to_string(), "go-kratos".to_string()],
192 requires: vec![],
193 conflicts_with: vec![],
194 is_primary_indicator: true,
195 alternative_names: vec!["go-kratos".to_string()],
196 },
197
198 TechnologyRule {
200 name: "Sarama".to_string(),
201 category: TechnologyCategory::Library(LibraryType::Utility),
202 confidence: 0.85,
203 dependency_patterns: vec!["github.com/shopify/sarama".to_string(), "sarama".to_string()],
204 requires: vec![],
205 conflicts_with: vec![],
206 is_primary_indicator: false,
207 alternative_names: vec!["shopify/sarama".to_string()],
208 },
209
210 TechnologyRule {
212 name: "Testify".to_string(),
213 category: TechnologyCategory::Testing,
214 confidence: 0.85,
215 dependency_patterns: vec!["github.com/stretchr/testify".to_string(), "testify".to_string()],
216 requires: vec![],
217 conflicts_with: vec![],
218 is_primary_indicator: false,
219 alternative_names: vec!["stretchr/testify".to_string()],
220 },
221 TechnologyRule {
222 name: "Ginkgo".to_string(),
223 category: TechnologyCategory::Testing,
224 confidence: 0.85,
225 dependency_patterns: vec!["github.com/onsi/ginkgo".to_string(), "ginkgo".to_string()],
226 requires: vec![],
227 conflicts_with: vec![],
228 is_primary_indicator: false,
229 alternative_names: vec!["onsi/ginkgo".to_string()],
230 },
231
232 TechnologyRule {
234 name: "Cobra".to_string(),
235 category: TechnologyCategory::Library(LibraryType::CLI),
236 confidence: 0.85,
237 dependency_patterns: vec!["github.com/spf13/cobra".to_string(), "cobra".to_string()],
238 requires: vec![],
239 conflicts_with: vec![],
240 is_primary_indicator: true,
241 alternative_names: vec!["spf13/cobra".to_string()],
242 },
243
244 TechnologyRule {
246 name: "Viper".to_string(),
247 category: TechnologyCategory::Library(LibraryType::Utility),
248 confidence: 0.80,
249 dependency_patterns: vec!["github.com/spf13/viper".to_string(), "viper".to_string()],
250 requires: vec![],
251 conflicts_with: vec![],
252 is_primary_indicator: false,
253 alternative_names: vec!["spf13/viper".to_string()],
254 },
255 ]
256}