func GuessPackage(fileName string) (string, error) {
	goModDir, err := FindDir()
	if err != nil {
		return "", fmt.Errorf("find go.mod dir: %w", err)
	}
	goModPath, err := ParsePath()
	if err != nil {
		return "", fmt.Errorf("parse go.mod dir: %w", err)
	}
	abs, err := filepath.Abs(fileName)
	if err != nil {
		return "", fmt.Errorf("abs path for %s: %w", fileName, err)
	}
	rel, err := filepath.Rel(goModDir, abs)
	if err != nil {
		return "", fmt.Errorf("rel path to go.mod for %s: %w", fileName, err)
	}
	relDir := filepath.ToSlash(filepath.Clean(filepath.Dir(rel)))
	return goModPath + "/" + relDir, nil
}
GuessPackage guesses the full Go package path for a file name, relative to
current working directory.
Imperfect. Assumes package names always match directory names.
package gomod
import (
	"fmt"
	"github.com/jschaf/pggen/internal/paths"
	"golang.org/x/mod/modfile"
	"io/ioutil"
	"os"
	"path/filepath"
	"sync"
)
var (
	goModDirOnce = &sync.Once{}
	goModDir     string
	goModDirErr  error
	goModNameOnce = &sync.Once{}
	goModPath     string
	goModPathErr  error
)
func FindDir() (string, error) {
	goModDirOnce.Do(func() {
		wd, err := os.Getwd()
		if err != nil {
			goModDirErr = fmt.Errorf("FindDir working dir: %w", err)
			return
		}
		goModDir, goModDirErr = paths.WalkUp(wd, "go.mod")
	})
	return goModDir, goModDirErr
}
func ParsePath() (string, error) {
	goModNameOnce.Do(func() {
		dir, err := FindDir()
		if err != nil {
			goModPathErr = fmt.Errorf("find go.mod dir: %w", err)
			return
		}
		p := filepath.Join(dir, "go.mod")
		bs, err := ioutil.ReadFile(p)
		if err != nil {
			goModPathErr = fmt.Errorf("read go.mod: %w", err)
			return
		}
		goModPath = modfile.ModulePath(bs)
	})
	return goModPath, goModPathErr
}