tools

package module
v0.0.0-...-71c8dda Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Go Tools

Tools for refactoring go source code

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeclNotFound    = errors.New("Declaration not found")
	ErrPackageMismatch = errors.New("Different package declarations found")
)

Functions

func Organize

func Organize(filename string, input []byte) (output []byte, err error)

func SeparateValues

func SeparateValues(filename string, input []byte) (output []byte, err error)

Types

type Change

type Change struct {
	Filename string
	Orig     []byte
	Current  []byte
}

type FileWriter

type FileWriter func(filename string, data []byte) error

type Replacer

type Replacer struct {
	Err error
	// contains filtered or unexported fields
}

func Replace

func Replace(filename string, src []byte) (r *Replacer)

func (*Replacer) Content

func (r *Replacer) Content() []byte

func (*Replacer) Func

func (r *Replacer) Func(name, receiver string, content string) *Replacer

type Tools

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

func New

func New() *Tools

func (*Tools) Add

func (f *Tools) Add(filename string, src []byte) error

Add will attempt to add the given source to the file set and parse the content. If the filename already exists in the file set then fs.ErrExist is returned. Otherwise any parse errors are returned

func (*Tools) AddDir

func (f *Tools) AddDir(dir string) error

AddDir will add all the *.go files in the given directory to the local file set. Each file will be parsed. If any parsing errors occur processing stops and the associated error is returned

func (*Tools) AddFile

func (f *Tools) AddFile(filename string) error

AddFile will read the file and add it to the local fileset

func (*Tools) AddFiles

func (f *Tools) AddFiles(files ...string) (err error)

AddFiles will add all the files supplied

func (*Tools) ChangedFiles

func (f *Tools) ChangedFiles() (changed []string)

ChangedFiles returns a list of filenames whose content has changed during the course of processing

func (*Tools) Changes

func (f *Tools) Changes() (changed []Change)

Changes returns a slice of Change structs containing information about each file that was changed

func (*Tools) Organize

func (f *Tools) Organize(filename string) (output []byte, err error)

func (*Tools) OrganizeAll

func (f *Tools) OrganizeAll() (err error)

func (*Tools) OrganizeFiles

func (f *Tools) OrganizeFiles(files ...string) (err error)

func (*Tools) SeparateValues

func (f *Tools) SeparateValues(filename string) ([]byte, error)

SeparateValues analyzes the file and will group const and var blocks by type. SeparateValues will only manipulate declarations that are within parenthesized blocks, ie:

const (
 Int1 int = iota
 Int2
 Int3
 Int4

 Str1 string = "string1"
 Str2        = "string2"
 Str3        = "string3"
 Str4        = "string4"
)

Becomes:

const (
  Int1 int = iota
  Int2
  Int3
  Int4
)

const (
  Str1 string = "string1"
  Str2        = "string2"
  Str3        = "string3"
  Str4        = "string4"
)

func (*Tools) WriteFiles

func (f *Tools) WriteFiles(writer FileWriter) (err error)

WriteFiles will write all the changed files using the supplied FileWriter. If an error is encountered processing stops and the error is returned

Directories

Path Synopsis
cmd
gorg
Package diff implements a Diff function that compare two inputs using the 'diff' tool.
Package diff implements a Diff function that compare two inputs using the 'diff' tool.

Jump to

Keyboard shortcuts

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