astedit

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package astedit modifies Go source files while keeping their formatting and comments (it uses dave/dst). The maker uses it to add fields and methods to existing entities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File is a Go source file being edited.

func Open

func Open(path string) (*File, error)

Open parses the file at path.

func Parse

func Parse(path string, src []byte) (*File, error)

Parse parses src (path is used for error messages and Save).

func (*File) AddDecls

func (f *File) AddDecls(src string) error

AddDecls appends top level declarations given as Go source.

func (*File) AddField

func (f *File) AddField(structName, decl, comment string) error

AddField appends a field declaration (e.g. "title string `orm:\"length:200\"`") to the struct, optionally with a doc comment.

func (*File) AddImport

func (f *File) AddImport(path, name string)

AddImport adds an import (with optional name) if it is missing.

func (*File) HasField

func (f *File) HasField(structName, field string) bool

HasField reports whether the struct has a field (case-insensitive).

func (*File) HasMethod

func (f *File) HasMethod(typeName, name string) bool

HasMethod reports whether a method with name exists on the type.

func (*File) Package

func (f *File) Package() string

Package returns the package name.

func (*File) Save

func (f *File) Save() error

Save writes the file back.

func (*File) Source

func (f *File) Source() ([]byte, error)

Source renders the file (gofmt formatted, imports sorted).

func (*File) Struct

func (f *File) Struct(name string) *dst.StructType

Struct returns the struct type named name, or nil.

Jump to

Keyboard shortcuts

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