imports

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package imports is a small package for dealing with import paths. imports picks unique names if needed and is able to determine the assumed name of the of an import path. It also orders the imports properly for `gofmt`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssumedName

func AssumedName(importPath string) string

AssumedName returns the assumed package name of an import path. It does this using only string parsing of the import path. It picks the last element of the path that does not look like a major version, and then picks the valid identifier off the start of that element. It is used to determine if a local rename should be added to an import for clarity. This function could be moved to a standard package and exported if we want for use in other tools.

Types

type Import

type Import struct {
	// Package identifier name
	Name string `json:"name,omitempty"`
	// Path to the import
	Path string `json:"path,omitempty"`
}

Import struct returned by list

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set of imports

func New

func New() *Set

New import set

func (*Set) Add

func (s *Set) Add(path string) string

Add to the set

func (*Set) AddNamed

func (s *Set) AddNamed(name, path string) string

AddNamed brings a preferred name

func (*Set) AddStd

func (s *Set) AddStd(pkgs ...string)

AddStd is a convenience function for adding standard library packages

func (*Set) List

func (s *Set) List() (imports []*Import)

List imports by path first, then by name

func (*Set) Reserve

func (s *Set) Reserve(path string) string

Reserve a name, but don't take import it. If Add or AddNamed come later, we'll use the same name but add it to the list of paths

Jump to

Keyboard shortcuts

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