init
This commit is contained in:
commit
9298fc4e4c
12 changed files with 599 additions and 0 deletions
38
internal/packages/packages.go
Normal file
38
internal/packages/packages.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package packages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Package struct {
|
||||
Name string
|
||||
Dependencies []Dependency
|
||||
}
|
||||
|
||||
type Dependency struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
func LookupPackageFile(name string) (io.Reader, error) {
|
||||
path := filepath.Join("./packages", name+".lua")
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("opening package file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
_, err = io.Copy(buf, f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading package file: %w", err)
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue