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: 5 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址