gregoryv / goindex

Tools to manipulate go source files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

then grab Boat related sections using a combination of grep and grab

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

type Boat struct {
        model string
}

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

About

Tools to manipulate go source files

License:MIT License


Languages

Language:Go 100.0%