34 lines
598 B
Go
34 lines
598 B
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
"path"
|
|
"strings"
|
|
|
|
"path/filepath"
|
|
)
|
|
|
|
func GetPackageFromStore(packageName string) (string, error) {
|
|
fileToServe := ""
|
|
searchDir, err := filepath.Abs("./examples")
|
|
if err != nil {
|
|
fmt.Printf("File repo not found: +%v/n", err)
|
|
return "", err
|
|
}
|
|
|
|
err = filepath.WalkDir(searchDir, func(fp string, info fs.DirEntry, e error) error {
|
|
if strings.Contains(fp, path.Join(packageName, "index.json")) {
|
|
fileToServe = fp
|
|
}
|
|
return e
|
|
})
|
|
|
|
if err != nil {
|
|
fmt.Printf("List files error: +%v/n", err)
|
|
return "", err
|
|
}
|
|
|
|
return fileToServe, nil
|
|
}
|