util

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortImports

func SortImports(imports []Import)

SortImports performs an in-place sort on the passed imports, sorting each by the Path.

Types

type GroupedImports

type GroupedImports struct {
	StandardLib []Import
	ThirdParty  []Import
	Module      []Import
}

GroupedImports groups imports into different sections, for cleaner import blocks.

func GroupImports

func GroupImports(imports []Import) GroupedImports

GroupImports groups the passed imports into a GroupedImports. Each group maintains the relative order of the imports.

func (GroupedImports) Groups

func (i GroupedImports) Groups() [][]Import

Groups returns a slice of slice of Import, with each top-level slice being a different group. The groups are ordered as standard library, third party, and then module imports.

func (GroupedImports) Len

func (i GroupedImports) Len() int

Len returns the total number of imports

type Import

type Import struct {
	Path string
	As   string
}

Import represents an import of a package in a Go file

type ImportSet

type ImportSet map[Import]struct{}

ImportSet is a set of Imports (for removing duplicates). Its zero value can be used without initialization.

func (*ImportSet) Add

func (i *ImportSet) Add(newImport Import)

Add adds the given import to the set, ignoring duplicates.

func (*ImportSet) AddPath

func (i *ImportSet) AddPath(path string)

AddPath adds the given import path to the set.

func (ImportSet) Get

func (i ImportSet) Get() []Import

Get returns a new slice of all the imports stored in the set. The order is not specified; it is recommended to call SortImports on the returned value.

func (*ImportSet) Merge

func (i *ImportSet) Merge(other ImportSet)

Merge adds all Import values from `other` into this set.

type RecursiveAppend

type RecursiveAppend[T any] struct {
	Idx  int
	Keys []T
	Root string
	Data map[string]any
}

RecursiveAppend is used in templates to give a way to concisely reference nested fields.

func (RecursiveAppend[T]) Current

func (r RecursiveAppend[T]) Current() T

func (RecursiveAppend[T]) IsLast

func (r RecursiveAppend[T]) IsLast() bool

func (RecursiveAppend[T]) IterVar

func (r RecursiveAppend[T]) IterVar() string

func (RecursiveAppend[T]) Next

func (r RecursiveAppend[T]) Next() (RecursiveAppend[T], error)

func (RecursiveAppend[T]) NextIterVar

func (r RecursiveAppend[T]) NextIterVar() string

func (*RecursiveAppend[T]) SetData

func (r *RecursiveAppend[T]) SetData(key string, value any) error

func (RecursiveAppend[T]) WithRoot

func (r RecursiveAppend[T]) WithRoot(root string) RecursiveAppend[T]

Jump to

Keyboard shortcuts

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