Documentation ¶
Overview ¶
Package builtin provides simple functions, types, constants and a package that can be used as globals in a Scriggo template.
For example, to use the Min and Max functions as global min and max functions
globals := native.Declarations{ "min": builtin.Min, "max": builtin.Max, } opts := &scriggo.BuildOptions{ Globals: globals, } template, err := scriggo.BuildTemplate(fsys, file, opts)
And to use them in a template
{{ min(x, y) }} {{ max(x, y) }}
Use the regexp function and the returned Regex value in this way
{% var re = regexp(`(scrig)go`) %} {{ re.Match("go") }} {{ re.Match("scriggo") }}
Use this Declarations value to use all the builtin of this package in a template or choose the most appropriate
native.Declarations{ // crypto "hmacSHA1": builtin.HmacSHA1, "hmacSHA256": builtin.HmacSHA256, "sha1": builtin.Sha1, "sha256": builtin.Sha256, // encoding "base64": builtin.Base64, "hex": builtin.Hex, "marshalJSON": builtin.MarshalJSON, "marshalJSONIndent": builtin.MarshalJSONIndent, "marshalYAML": builtin.MarshalYAML, "md5": builtin.Md5, "unmarshalJSON": builtin.UnmarshalJSON, "unmarshalYAML": builtin.UnmarshalYAML, // html "htmlEscape": builtin.HtmlEscape, // math "abs": builtin.Abs, "max": builtin.Max, "min": builtin.Min, "pow": builtin.Pow, // net "File": reflect.TypeOf((*builtin.File)(nil)).Elem(), "FormData": reflect.TypeOf(builtin.FormData{}), "form": (*builtin.FormData)(nil), "queryEscape": builtin.QueryEscape, // regexp "Regexp": reflect.TypeOf(builtin.Regexp{}), "regexp": builtin.RegExp, // sort "reverse": builtin.Reverse, "sort": builtin.Sort, // strconv "formatFloat": builtin.FormatFloat, "formatInt": builtin.FormatInt, "parseFloat": builtin.ParseFloat, "parseInt": builtin.ParseInt, // strings "abbreviate": builtin.Abbreviate, "capitalize": builtin.Capitalize, "capitalizeAll": builtin.CapitalizeAll, "hasPrefix": builtin.HasPrefix, "hasSuffix": builtin.HasSuffix, "index": builtin.Index, "indexAny": builtin.IndexAny, "join": builtin.Join, "lastIndex": builtin.LastIndex, "replace": builtin.Replace, "replaceAll": builtin.ReplaceAll, "runeCount": builtin.RuneCount, "split": builtin.Split, "splitAfter": builtin.SplitAfter, "splitAfterN": builtin.SplitAfterN, "splitN": builtin.SplitN, "sprint": builtin.Sprint, "sprintf": builtin.Sprintf, "toKebab": builtin.ToKebab, "toLower": builtin.ToLower, "toUpper": builtin.ToUpper, "trim": builtin.Trim, "trimLeft": builtin.TrimLeft, "trimPrefix": builtin.TrimPrefix, "trimRight": builtin.TrimRight, "trimSuffix": builtin.TrimSuffix, // time "Duration": reflect.TypeOf(builtin.Duration(0)), "Hour": time.Hour, "Microsecond": time.Microsecond, "Millisecond": time.Millisecond, "Minute": time.Minute, "Nanosecond": time.Nanosecond, "Second": time.Second, "Time": reflect.TypeOf(builtin.Time{}), "date": builtin.Date, "now": builtin.Now, "parseDuration": builtin.ParseDuration, "parseTime": builtin.ParseTime, "unixTime": builtin.UnixTime, // unsafeconv, uncomment the declaration below to allow to use unsafe conversions between string and native types // "unsafeconv": builtin.Unsafeconv, }
To initialize the form builtin value, with data read from the request r, use this map as vars argument to Run
map[string]interface{}{"form": builtin.NewFormData(r, 10)}
Index ¶
- Variables
- func Abbreviate(s string, n int) string
- func Abs(x int) int
- func Base64(s string) string
- func Capitalize(s string) string
- func CapitalizeAll(s string) string
- func FormatFloat(f float64, format string, precision int) string
- func FormatInt(i int, base int) string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Hex(s string) string
- func HmacSHA1(message, key string) string
- func HmacSHA256(message, key string) string
- func HtmlEscape(s string) native.HTML
- func Index(s, substr string) int
- func IndexAny(s, chars string) int
- func Join(elems []string, sep string) string
- func LastIndex(s, substr string) int
- func MarshalJSON(v interface{}) (native.JSON, error)
- func MarshalJSONIndent(v interface{}, prefix, indent string) (native.JSON, error)
- func MarshalYAML(v interface{}) (_ string, err error)
- func Max(x, y int) int
- func Md5(s string) string
- func Min(x, y int) int
- func ParseFloat(s string) (float64, error)
- func ParseInt(s string, base int) (int, error)
- func Pow(x, y float64) float64
- func QueryEscape(s string) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func Reverse(slice interface{})
- func RuneCount(s string) (n int)
- func Sha1(s string) string
- func Sha256(s string) string
- func Sort(slice interface{}, less func(i, j int) bool)
- func Split(s, sep string) []string
- func SplitAfter(s, sep string) []string
- func SplitAfterN(s, sep string, n int) []string
- func SplitN(s, sep string, n int) []string
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func ToKebab(s string) string
- func ToLower(s string) string
- func ToUpper(s string) string
- func Trim(s, cutset string) string
- func TrimLeft(s, cutset string) string
- func TrimPrefix(s, prefix string) string
- func TrimRight(s, cutset string) string
- func TrimSuffix(s, suffix string) string
- func UnmarshalJSON(data string, v interface{}) error
- func UnmarshalYAML(data string, v interface{}) (err error)
- type Duration
- type File
- type FormData
- type Opener
- type Regexp
- func (re Regexp) Find(s string) string
- func (re Regexp) FindAll(s string, n int) []string
- func (re Regexp) FindAllSubmatch(s string, n int) [][]string
- func (re Regexp) FindSubmatch(s string) []string
- func (re Regexp) Match(s string) bool
- func (re Regexp) ReplaceAll(s, repl string) string
- func (re Regexp) ReplaceAllFunc(s string, repl func(string) string) string
- func (re Regexp) Split(s string, n int) []string
- type Time
- func (t Time) Add(d Duration) Time
- func (t Time) AddDate(years, months, days int) Time
- func (t Time) After(u Time) bool
- func (t Time) Before(u Time) bool
- func (t Time) Clock() (hour, minute, second int)
- func (t Time) Date() (year, month, day int)
- func (t Time) Day() int
- func (t Time) Equal(u Time) bool
- func (t Time) Format(layout string) string
- func (t Time) Hour() int
- func (t Time) IsZero() bool
- func (t Time) JS() native.JS
- func (t Time) JSON() native.JSON
- func (t Time) Minute() int
- func (t Time) Month() int
- func (t Time) Nanosecond() int
- func (t Time) Round(d Duration) Time
- func (t Time) Second() int
- func (t Time) String() string
- func (t Time) Sub(u Time) Duration
- func (t Time) Truncate(d Duration) Time
- func (t Time) UTC() Time
- func (t Time) Unix() int64
- func (t Time) UnixNano() int64
- func (t Time) Weekday() int
- func (t Time) Year() int
- func (t Time) YearDay() int
Constants ¶
This section is empty.
Variables ¶
var ErrBadRequest = errors.New("form: bad request")
ErrBadRequest is the error that occurs when parsing a malformed HTTP request body or query string in FormData methods.
var ErrRequestEntityTooLarge = errors.New("form: request entity too large")
ErrRequestEntityTooLarge is the error that occurs when the HTTP request's body is too large
var Unsafeconv = native.Package{ Name: "unsafeconv", Declarations: map[string]native.Declaration{ "ToHTML": func(s string) native.HTML { return native.HTML(s) }, "ToCSS": func(s string) native.CSS { return native.CSS(s) }, "ToJS": func(s string) native.JS { return native.JS(s) }, "ToJSON": func(s string) native.JSON { return native.JSON(s) }, "ToMarkdown": func(s string) native.Markdown { return native.Markdown(s) }, }, }
Unsafeconv provides a package that implements functions to make unsafe conversions between string values and native types.
Functions ¶
func Abbreviate ¶
Abbreviate abbreviates s to almost n runes. If s is longer than n runes, the abbreviated string terminates with "...".
func Abs ¶
Abs returns the absolute value of x. As a special case, if x is the smallest negative integer, Abs returns x.
func Capitalize ¶
Capitalize returns a copy of the string s with the first non-separator in upper case.
func CapitalizeAll ¶
CapitalizeAll returns a copy of the string s with the first letter of each word in upper case.
func FormatFloat ¶
FormatFloat converts the floating-point number f to a string, according to the given format and precision. It can round the result.
The format is one of "e", "f" or "g"
"e": -d.dddde±dd, a decimal exponent "f": -ddd.dddd, no exponent "g": "e" for large exponents, "f" otherwise
The precision, for -1 <= precision <= 1000, controls the number of digits (excluding the exponent). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly. For "e" and "f" it is the number of digits after the decimal point. For "g" it is the maximum number of significant digits (trailing zeros are removed).
If the format or the precision is not valid, FormatFloat panics.
func FormatInt ¶
FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.
It panics if base is not in the range.
func HmacSHA1 ¶
HmacSHA1 returns the HMAC-SHA1 tag for the given message and key, as a base64 encoded string.
func HmacSHA256 ¶
HmacSHA256 returns the HMAC-SHA256 tag for the given message and key, as a base64 encoded string.
func HtmlEscape ¶
HtmlEscape escapes s, replacing the characters <, >, &, " and ' and returns the escaped string as native.HTML type.
func Index ¶
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
The returned index refers to the bytes and not the runes of s.
func IndexAny ¶
IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
The returned index refers to the bytes and not the runes of s.
func Join ¶
Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.
func LastIndex ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
The returned index refers to the bytes and not the runes of s.
func MarshalJSON ¶
MarshalJSON returns the JSON encoding of v.
See https://pkg.go.dev/encoding/json#Marshal for details.
func MarshalJSONIndent ¶
MarshalJSONIndent is like MarshalJSON but indents the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting. prefix and indent can only contain whitespace: ' ', '\t', '\n' and '\r'.
func MarshalYAML ¶ added in v0.55.0
MarshalYAML returns the YAML encoding of v.
See https://pkg.go.dev/gopkg.in/yaml.v3#Marshal for details.
func ParseFloat ¶
ParseFloat converts the string s to a float64 value.
If s is well-formed and near a valid floating-point number, ParseFloat returns the nearest floating-point number rounded using IEEE754 unbiased rounding.
func ParseInt ¶
ParseInt interprets a string s in the given base, for 2 <= base <= 36, and returns the corresponding value. It returns 0 and an error if s is empty, contains invalid digits or the value corresponding to s cannot be represented by an int value.
func Pow ¶ added in v0.50.0
Pow returns x**y. See https://pkg.go.dev/math#Pow.
func QueryEscape ¶
QueryEscape escapes the string, so it can be safely placed inside a URL query.
func Replace ¶
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If n < 0, there is no limit on the number of replacements.
func ReplaceAll ¶
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new.
func Reverse ¶
func Reverse(slice interface{})
Reverse reverses the order of the elements of slice. If slice is not a slice, it panics.
func RuneCount ¶
RuneCount returns the number of runes in s. Erroneous and short encodings are treated as single runes of width 1 byte.
func Sort ¶
Sort the elements of slice given the provided less function. If slice is not a slice, it panics.
The less function reports whether slice[i] should be ordered before slice[j]. If less is nil, the elements are sorted in a natural order based on their type.
The natural order can differ between different versions of Scriggo.
func Split ¶
Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.
If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s. If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.
It is equivalent to SplitN with a count of -1.
func SplitAfter ¶
SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.
If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s. If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and sep are empty, SplitAfter returns an empty slice.
It is equivalent to SplitAfterN with a count of -1.
func SplitAfterN ¶
SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.
func SplitN ¶
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.
func Sprint ¶
func Sprint(a ...interface{}) string
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
func Trim ¶
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func TrimLeft ¶
TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func TrimRight ¶
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func TrimSuffix ¶
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
func UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the result in a new value pointed to by v. If v is nil or not a pointer, UnmarshalJSON returns an error.
Unlike json.Unmarshal of the Go standard library, UnmarshalJSON does not change the value pointed to by v but instantiates a new value and then replaces the value pointed to by v, if no errors occur.
See https://pkg.go.dev/encoding/json#Unmarshal for details.
func UnmarshalYAML ¶ added in v0.55.0
UnmarshalYAML parses the YAML-encoded data and stores the result in a new value pointed to by v. If v is nil or not a pointer, UnmarshalYAML returns an error.
Unlike yaml.Unmarshal of the yaml package, UnmarshalYAML does not accept a map value, use a pointer to a map value instead. UnmarshalYAM does not change the value pointed to by v but instantiates a new value and then replaces the value pointed to by v, if no errors occur.
See https://pkg.go.dev/gopkg.in/yaml.v3#Unmarshal for details.
Types ¶
type Duration ¶
A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
type File ¶
type File interface { Name() string // name. Type() string // type, as mime type. Size() int // size, in bytes. }
File represents a file. Files that can be opened also implement Opener.
type FormData ¶
type FormData struct {
// contains filtered or unexported fields
}
FormData contains the form data from the query string and body of an HTTP request. Values and files passed as multipart/form-data are only available after ParseMultipart method is called.
func NewFormData ¶
NewFormData returns a new FormData value. maxMemory is passed as is to the r.ParseMultipartForm method.
func (FormData) File ¶
File returns the first file associated with the given field. It returns nil if there are no values associated with the field.
Call File only after ParseMultipart is called.
func (FormData) Files ¶
Files returns the parsed files of a multipart form. It returns a non nil map, if ParseMultipart has been called.
Call Files only after ParseMultipart is called.
func (FormData) ParseMultipart ¶
func (form FormData) ParseMultipart()
ParseMultipart parses a request body as multipart/form-data. If the body is not multipart/form-data, it does nothing. It should be called before calling the File and Files methods and can be called multiple times.
It panics with ErrBadRequest if the request is not valid, ErrRequestEntityTooLarge if the length of the body is too large or another error if another error occurs.
func (FormData) Value ¶
Value returns the first form data value associated with the given field. If there are no files associated with the field, it returns an empty string.
It panics with ErrBadRequest if the request is not valid, ErrRequestEntityTooLarge if the length of the body is too large or another error if another error occurs.
type Opener ¶
type Opener interface { // Open opens the file. Open() (io.ReadSeekCloser, error) }
Opener is implemented by a File that can be opened. Opener is not intended to be used as a builtin type but it can be used by builtins to open a file.
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp represents a regular expression.
func RegExp ¶
RegExp parses a regular expression and returns a Regexp value that can be used to match against text. It panics if the expression cannot be parsed.
For the syntax of regular expressions see https://pkg.go.dev/regexp/syntax.
func (Regexp) Find ¶
Find returns a string holding the text of the leftmost match in s of the regular expression. If there is no match, the return value is an empty string, but it will also be empty if the regular expression successfully matches an empty string. Use FindSubmatch if it is necessary to distinguish these cases.
func (Regexp) FindAll ¶
FindAll is the 'All' version of Find; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the Go regexp package comment. A return value of nil indicates no match.
func (Regexp) FindAllSubmatch ¶
FindAllSubmatch is the 'All' version of FindSubmatch; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the Go regexp package comment. A return value of nil indicates no match.
func (Regexp) FindSubmatch ¶
FindSubmatch returns a slice of strings holding the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions, as defined by the 'Submatch' description in the Go regexp package comment. A return value of nil indicates no match.
func (Regexp) Match ¶
Match reports whether the string s contains any match of the regular expression.
func (Regexp) ReplaceAll ¶
ReplaceAll returns a copy of s, replacing matches of the Regexp with the replacement string repl. Inside repl, $ signs are interpreted as in Expand method of the Go regexp package, so for instance $1 represents the text of the first submatch.
func (Regexp) ReplaceAllFunc ¶
ReplaceAllFunc returns a copy of s in which all matches of the Regexp have been replaced by the return value of function repl applied to the matched substring. The replacement returned by repl is substituted directly, without expanding.
func (Regexp) Split ¶
Split slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches.
The slice returned by this method consists of all the substrings of s not contained in the slice returned by FindAllString. When called on an expression that contains no metacharacters, it is equivalent to SplitN.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
A Time represents an instant in time.
It is a stripped down version of the Go time.Time type, with additional methods to show time values in JavaScript and JSON contexts.
func Date ¶
Date returns the time corresponding to the given date with time zone determined by location. If location does not exist, it returns an error.
For example, the following call returns March 27, 2021 11:21:14.964553705 CET.
Date(2021, 3, 27, 11, 21, 14, 964553705, "Europe/Rome")
For UTC use "" or "UTC" as location. For the system's local time zone use "Local" as location.
The month, day, hour, min, sec and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1.
func NewTime ¶
NewTime returns a Time value at the time of t. It is not intended to be used as a builtin but it can be used to implement builtins that return time values.
For example, a builtin that returns the current local time rounded to milliseconds and with location "America/New_York" can be implemented as
func now() builtin.Time { l := time.LoadLocation("America/New_York") t := time.Now().Rounded(time.Millisecond).In(l) return builtin.NewTime(t) }
and once added to the declarations
native.Declarations{ ... "now" : now, ... }
it can be used in a template
Current time: {{ now() }}
func ParseTime ¶
ParseTime parses a formatted string and returns the time value it represents. The layout defines the format by showing how the reference time
Mon Jan 2 15:04:05 -0700 MST 2006
would be interpreted if it were the value; it serves as an example of the input format. The same interpretation will then be made to the input string.
See https://pkg.go.dev/time#Parse for more details.
As a special case, if layout is an empty string, ParseTime parses a time representation using a predefined list of layouts.
It returns an error if value cannot be parsed.
func UnixTime ¶
UnixTime returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).
func (Time) AddDate ¶
AddDate returns the time corresponding to adding the given number of years, months and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.
AddDate normalizes its result in the same way that the Date function does.
func (Time) Clock ¶
Clock returns the hour, minute and second within the day specified by t. hour is in the range [0, 23], minute and second are in the range [0, 59].
func (Time) Date ¶
Date returns the year, month and day in which t occurs. month is in the range [1, 12] and day is in the range [1, 31].
func (Time) Format ¶
Format returns a textual representation of the time value formatted according to layout, which defines the format by showing how the reference time
Mon Jan 2 15:04:05 -0700 MST 2006
would be displayed if it were the value; it serves as an example of the desired output. The same display rules will then be applied to the time value.
A fractional second is represented by adding a period and zeros to the end of the seconds section of layout string, as in "15:04:05.000" to format a time stamp with millisecond precision.
func (Time) IsZero ¶
IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
func (Time) JS ¶
JS returns the time as a JavaScript date. The result is undefined if the year of t is not in the range [-999999, 999999].
func (Time) Minute ¶
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
func (Time) Month ¶
Month returns the month of the year specified by t, in the range [1, 12] where 1 is January and 12 is December.
func (Time) Nanosecond ¶
Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].
func (Time) Round ¶
Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Time) Second ¶
Second returns the second offset within the minute specified by t, in the range [0, 59].
func (Time) Sub ¶
Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).
func (Time) Truncate ¶
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Time) Unix ¶
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t. Unix-like operating systems often record time as a 32-bit count of seconds, but since the method here returns a 64-bit value it is valid for billions of years into the past or future.
func (Time) UnixNano ¶
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined. The result does not depend on the location associated with t.