multipart.go 727 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package bundler
  2. import (
  3. "os"
  4. "path/filepath"
  5. pb "github.com/sqlc-dev/sqlc/internal/quickdb/v1"
  6. "github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
  7. )
  8. func readFiles(dir string, paths []string) ([]*pb.File, error) {
  9. files, err := sqlpath.Glob(paths)
  10. if err != nil {
  11. return nil, err
  12. }
  13. var out []*pb.File
  14. for _, file := range files {
  15. f, err := readFile(dir, file)
  16. if err != nil {
  17. return nil, err
  18. }
  19. out = append(out, f)
  20. }
  21. return out, nil
  22. }
  23. func readFile(dir string, path string) (*pb.File, error) {
  24. rel, err := filepath.Rel(dir, path)
  25. if err != nil {
  26. return nil, err
  27. }
  28. blob, err := os.ReadFile(path)
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &pb.File{
  33. Name: rel,
  34. Contents: blob,
  35. }, nil
  36. }