Standard library / go/token
go/token.FileSet.Write()
Serializes a file set through an encoding callback. The encoding format is chosen by the caller. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (s *FileSet) Write(encode func(any) error) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| encode | func(any) error | Callback that encodes file-set data. |
Return Value
error
Parsing or setting error; nil on success.
Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/gob" "fmt" "go/token")
func check(e error) { if e != nil { panic(e) }}
func main() { s := token.NewFileSet() f := s.AddFile("demo.go", -1, 5) f.SetLinesForContent([]byte("ab\ncd")) var b bytes.Buffer check(s.Write(gob.NewEncoder(&b).Encode)) fmt.Println(b.Len() > 0)}