Golang go/token.FileSet.AddFile function examples
package go/token
AddFile adds a new file with a given filename(1st parameter), base(2nd parameter) offset, and file size(3rd parameter) to the file set s and returns the file. Multiple files may have the same name. The base offset must not be smaller than the FileSet's Base(), and size must not be negative. As a special case, if a negative base is provided, the current value of the FileSet's Base() is used instead.
Adding the file will set the file set's Base() value to base + size + 1 as the minimum base value for the next file. The following relationship exists between a Pos value p for a given file offset offs:
int(p) = base + offs
with offs in the range [0, size] and thus p in the range [base, base+size]. For convenience, File.Pos may be used to create file-specific position values from a file offset.
Golang go/token.FileSet.AddFile function usage examples
Example 1:
if util.IsText(src) {
// only add the file to the file set (for the full text index)
file = x.fset.AddFile(filename, x.fset.Base(), len(src))
file.SetLinesForContent(src)
return
}
Example 2:
var src []byte
var s scanner.Scanner
fset := token.NewFileSet()
file := fset.AddFile("", fset.Base(), len(src))
Reference :
Advertisement
Something interesting
Tutorials
+16.5k Golang : File path independent of Operating System
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+39k Golang : How to iterate over a []string(array)
+7.5k Gogland : Single File versus Go Application Run Configurations
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+11.3k Golang : Post data with url.Values{}
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+7.2k Golang : Dealing with postal or zip code example
+21.6k Golang : GORM create record or insert new record into database example
+6.6k Golang : How to validate ISBN?