OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.19.4
/
src
/
go
/
printer
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
12/01/2022 06:13:56 PM
rwxr-xr-x
📄
comment.go
3.51 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
example_test.go
1.78 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
gobuild.go
4.59 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
nodes.go
51.57 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
performance_test.go
1.27 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
printer.go
40.69 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
printer_test.go
18.43 KB
12/01/2022 06:12:58 PM
rw-r--r--
📁
testdata
-
12/01/2022 06:13:56 PM
rwxr-xr-x
Editing: example_test.go
Close
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package printer_test import ( "bytes" "fmt" "go/ast" "go/parser" "go/printer" "go/token" "strings" "testing" ) // Dummy test function so that godoc does not use the entire file as example. func Test(*testing.T) {} func parseFunc(filename, functionname string) (fun *ast.FuncDecl, fset *token.FileSet) { fset = token.NewFileSet() if file, err := parser.ParseFile(fset, filename, nil, 0); err == nil { for _, d := range file.Decls { if f, ok := d.(*ast.FuncDecl); ok && f.Name.Name == functionname { fun = f return } } } panic("function not found") } func ExampleFprint() { // Parse source file and extract the AST without comments for // this function, with position information referring to the // file set fset. funcAST, fset := parseFunc("example_test.go", "ExampleFprint") // Print the function body into buffer buf. // The file set is provided to the printer so that it knows // about the original source formatting and can add additional // line breaks where they were present in the source. var buf bytes.Buffer printer.Fprint(&buf, fset, funcAST.Body) // Remove braces {} enclosing the function body, unindent, // and trim leading and trailing white space. s := buf.String() s = s[1 : len(s)-1] s = strings.TrimSpace(strings.ReplaceAll(s, "\n\t", "\n")) // Print the cleaned-up body text to stdout. fmt.Println(s) // output: // funcAST, fset := parseFunc("example_test.go", "ExampleFprint") // // var buf bytes.Buffer // printer.Fprint(&buf, fset, funcAST.Body) // // s := buf.String() // s = s[1 : len(s)-1] // s = strings.TrimSpace(strings.ReplaceAll(s, "\n\t", "\n")) // // fmt.Println(s) }