gocodeutil

package
v0.0.0-...-9c8aaae Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtImports

func FmtImports(pkgs map[string]string) string

func FormatGoFileFromString

func FormatGoFileFromString(s string) (string, error)
Example (RemoveUnusedImports)
package main

import (
	"fmt"

	"github.com/hori-ryota/go-codegen/util/gocodeutil"
)

func main() {
	src := `package example

import (
    "usedA"
    used "usedB"
    "unusedA"
    unused "unusedB"
)

func foo() {
    usedA.Bar()
    used.Baz()
}`

	dst, err := gocodeutil.FormatGoFileFromString(src)
	if err != nil {
		panic(err)
	}
	fmt.Print(dst)
}
Output:

package example

import (
	"usedA"
	used "usedB"
)

func foo() {
	usedA.Bar()
	used.Baz()
}

func LocalPathToGoPackagePath

func LocalPathToGoPackagePath(s string) (string, error)

func RemoveUnusedImports

func RemoveUnusedImports(fset *token.FileSet, file *ast.File)

Types

This section is empty.

Jump to

Keyboard shortcuts

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