imports

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package imports changes the import paths of Go files, keeping everything else byte for byte. orb eject uses it to point an app at its copy of a built-in module, and go generate to point a golden app's copy back at the library (ADR-0083).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite

func Rewrite(filename string, src []byte, m Mapping) (out []byte, changed bool, err error)

Rewrite changes src's imports that m maps, then formats it. The import gets the package's name when that differs from its new path's last element, and loses a name that the new path makes redundant, so the file keeps compiling and reads the same; and it moves to the group of imports it belongs with, such as the app's own. changed is false, and src is returned as it is, when m maps none of src's imports.

Types

type Mapping

type Mapping func(imp string) (to, name string, ok bool)

A Mapping returns the path an import moves to and the name of the package found there, or ok false to leave the import as it is. name is empty when the package's name is the last element of to.

Jump to

Keyboard shortcuts

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