gosrcfmt

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AST added in v1.6.0

func AST(fset *token.FileSet, file *ast.File) ([]byte, error)

AST format of given AST

Example
package main

import (
	"go/parser"
	"go/token"
	"io/ioutil"
	"os"

	"github.com/sirkon/message"

	"github.com/sirkon/gosrcfmt"
)

func main() {
	fset := token.NewFileSet()
	data, err := ioutil.ReadFile("testdata/main.go")
	if err != nil {
		message.Fatal(err)
	}
	file, err := parser.ParseFile(fset, "testdata/main.go", data, parser.AllErrors|parser.ParseComments)
	if err != nil {
		message.Fatal(err)
	}
	output, err := gosrcfmt.AST(fset, file)
	if err != nil {
		message.Fatal(err)
	}
	_, _ = os.Stdout.Write(output)

}
Output:

// +build !windows

package pkg

func main() {
	if true {
	}
}

func ASTWrite added in v1.7.0

func ASTWrite(dest io.Writer, fset *token.FileSet, file *ast.File) error

ASTWrite writes AST output into dest

func Autogen added in v1.6.0

func Autogen(data []byte) ([]byte, error)

Autogen format for autogenerated code

func AutogenWrite added in v1.7.0

func AutogenWrite(dest io.Writer, data []byte) error

AutogenWrite writes Autogen output into dest

func Format

func Format(dest io.Writer, data []byte)

Format formats data from src as a go code with gofmt utility Deprecated

func FormatReader

func FormatReader(dest io.Writer, src io.Reader)

FormatReader formats data from src as a go code with gofmt utility Deprecated

func Source added in v1.6.0

func Source(src []byte, filename string) ([]byte, error)

Source parse, format and return given source code

func SourceWrite added in v1.7.0

func SourceWrite(dest io.Writer, src []byte, filename string) error

SourceWrite writes Source output into dest

Types

This section is empty.

Jump to

Keyboard shortcuts

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