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.3k Golang : convert string or integer to big.Int type
+55.3k Golang : Unmarshal JSON from http response
+18k Golang : Get all upper case or lower case characters from string example
+21.8k SSL : How to check if current certificate is sha1 or sha2
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+4.4k Golang : Valued expressions and functions example
+12.8k Golang : Convert int(year) to time.Time type
+18.8k Golang : Delete duplicate items from a slice/array
+18.5k Golang : Send email with attachment
+9.7k Golang : Detect number of active displays and the display's resolution
+8.1k Golang : HTTP Server Example