This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
gofiber_detector.go
54 lines (46 loc) · 1.54 KB
/
gofiber_detector.go
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
/*******************************************************************************
* Copyright (c) 2022 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc.
******************************************************************************/
package enricher
import (
"context"
"regexp"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"github.com/redhat-developer/alizer/go/pkg/utils"
"golang.org/x/mod/modfile"
)
type GoFiberDetector struct{}
func (g GoFiberDetector) GetSupportedFrameworks() []string {
return []string{"GoFiber"}
}
// DoFrameworkDetection uses a tag to check for the framework name
func (g GoFiberDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/gofiber/fiber") {
language.Frameworks = append(language.Frameworks, "GoFiber")
}
}
func (g GoFiberDetector) DoPortsDetection(component *model.Component, ctx *context.Context) {
files, err := utils.GetCachedFilePathsFromRoot(component.Path, ctx)
if err != nil {
return
}
matchRegexRules := model.PortMatchRules{
MatchIndexRegexes: []model.PortMatchRule{
{
Regex: regexp.MustCompile(`.Listen\(([^,)]*)`),
ToReplace: ".Listen(",
},
},
}
ports := GetPortFromFilesGo(matchRegexRules, files)
if len(ports) > 0 {
component.Ports = ports
}
}