-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2de866
commit a0787ee
Showing
7 changed files
with
29 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${fileDirname}" | ||
"mode": "debug", | ||
"program": "${workspaceFolder}/cmd/api/main.go", | ||
"cwd": "${workspaceFolder}", | ||
"args": [], | ||
"buildFlags": "", | ||
"env": {}, | ||
"port": 0 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,12 @@ | ||
package routes | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"plugin" | ||
"strings" | ||
|
||
"github.com/VikashChauhan51/go-sample-api/internal/core/interfaces" | ||
) | ||
|
||
// ScanRoutes scans all route files in the current directory and collects routes. | ||
func ScanRoutes(db interfaces.Database) ([]Route, error) { | ||
func ScanRoutes(db interfaces.Database) []Route { | ||
var allRoutes []Route | ||
|
||
// Find all *_routes.go files in the current directory | ||
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if strings.HasSuffix(info.Name(), "_routes.go") { | ||
routes, err := loadRoutesFromPlugin(path, db) | ||
if err != nil { | ||
return err | ||
} | ||
allRoutes = append(allRoutes, routes...) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to scan route files: %v", err) | ||
} | ||
|
||
return allRoutes, nil | ||
} | ||
|
||
// loadRoutesFromPlugin loads routes from a plugin file. | ||
func loadRoutesFromPlugin(path string, db interfaces.Database) ([]Route, error) { | ||
p, err := plugin.Open(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open plugin %s: %v", path, err) | ||
} | ||
|
||
sym, err := p.Lookup("Routes") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to find GetRoutes in plugin %s: %v", path, err) | ||
} | ||
|
||
getRoutesFunc, ok := sym.(func(interfaces.Database) []Route) | ||
if !ok { | ||
return nil, fmt.Errorf("GetRoutes function has incorrect signature in plugin %s", path) | ||
} | ||
|
||
return getRoutesFunc(db), nil | ||
booksRoutes := GetBookRoutes(db) | ||
allRoutes = append(allRoutes, booksRoutes...) | ||
return allRoutes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters