patch

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCode

func AddCode(edit *goedit.Edit, pos token.Pos, code string)

func AddCodeAfterImportsLegacy deprecated added in v1.1.4

func AddCodeAfterImportsLegacy(code string, beginMark string, endMark string, contents []string) string

Deprecated: use AddImportAfterName instead

func AddContentAfter deprecated

func AddContentAfter(content string, beginMark string, endMark string, seq []string, addContent string) string

Deprecated: use AddContentAtIndex instead

func AddContentAfterName added in v1.1.4

func AddContentAfterName(code string, beginMark string, endMark string, insertContent string) string

func AddContentBefore deprecated

func AddContentBefore(content string, beginMark string, endMark string, seq []string, addContent string) string

Deprecated: use AddContentAtIndex instead

func AddImport

func AddImport(edit *goedit.Edit, file *ast.File, name string, pkgPath string)

func AddImportAfterName added in v1.1.4

func AddImportAfterName(code string, beginMark string, endMark string, name string, pkgPath string) string

package something -> package something;import __my_fmt "fmt"

func Append added in v1.1.2

func Append(edit *goedit.Edit, file *ast.File, s string)

func CleanPatch

func CleanPatch(content string) string

CleanPatch removes all content between /*<begin and /*<end markers

func CleanPatchMarkers

func CleanPatchMarkers(content string, start PatchMarker, end PatchMarker) string

func EditFile

func EditFile(file string, callback func(content string) (string, error)) (err error)

func FmtLineDirective

func FmtLineDirective(srcFile string, line int) string

for line directive, check https://github.com/golang/go/blob/24b395119b4df7f16915b9f01a6aded647b79bbd/src/cmd/compile/doc.go#L171 this tells the compiler, next line's line number is `line`

func GetFuncInsertPosition

func GetFuncInsertPosition(file *ast.File) token.Pos

NOTE: new func is always inserted after a position because a function or variable may have some special directive like go:embed, go:linkname... we cannot add anything before them.

func RemoveBuildIgnore

func RemoveBuildIgnore(content string) (string, error)

func RemoveMarker

func RemoveMarker(content string, marker string) (string, error)

func ReplaceContentAfter

func ReplaceContentAfter(content string, beginMark string, endMark string, seq []string, target string, replaceContent string) string

func UpdateContent

func UpdateContent(content string, beginMark string, endMark string, seq []string, i int, position UpdatePosition, addContent string) string

func UpdateContentLines

func UpdateContentLines(content string, beginMark string, endMark string, seq []string, i int, position UpdatePosition, addContent string) string

UpdateContentLines add content before or after the `i`'s anchor in `seq` two lines will be automatically added after `beginMark`, and before `endMark`, so you don't need to include a line in `addContent`

Types

type FilePath

type FilePath []string

func (FilePath) Append

func (c FilePath) Append(s ...string) FilePath

func (FilePath) JoinPrefix

func (c FilePath) JoinPrefix(s ...string) string

type PatchMarker

type PatchMarker struct {
	Begin string
	End   string
}

type UpdatePosition

type UpdatePosition int
const (
	UpdatePosition_After   UpdatePosition = 0
	UpdatePosition_Before  UpdatePosition = 1
	UpdatePosition_Replace UpdatePosition = 2
)

Jump to

Keyboard shortcuts

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