goindex

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 3 Imported by: 0

README

goindex - Package for indexing go files

This module provides tools to manipulate go source files by indexing and extracting sections of code. This is useful when you are dealing with large files and want to extract type related sections into a separate file.

Quick start

$ go install github.com/gregoryv/goindex/cmd/...@latest

Index contents of a go file

$ goindex complex.go
complex.go 0 18 package testdata
complex.go 18 31 import
complex.go 31 54 // Decoupled comment
complex.go 54 96 func NewBoat() *Boat
complex.go 96 132 type Boat struct
complex.go 132 282 func (me *Boat) Model() string
complex.go 282 369 func DoSomething(v interface{ X() }) (interface{ S() int }, error)
complex.go 369 392 // Decoupled comment

Grab Boat related sections

$ goindex complex.go | grep Boat | grab
func NewBoat() *Boat {
        return &Boat{}
}

type Boat struct {
        model string
}

// Func comment
func (me *Boat) Model() string {
        if me.model == "" {
                return fmt.Sprintf("%s", "unknown")
        }
        // Inline comment
        return me.model
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

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

func NewCursor

func NewCursor(s *scanner.Scanner) *Cursor

NewCursor returns a cursor for the given scanner. The scanner should not be used outside of the cursor.

func (*Cursor) At

func (c *Cursor) At(file *token.File) int

func (*Cursor) InsideBrace

func (c *Cursor) InsideBrace() bool

func (*Cursor) InsideParen

func (c *Cursor) InsideParen() bool

func (*Cursor) Lit

func (c *Cursor) Lit() string

func (*Cursor) Next

func (c *Cursor) Next() bool

Next returns true until token.EOF is found

func (*Cursor) Pos

func (c *Cursor) Pos() token.Pos

func (*Cursor) Token

func (c *Cursor) Token() token.Token

type Section

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

func Index

func Index(src []byte) []Section

Index parses the given go source into sections. A section can be - comment - import - type - func If a comment is coupled to e.g. a func it's included in that section.

func (*Section) From

func (me *Section) From() int

func (*Section) Grab

func (me *Section) Grab(src []byte) []byte

func (*Section) IsEmpty

func (me *Section) IsEmpty(src []byte) bool

func (*Section) String

func (me *Section) String() string

func (*Section) To

func (me *Section) To() int

Directories

Path Synopsis
cmd
goindex
Command goindex indexes a go source file into sections
Command goindex indexes a go source file into sections
grab
Command grab extracts sections from a file by byte range
Command grab extracts sections from a file by byte range

Jump to

Keyboard shortcuts

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