importpaths

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package importpaths implements import path rewriting credit: https://gist.github.com/jackspirou/61ce33574e9f411b8b4a

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("skip import")

ErrSkip is used to signal that an import should be skipped

Functions

func Rewrite

func Rewrite(dir string, replace ReplaceFunc) error

Rewrite takes a directory path and a function for replacing imports paths Note: underscore-prefix, dot-prefix, vendor, and submodule directories are skipped.

func RewriteFile

func RewriteFile(name string, replace ReplaceFunc) error

RewriteFile rewrites import statments in the named file according to the rules supplied by the map of strings.

func RewriteModule added in v0.8.0

func RewriteModule(dir string, opt RewriteModuleOptions) error

RewriteModule rewrites imports of a specific module to a new version or prefix. If a package directory is provided, only imports of that package will be rewritten.

Types

type ReplaceFunc

type ReplaceFunc func(pos token.Position, path string) (string, error)

ReplaceFunc is called with every import path and returns the replacement path if the second return parameter is false, the replacement doesn't happen

type RewriteModuleOptions added in v0.8.0

type RewriteModuleOptions struct {
	Prefix     string
	NewVersion string
	NewPrefix  string
	PkgDir     string
	OnRewrite  func(pos token.Position, oldpath, newpath string) error
}

RewriteModuleOptions contains options for rewriting a module's imports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL