id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
29,700
twpayne/go-geom
xy/line_centroid.go
AddLinearRing
func (calc *LineCentroidCalculator) AddLinearRing(line *geom.LinearRing) *LineCentroidCalculator { coords := line.FlatCoords() calc.addLine(coords, 0, len(coords)) return calc }
go
func (calc *LineCentroidCalculator) AddLinearRing(line *geom.LinearRing) *LineCentroidCalculator { coords := line.FlatCoords() calc.addLine(coords, 0, len(coords)) return calc }
[ "func", "(", "calc", "*", "LineCentroidCalculator", ")", "AddLinearRing", "(", "line", "*", "geom", ".", "LinearRing", ")", "*", "LineCentroidCalculator", "{", "coords", ":=", "line", ".", "FlatCoords", "(", ")", "\n", "calc", ".", "addLine", "(", "coords", ...
// AddLinearRing adds a LinearRing to the current calculation
[ "AddLinearRing", "adds", "a", "LinearRing", "to", "the", "current", "calculation" ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/line_centroid.go#L97-L101
29,701
twpayne/go-geom
xy/cga.go
IsOnLine
func IsOnLine(layout geom.Layout, point geom.Coord, lineSegmentCoordinates []float64) bool { stride := layout.Stride() if len(lineSegmentCoordinates) < (2 * stride) { panic(fmt.Sprintf("At least two coordinates are required in the lineSegmentsCoordinates array in 'algorithms.IsOnLine', was: %v", lineSegmentCoordina...
go
func IsOnLine(layout geom.Layout, point geom.Coord, lineSegmentCoordinates []float64) bool { stride := layout.Stride() if len(lineSegmentCoordinates) < (2 * stride) { panic(fmt.Sprintf("At least two coordinates are required in the lineSegmentsCoordinates array in 'algorithms.IsOnLine', was: %v", lineSegmentCoordina...
[ "func", "IsOnLine", "(", "layout", "geom", ".", "Layout", ",", "point", "geom", ".", "Coord", ",", "lineSegmentCoordinates", "[", "]", "float64", ")", "bool", "{", "stride", ":=", "layout", ".", "Stride", "(", ")", "\n", "if", "len", "(", "lineSegmentCoo...
// IsOnLine tests whether a point lies on the line segments defined by a list of // coordinates. // // Returns true if the point is a vertex of the line or lies in the interior // of a line segment in the linestring
[ "IsOnLine", "tests", "whether", "a", "point", "lies", "on", "the", "line", "segments", "defined", "by", "a", "list", "of", "coordinates", ".", "Returns", "true", "if", "the", "point", "is", "a", "vertex", "of", "the", "line", "or", "lies", "in", "the", ...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L63-L79
29,702
twpayne/go-geom
xy/cga.go
DistanceFromPointToLineString
func DistanceFromPointToLineString(layout geom.Layout, p geom.Coord, line []float64) float64 { if len(line) < 2 { panic(fmt.Sprintf("Line array must contain at least one vertex: %v", line)) } // this handles the case of length = 1 firstPoint := line[0:2] minDistance := internal.Distance2D(p, firstPoint) stride ...
go
func DistanceFromPointToLineString(layout geom.Layout, p geom.Coord, line []float64) float64 { if len(line) < 2 { panic(fmt.Sprintf("Line array must contain at least one vertex: %v", line)) } // this handles the case of length = 1 firstPoint := line[0:2] minDistance := internal.Distance2D(p, firstPoint) stride ...
[ "func", "DistanceFromPointToLineString", "(", "layout", "geom", ".", "Layout", ",", "p", "geom", ".", "Coord", ",", "line", "[", "]", "float64", ")", "float64", "{", "if", "len", "(", "line", ")", "<", "2", "{", "panic", "(", "fmt", ".", "Sprintf", "...
// DistanceFromPointToLineString computes the distance from a point to a sequence of line segments. // // Param p - a point // Param line - a sequence of contiguous line segments defined by their vertices
[ "DistanceFromPointToLineString", "computes", "the", "distance", "from", "a", "point", "to", "a", "sequence", "of", "line", "segments", ".", "Param", "p", "-", "a", "point", "Param", "line", "-", "a", "sequence", "of", "contiguous", "line", "segments", "defined...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L231-L248
29,703
twpayne/go-geom
xy/cga.go
SignedArea
func SignedArea(layout geom.Layout, ring []float64) float64 { stride := layout.Stride() if len(ring) < 3*stride { return 0.0 } sum := 0.0 // Based on the Shoelace formula. // http://en.wikipedia.org/wiki/Shoelace_formula x0 := ring[0] lenMinusOnePoint := len(ring) - stride for i := stride; i < lenMinusOnePoi...
go
func SignedArea(layout geom.Layout, ring []float64) float64 { stride := layout.Stride() if len(ring) < 3*stride { return 0.0 } sum := 0.0 // Based on the Shoelace formula. // http://en.wikipedia.org/wiki/Shoelace_formula x0 := ring[0] lenMinusOnePoint := len(ring) - stride for i := stride; i < lenMinusOnePoi...
[ "func", "SignedArea", "(", "layout", "geom", ".", "Layout", ",", "ring", "[", "]", "float64", ")", "float64", "{", "stride", ":=", "layout", ".", "Stride", "(", ")", "\n", "if", "len", "(", "ring", ")", "<", "3", "*", "stride", "{", "return", "0.0"...
// SignedArea computes the signed area for a ring. The signed area is positive if the // ring is oriented CW, negative if the ring is oriented CCW, and zero if the // ring is degenerate or flat.
[ "SignedArea", "computes", "the", "signed", "area", "for", "a", "ring", ".", "The", "signed", "area", "is", "positive", "if", "the", "ring", "is", "oriented", "CW", "negative", "if", "the", "ring", "is", "oriented", "CCW", "and", "zero", "if", "the", "rin...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L328-L345
29,704
twpayne/go-geom
xy/cga.go
Distance
func Distance(c1, c2 geom.Coord) float64 { return internal.Distance2D(c1, c2) }
go
func Distance(c1, c2 geom.Coord) float64 { return internal.Distance2D(c1, c2) }
[ "func", "Distance", "(", "c1", ",", "c2", "geom", ".", "Coord", ")", "float64", "{", "return", "internal", ".", "Distance2D", "(", "c1", ",", "c2", ")", "\n", "}" ]
// Distance calculates the 2d distance between the two coordinates
[ "Distance", "calculates", "the", "2d", "distance", "between", "the", "two", "coordinates" ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L369-L371
29,705
twpayne/go-geom
xy/convex_hull.go
ConvexHull
func ConvexHull(geometry geom.T) geom.T { // copy coords because the algorithm reorders them calc := convexHullCalculator{ layout: geometry.Layout(), stride: geometry.Layout().Stride(), inputPts: geometry.FlatCoords(), } return calc.getConvexHull() }
go
func ConvexHull(geometry geom.T) geom.T { // copy coords because the algorithm reorders them calc := convexHullCalculator{ layout: geometry.Layout(), stride: geometry.Layout().Stride(), inputPts: geometry.FlatCoords(), } return calc.getConvexHull() }
[ "func", "ConvexHull", "(", "geometry", "geom", ".", "T", ")", "geom", ".", "T", "{", "// copy coords because the algorithm reorders them", "calc", ":=", "convexHullCalculator", "{", "layout", ":", "geometry", ".", "Layout", "(", ")", ",", "stride", ":", "geometr...
// ConvexHull computes the convex hull of the geometry. // A convex hull is the smallest convex geometry that contains // all the points in the input geometry // Uses the Graham Scan algorithm
[ "ConvexHull", "computes", "the", "convex", "hull", "of", "the", "geometry", ".", "A", "convex", "hull", "is", "the", "smallest", "convex", "geometry", "that", "contains", "all", "the", "points", "in", "the", "input", "geometry", "Uses", "the", "Graham", "Sca...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/convex_hull.go#L24-L33
29,706
twpayne/go-geom
xy/convex_hull.go
ConvexHullFlat
func ConvexHullFlat(layout geom.Layout, coords []float64) geom.T { calc := convexHullCalculator{ inputPts: coords, layout: layout, stride: layout.Stride(), } return calc.getConvexHull() }
go
func ConvexHullFlat(layout geom.Layout, coords []float64) geom.T { calc := convexHullCalculator{ inputPts: coords, layout: layout, stride: layout.Stride(), } return calc.getConvexHull() }
[ "func", "ConvexHullFlat", "(", "layout", "geom", ".", "Layout", ",", "coords", "[", "]", "float64", ")", "geom", ".", "T", "{", "calc", ":=", "convexHullCalculator", "{", "inputPts", ":", "coords", ",", "layout", ":", "layout", ",", "stride", ":", "layou...
// ConvexHullFlat computes the convex hull of the geometry. // A convex hull is the smallest convex geometry that contains // all the points in the input coordinates // Uses the Graham Scan algorithm
[ "ConvexHullFlat", "computes", "the", "convex", "hull", "of", "the", "geometry", ".", "A", "convex", "hull", "is", "the", "smallest", "convex", "geometry", "that", "contains", "all", "the", "points", "in", "the", "input", "coordinates", "Uses", "the", "Graham",...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/convex_hull.go#L39-L46
29,707
twpayne/go-geom
flat.go
Bounds
func (g *geom0) Bounds() *Bounds { return NewBounds(g.layout).extendFlatCoords(g.flatCoords, 0, len(g.flatCoords), g.stride) }
go
func (g *geom0) Bounds() *Bounds { return NewBounds(g.layout).extendFlatCoords(g.flatCoords, 0, len(g.flatCoords), g.stride) }
[ "func", "(", "g", "*", "geom0", ")", "Bounds", "(", ")", "*", "Bounds", "{", "return", "NewBounds", "(", "g", ".", "layout", ")", ".", "extendFlatCoords", "(", "g", ".", "flatCoords", ",", "0", ",", "len", "(", "g", ".", "flatCoords", ")", ",", "...
// Bounds returns the bounds of g.
[ "Bounds", "returns", "the", "bounds", "of", "g", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L27-L29
29,708
twpayne/go-geom
flat.go
Coords
func (g *geom0) Coords() Coord { return inflate0(g.flatCoords, 0, len(g.flatCoords), g.stride) }
go
func (g *geom0) Coords() Coord { return inflate0(g.flatCoords, 0, len(g.flatCoords), g.stride) }
[ "func", "(", "g", "*", "geom0", ")", "Coords", "(", ")", "Coord", "{", "return", "inflate0", "(", "g", ".", "flatCoords", ",", "0", ",", "len", "(", "g", ".", "flatCoords", ")", ",", "g", ".", "stride", ")", "\n", "}" ]
// Coords returns all the coordinates in g, i.e. a single coordinate.
[ "Coords", "returns", "all", "the", "coordinates", "in", "g", "i", ".", "e", ".", "a", "single", "coordinate", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L32-L34
29,709
twpayne/go-geom
flat.go
Reserve
func (g *geom0) Reserve(n int) { if cap(g.flatCoords) < n*g.stride { fcs := make([]float64, len(g.flatCoords), n*g.stride) copy(fcs, g.flatCoords) g.flatCoords = fcs } }
go
func (g *geom0) Reserve(n int) { if cap(g.flatCoords) < n*g.stride { fcs := make([]float64, len(g.flatCoords), n*g.stride) copy(fcs, g.flatCoords) g.flatCoords = fcs } }
[ "func", "(", "g", "*", "geom0", ")", "Reserve", "(", "n", "int", ")", "{", "if", "cap", "(", "g", ".", "flatCoords", ")", "<", "n", "*", "g", ".", "stride", "{", "fcs", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "g", ".", "fla...
// Reserve reserves space in g for n coordinates.
[ "Reserve", "reserves", "space", "in", "g", "for", "n", "coordinates", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L63-L69
29,710
twpayne/go-geom
flat.go
Coord
func (g *geom1) Coord(i int) Coord { return g.flatCoords[i*g.stride : (i+1)*g.stride] }
go
func (g *geom1) Coord(i int) Coord { return g.flatCoords[i*g.stride : (i+1)*g.stride] }
[ "func", "(", "g", "*", "geom1", ")", "Coord", "(", "i", "int", ")", "Coord", "{", "return", "g", ".", "flatCoords", "[", "i", "*", "g", ".", "stride", ":", "(", "i", "+", "1", ")", "*", "g", ".", "stride", "]", "\n", "}" ]
// Coord returns the ith coord of g.
[ "Coord", "returns", "the", "ith", "coord", "of", "g", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L104-L106
29,711
twpayne/go-geom
flat.go
Coords
func (g *geom1) Coords() []Coord { return inflate1(g.flatCoords, 0, len(g.flatCoords), g.stride) }
go
func (g *geom1) Coords() []Coord { return inflate1(g.flatCoords, 0, len(g.flatCoords), g.stride) }
[ "func", "(", "g", "*", "geom1", ")", "Coords", "(", ")", "[", "]", "Coord", "{", "return", "inflate1", "(", "g", ".", "flatCoords", ",", "0", ",", "len", "(", "g", ".", "flatCoords", ")", ",", "g", ".", "stride", ")", "\n", "}" ]
// Coords unpacks and returns all of g's coordinates.
[ "Coords", "unpacks", "and", "returns", "all", "of", "g", "s", "coordinates", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L109-L111
29,712
twpayne/go-geom
flat.go
Coords
func (g *geom2) Coords() [][]Coord { return inflate2(g.flatCoords, 0, g.ends, g.stride) }
go
func (g *geom2) Coords() [][]Coord { return inflate2(g.flatCoords, 0, g.ends, g.stride) }
[ "func", "(", "g", "*", "geom2", ")", "Coords", "(", ")", "[", "]", "[", "]", "Coord", "{", "return", "inflate2", "(", "g", ".", "flatCoords", ",", "0", ",", "g", ".", "ends", ",", "g", ".", "stride", ")", "\n", "}" ]
// Coords returns all of g's coordinates.
[ "Coords", "returns", "all", "of", "g", "s", "coordinates", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L141-L143
29,713
twpayne/go-geom
flat.go
Coords
func (g *geom3) Coords() [][][]Coord { return inflate3(g.flatCoords, 0, g.endss, g.stride) }
go
func (g *geom3) Coords() [][][]Coord { return inflate3(g.flatCoords, 0, g.endss, g.stride) }
[ "func", "(", "g", "*", "geom3", ")", "Coords", "(", ")", "[", "]", "[", "]", "[", "]", "Coord", "{", "return", "inflate3", "(", "g", ".", "flatCoords", ",", "0", ",", "g", ".", "endss", ",", "g", ".", "stride", ")", "\n", "}" ]
// Coords returns all the coordinates in g.
[ "Coords", "returns", "all", "the", "coordinates", "in", "g", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L189-L191
29,714
twpayne/go-geom
xyz/vector.go
VectorDot
func VectorDot(v1Start, v1End, v2Start, v2End geom.Coord) float64 { v1Startv2Endx := v1End[0] - v1Start[0] v1Startv2Endy := v1End[1] - v1Start[1] v1Startv2Endz := v1End[2] - v1Start[2] v2Startv2Endx := v2End[0] - v2Start[0] v2Startv2Endy := v2End[1] - v2Start[1] v2Startv2Endz := v2End[2] - v2Start[2] return v1St...
go
func VectorDot(v1Start, v1End, v2Start, v2End geom.Coord) float64 { v1Startv2Endx := v1End[0] - v1Start[0] v1Startv2Endy := v1End[1] - v1Start[1] v1Startv2Endz := v1End[2] - v1Start[2] v2Startv2Endx := v2End[0] - v2Start[0] v2Startv2Endy := v2End[1] - v2Start[1] v2Startv2Endz := v2End[2] - v2Start[2] return v1St...
[ "func", "VectorDot", "(", "v1Start", ",", "v1End", ",", "v2Start", ",", "v2End", "geom", ".", "Coord", ")", "float64", "{", "v1Startv2Endx", ":=", "v1End", "[", "0", "]", "-", "v1Start", "[", "0", "]", "\n", "v1Startv2Endy", ":=", "v1End", "[", "1", ...
// VectorDot calculates the dot product of two vectors
[ "VectorDot", "calculates", "the", "dot", "product", "of", "two", "vectors" ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L10-L18
29,715
twpayne/go-geom
xyz/vector.go
VectorNormalize
func VectorNormalize(vector geom.Coord) geom.Coord { vLen := VectorLength(vector) return geom.Coord{vector[0] / vLen, vector[1] / vLen, vector[2] / vLen} }
go
func VectorNormalize(vector geom.Coord) geom.Coord { vLen := VectorLength(vector) return geom.Coord{vector[0] / vLen, vector[1] / vLen, vector[2] / vLen} }
[ "func", "VectorNormalize", "(", "vector", "geom", ".", "Coord", ")", "geom", ".", "Coord", "{", "vLen", ":=", "VectorLength", "(", "vector", ")", "\n", "return", "geom", ".", "Coord", "{", "vector", "[", "0", "]", "/", "vLen", ",", "vector", "[", "1"...
// VectorNormalize creates a coordinate that is the normalized vector from 0,0,0 to vector
[ "VectorNormalize", "creates", "a", "coordinate", "that", "is", "the", "normalized", "vector", "from", "0", "0", "0", "to", "vector" ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L21-L24
29,716
twpayne/go-geom
xyz/vector.go
VectorLength
func VectorLength(vector geom.Coord) float64 { return math.Sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]) }
go
func VectorLength(vector geom.Coord) float64 { return math.Sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]) }
[ "func", "VectorLength", "(", "vector", "geom", ".", "Coord", ")", "float64", "{", "return", "math", ".", "Sqrt", "(", "vector", "[", "0", "]", "*", "vector", "[", "0", "]", "+", "vector", "[", "1", "]", "*", "vector", "[", "1", "]", "+", "vector"...
// VectorLength calculates the length of the vector from 0,0,0 to vector
[ "VectorLength", "calculates", "the", "length", "of", "the", "vector", "from", "0", "0", "0", "to", "vector" ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L27-L29
29,717
twpayne/go-geom
encoding/kml/kml.go
Encode
func Encode(g geom.T) (kml.Element, error) { switch g := g.(type) { case *geom.Point: return EncodePoint(g), nil case *geom.LineString: return EncodeLineString(g), nil case *geom.LinearRing: return EncodeLinearRing(g), nil case *geom.MultiLineString: return EncodeMultiLineString(g), nil case *geom.MultiPo...
go
func Encode(g geom.T) (kml.Element, error) { switch g := g.(type) { case *geom.Point: return EncodePoint(g), nil case *geom.LineString: return EncodeLineString(g), nil case *geom.LinearRing: return EncodeLinearRing(g), nil case *geom.MultiLineString: return EncodeMultiLineString(g), nil case *geom.MultiPo...
[ "func", "Encode", "(", "g", "geom", ".", "T", ")", "(", "kml", ".", "Element", ",", "error", ")", "{", "switch", "g", ":=", "g", ".", "(", "type", ")", "{", "case", "*", "geom", ".", "Point", ":", "return", "EncodePoint", "(", "g", ")", ",", ...
// Encode encodes an arbitrary geometry.
[ "Encode", "encodes", "an", "arbitrary", "geometry", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L10-L31
29,718
twpayne/go-geom
encoding/kml/kml.go
EncodeLineString
func EncodeLineString(ls *geom.LineString) kml.Element { flatCoords := ls.FlatCoords() return kml.LineString(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), ls.Stride(), dim(ls.Layout()))) }
go
func EncodeLineString(ls *geom.LineString) kml.Element { flatCoords := ls.FlatCoords() return kml.LineString(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), ls.Stride(), dim(ls.Layout()))) }
[ "func", "EncodeLineString", "(", "ls", "*", "geom", ".", "LineString", ")", "kml", ".", "Element", "{", "flatCoords", ":=", "ls", ".", "FlatCoords", "(", ")", "\n", "return", "kml", ".", "LineString", "(", "kml", ".", "CoordinatesFlat", "(", "flatCoords", ...
// EncodeLineString encodes a LineString.
[ "EncodeLineString", "encodes", "a", "LineString", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L34-L37
29,719
twpayne/go-geom
encoding/kml/kml.go
EncodeLinearRing
func EncodeLinearRing(lr *geom.LinearRing) kml.Element { flatCoords := lr.FlatCoords() return kml.LinearRing(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), lr.Stride(), dim(lr.Layout()))) }
go
func EncodeLinearRing(lr *geom.LinearRing) kml.Element { flatCoords := lr.FlatCoords() return kml.LinearRing(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), lr.Stride(), dim(lr.Layout()))) }
[ "func", "EncodeLinearRing", "(", "lr", "*", "geom", ".", "LinearRing", ")", "kml", ".", "Element", "{", "flatCoords", ":=", "lr", ".", "FlatCoords", "(", ")", "\n", "return", "kml", ".", "LinearRing", "(", "kml", ".", "CoordinatesFlat", "(", "flatCoords", ...
// EncodeLinearRing encodes a LinearRing.
[ "EncodeLinearRing", "encodes", "a", "LinearRing", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L40-L43
29,720
twpayne/go-geom
encoding/kml/kml.go
EncodeMultiLineString
func EncodeMultiLineString(mls *geom.MultiLineString) kml.Element { lineStrings := make([]kml.Element, mls.NumLineStrings()) flatCoords := mls.FlatCoords() ends := mls.Ends() stride := mls.Stride() d := dim(mls.Layout()) offset := 0 for i, end := range ends { lineStrings[i] = kml.LineString(kml.CoordinatesFlat...
go
func EncodeMultiLineString(mls *geom.MultiLineString) kml.Element { lineStrings := make([]kml.Element, mls.NumLineStrings()) flatCoords := mls.FlatCoords() ends := mls.Ends() stride := mls.Stride() d := dim(mls.Layout()) offset := 0 for i, end := range ends { lineStrings[i] = kml.LineString(kml.CoordinatesFlat...
[ "func", "EncodeMultiLineString", "(", "mls", "*", "geom", ".", "MultiLineString", ")", "kml", ".", "Element", "{", "lineStrings", ":=", "make", "(", "[", "]", "kml", ".", "Element", ",", "mls", ".", "NumLineStrings", "(", ")", ")", "\n", "flatCoords", ":...
// EncodeMultiLineString encodes a MultiLineString.
[ "EncodeMultiLineString", "encodes", "a", "MultiLineString", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L46-L58
29,721
twpayne/go-geom
encoding/kml/kml.go
EncodeMultiPoint
func EncodeMultiPoint(mp *geom.MultiPoint) kml.Element { points := make([]kml.Element, mp.NumPoints()) flatCoords := mp.FlatCoords() stride := mp.Stride() d := dim(mp.Layout()) for i, offset, end := 0, 0, len(flatCoords); offset < end; i++ { points[i] = kml.Point(kml.CoordinatesFlat(flatCoords, offset, offset+st...
go
func EncodeMultiPoint(mp *geom.MultiPoint) kml.Element { points := make([]kml.Element, mp.NumPoints()) flatCoords := mp.FlatCoords() stride := mp.Stride() d := dim(mp.Layout()) for i, offset, end := 0, 0, len(flatCoords); offset < end; i++ { points[i] = kml.Point(kml.CoordinatesFlat(flatCoords, offset, offset+st...
[ "func", "EncodeMultiPoint", "(", "mp", "*", "geom", ".", "MultiPoint", ")", "kml", ".", "Element", "{", "points", ":=", "make", "(", "[", "]", "kml", ".", "Element", ",", "mp", ".", "NumPoints", "(", ")", ")", "\n", "flatCoords", ":=", "mp", ".", "...
// EncodeMultiPoint encodes a MultiPoint.
[ "EncodeMultiPoint", "encodes", "a", "MultiPoint", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L61-L71
29,722
twpayne/go-geom
encoding/kml/kml.go
EncodeMultiPolygon
func EncodeMultiPolygon(mp *geom.MultiPolygon) kml.Element { polygons := make([]kml.Element, mp.NumPolygons()) flatCoords := mp.FlatCoords() endss := mp.Endss() stride := mp.Stride() d := dim(mp.Layout()) offset := 0 for i, ends := range endss { boundaries := make([]kml.Element, len(ends)) for j, end := rang...
go
func EncodeMultiPolygon(mp *geom.MultiPolygon) kml.Element { polygons := make([]kml.Element, mp.NumPolygons()) flatCoords := mp.FlatCoords() endss := mp.Endss() stride := mp.Stride() d := dim(mp.Layout()) offset := 0 for i, ends := range endss { boundaries := make([]kml.Element, len(ends)) for j, end := rang...
[ "func", "EncodeMultiPolygon", "(", "mp", "*", "geom", ".", "MultiPolygon", ")", "kml", ".", "Element", "{", "polygons", ":=", "make", "(", "[", "]", "kml", ".", "Element", ",", "mp", ".", "NumPolygons", "(", ")", ")", "\n", "flatCoords", ":=", "mp", ...
// EncodeMultiPolygon encodes a MultiPolygon.
[ "EncodeMultiPolygon", "encodes", "a", "MultiPolygon", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L74-L95
29,723
twpayne/go-geom
encoding/kml/kml.go
EncodePoint
func EncodePoint(p *geom.Point) kml.Element { flatCoords := p.FlatCoords() return kml.Point(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), p.Stride(), dim(p.Layout()))) }
go
func EncodePoint(p *geom.Point) kml.Element { flatCoords := p.FlatCoords() return kml.Point(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), p.Stride(), dim(p.Layout()))) }
[ "func", "EncodePoint", "(", "p", "*", "geom", ".", "Point", ")", "kml", ".", "Element", "{", "flatCoords", ":=", "p", ".", "FlatCoords", "(", ")", "\n", "return", "kml", ".", "Point", "(", "kml", ".", "CoordinatesFlat", "(", "flatCoords", ",", "0", "...
// EncodePoint encodes a Point.
[ "EncodePoint", "encodes", "a", "Point", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L98-L101
29,724
twpayne/go-geom
encoding/kml/kml.go
EncodePolygon
func EncodePolygon(p *geom.Polygon) kml.Element { boundaries := make([]kml.Element, p.NumLinearRings()) stride := p.Stride() flatCoords := p.FlatCoords() d := dim(p.Layout()) offset := 0 for i, end := range p.Ends() { linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d)) if i =...
go
func EncodePolygon(p *geom.Polygon) kml.Element { boundaries := make([]kml.Element, p.NumLinearRings()) stride := p.Stride() flatCoords := p.FlatCoords() d := dim(p.Layout()) offset := 0 for i, end := range p.Ends() { linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d)) if i =...
[ "func", "EncodePolygon", "(", "p", "*", "geom", ".", "Polygon", ")", "kml", ".", "Element", "{", "boundaries", ":=", "make", "(", "[", "]", "kml", ".", "Element", ",", "p", ".", "NumLinearRings", "(", ")", ")", "\n", "stride", ":=", "p", ".", "Stri...
// EncodePolygon encodes a Polygon.
[ "EncodePolygon", "encodes", "a", "Polygon", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L104-L120
29,725
twpayne/go-geom
encoding/kml/kml.go
EncodeGeometryCollection
func EncodeGeometryCollection(g *geom.GeometryCollection) (kml.Element, error) { geometries := make([]kml.Element, g.NumGeoms()) for i, g := range g.Geoms() { var err error geometries[i], err = Encode(g) if err != nil { return nil, err } } return kml.MultiGeometry(geometries...), nil }
go
func EncodeGeometryCollection(g *geom.GeometryCollection) (kml.Element, error) { geometries := make([]kml.Element, g.NumGeoms()) for i, g := range g.Geoms() { var err error geometries[i], err = Encode(g) if err != nil { return nil, err } } return kml.MultiGeometry(geometries...), nil }
[ "func", "EncodeGeometryCollection", "(", "g", "*", "geom", ".", "GeometryCollection", ")", "(", "kml", ".", "Element", ",", "error", ")", "{", "geometries", ":=", "make", "(", "[", "]", "kml", ".", "Element", ",", "g", ".", "NumGeoms", "(", ")", ")", ...
// EncodeGeometryCollection encodes a GeometryCollection.
[ "EncodeGeometryCollection", "encodes", "a", "GeometryCollection", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L123-L133
29,726
twpayne/go-geom
multipoint.go
NewMultiPointFlat
func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint { g := new(MultiPoint) g.layout = layout g.stride = layout.Stride() g.flatCoords = flatCoords return g }
go
func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint { g := new(MultiPoint) g.layout = layout g.stride = layout.Stride() g.flatCoords = flatCoords return g }
[ "func", "NewMultiPointFlat", "(", "layout", "Layout", ",", "flatCoords", "[", "]", "float64", ")", "*", "MultiPoint", "{", "g", ":=", "new", "(", "MultiPoint", ")", "\n", "g", ".", "layout", "=", "layout", "\n", "g", ".", "stride", "=", "layout", ".", ...
// NewMultiPointFlat returns a new MultiPoint with the given flat coordinates.
[ "NewMultiPointFlat", "returns", "a", "new", "MultiPoint", "with", "the", "given", "flat", "coordinates", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L14-L20
29,727
twpayne/go-geom
multipoint.go
Point
func (g *MultiPoint) Point(i int) *Point { return NewPointFlat(g.layout, g.Coord(i)) }
go
func (g *MultiPoint) Point(i int) *Point { return NewPointFlat(g.layout, g.Coord(i)) }
[ "func", "(", "g", "*", "MultiPoint", ")", "Point", "(", "i", "int", ")", "*", "Point", "{", "return", "NewPointFlat", "(", "g", ".", "layout", ",", "g", ".", "Coord", "(", "i", ")", ")", "\n", "}" ]
// Point returns the ith Point.
[ "Point", "returns", "the", "ith", "Point", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L68-L70
29,728
twpayne/go-geom
multipoint.go
Push
func (g *MultiPoint) Push(p *Point) error { if p.layout != g.layout { return ErrLayoutMismatch{Got: p.layout, Want: g.layout} } g.flatCoords = append(g.flatCoords, p.flatCoords...) return nil }
go
func (g *MultiPoint) Push(p *Point) error { if p.layout != g.layout { return ErrLayoutMismatch{Got: p.layout, Want: g.layout} } g.flatCoords = append(g.flatCoords, p.flatCoords...) return nil }
[ "func", "(", "g", "*", "MultiPoint", ")", "Push", "(", "p", "*", "Point", ")", "error", "{", "if", "p", ".", "layout", "!=", "g", ".", "layout", "{", "return", "ErrLayoutMismatch", "{", "Got", ":", "p", ".", "layout", ",", "Want", ":", "g", ".", ...
// Push appends a point.
[ "Push", "appends", "a", "point", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L73-L79
29,729
twpayne/go-geom
xy/area_centroid.go
NewAreaCentroidCalculator
func NewAreaCentroidCalculator(layout geom.Layout) *AreaCentroidCalculator { return &AreaCentroidCalculator{ layout: layout, stride: layout.Stride(), centSum: geom.Coord(make([]float64, layout.Stride())), triangleCent3: geom.Coord(make([]float64, layout.Stride())), cg3: geom.Coo...
go
func NewAreaCentroidCalculator(layout geom.Layout) *AreaCentroidCalculator { return &AreaCentroidCalculator{ layout: layout, stride: layout.Stride(), centSum: geom.Coord(make([]float64, layout.Stride())), triangleCent3: geom.Coord(make([]float64, layout.Stride())), cg3: geom.Coo...
[ "func", "NewAreaCentroidCalculator", "(", "layout", "geom", ".", "Layout", ")", "*", "AreaCentroidCalculator", "{", "return", "&", "AreaCentroidCalculator", "{", "layout", ":", "layout", ",", "stride", ":", "layout", ".", "Stride", "(", ")", ",", "centSum", ":...
// NewAreaCentroidCalculator creates a new instance of the calculator. // Once a calculator is created polygons can be added to it and the // GetCentroid method can be used at any point to get the current centroid // the centroid will naturally change each time a polygon is added
[ "NewAreaCentroidCalculator", "creates", "a", "new", "instance", "of", "the", "calculator", ".", "Once", "a", "calculator", "is", "created", "polygons", "can", "be", "added", "to", "it", "and", "the", "GetCentroid", "method", "can", "be", "used", "at", "any", ...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L72-L80
29,730
twpayne/go-geom
xy/area_centroid.go
AddPolygon
func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) { calc.setBasePoint(polygon.Coord(0)) calc.addShell(polygon.LinearRing(0).FlatCoords()) for i := 1; i < polygon.NumLinearRings(); i++ { calc.addHole(polygon.LinearRing(i).FlatCoords()) } }
go
func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) { calc.setBasePoint(polygon.Coord(0)) calc.addShell(polygon.LinearRing(0).FlatCoords()) for i := 1; i < polygon.NumLinearRings(); i++ { calc.addHole(polygon.LinearRing(i).FlatCoords()) } }
[ "func", "(", "calc", "*", "AreaCentroidCalculator", ")", "AddPolygon", "(", "polygon", "*", "geom", ".", "Polygon", ")", "{", "calc", ".", "setBasePoint", "(", "polygon", ".", "Coord", "(", "0", ")", ")", "\n\n", "calc", ".", "addShell", "(", "polygon", ...
// AddPolygon adds a polygon to the calculation.
[ "AddPolygon", "adds", "a", "polygon", "to", "the", "calculation", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L102-L109
29,731
twpayne/go-geom
xy/area_centroid.go
centroid3
func centroid3(p1, p2, p3, c geom.Coord) { c[0] = p1[0] + p2[0] + p3[0] c[1] = p1[1] + p2[1] + p3[1] }
go
func centroid3(p1, p2, p3, c geom.Coord) { c[0] = p1[0] + p2[0] + p3[0] c[1] = p1[1] + p2[1] + p3[1] }
[ "func", "centroid3", "(", "p1", ",", "p2", ",", "p3", ",", "c", "geom", ".", "Coord", ")", "{", "c", "[", "0", "]", "=", "p1", "[", "0", "]", "+", "p2", "[", "0", "]", "+", "p3", "[", "0", "]", "\n", "c", "[", "1", "]", "=", "p1", "["...
// Returns three times the centroid of the triangle p1-p2-p3. // The factor of 3 is left in to permit division to be avoided until later.
[ "Returns", "three", "times", "the", "centroid", "of", "the", "triangle", "p1", "-", "p2", "-", "p3", ".", "The", "factor", "of", "3", "is", "left", "in", "to", "permit", "division", "to", "be", "avoided", "until", "later", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L165-L168
29,732
twpayne/go-geom
xy/area_centroid.go
area2
func area2(p1, p2, p3 geom.Coord) float64 { return (p2[0]-p1[0])*(p3[1]-p1[1]) - (p3[0]-p1[0])*(p2[1]-p1[1]) }
go
func area2(p1, p2, p3 geom.Coord) float64 { return (p2[0]-p1[0])*(p3[1]-p1[1]) - (p3[0]-p1[0])*(p2[1]-p1[1]) }
[ "func", "area2", "(", "p1", ",", "p2", ",", "p3", "geom", ".", "Coord", ")", "float64", "{", "return", "(", "p2", "[", "0", "]", "-", "p1", "[", "0", "]", ")", "*", "(", "p3", "[", "1", "]", "-", "p1", "[", "1", "]", ")", "-", "(", "p3"...
// Returns twice the signed area of the triangle p1-p2-p3, // positive if a,b,c are oriented ccw, and negative if cw.
[ "Returns", "twice", "the", "signed", "area", "of", "the", "triangle", "p1", "-", "p2", "-", "p3", "positive", "if", "a", "b", "c", "are", "oriented", "ccw", "and", "negative", "if", "cw", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L172-L174
29,733
twpayne/go-geom
xy/radial_comparator.go
NewRadialSorting
func NewRadialSorting(layout geom.Layout, coordData []float64, focalPoint geom.Coord) sort.Interface { isLess := func(v1, v2 []float64) bool { orient := bigxy.OrientationIndex(focalPoint, v1, v2) if orient == orientation.CounterClockwise { return false } if orient == orientation.Clockwise { return true ...
go
func NewRadialSorting(layout geom.Layout, coordData []float64, focalPoint geom.Coord) sort.Interface { isLess := func(v1, v2 []float64) bool { orient := bigxy.OrientationIndex(focalPoint, v1, v2) if orient == orientation.CounterClockwise { return false } if orient == orientation.Clockwise { return true ...
[ "func", "NewRadialSorting", "(", "layout", "geom", ".", "Layout", ",", "coordData", "[", "]", "float64", ",", "focalPoint", "geom", ".", "Coord", ")", "sort", ".", "Interface", "{", "isLess", ":=", "func", "(", "v1", ",", "v2", "[", "]", "float64", ")"...
// NewRadialSorting creates an implementation sort.Interface which will sort the wrapped coordinate array // radially around the focal point. The comparison is based on the angle and distance // from the focal point. // First the angle is checked. // Counter clockwise indicates a greater value and clockwise indicates ...
[ "NewRadialSorting", "creates", "an", "implementation", "sort", ".", "Interface", "which", "will", "sort", "the", "wrapped", "coordinate", "array", "radially", "around", "the", "focal", "point", ".", "The", "comparison", "is", "based", "on", "the", "angle", "and"...
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/radial_comparator.go#L18-L40
29,734
twpayne/go-geom
encoding/wkbcommon/binary.go
ReadUInt32
func ReadUInt32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) { var buf [4]byte if _, err := io.ReadFull(r, buf[:]); err != nil { return 0, err } return byteOrder.Uint32(buf[:]), nil }
go
func ReadUInt32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) { var buf [4]byte if _, err := io.ReadFull(r, buf[:]); err != nil { return 0, err } return byteOrder.Uint32(buf[:]), nil }
[ "func", "ReadUInt32", "(", "r", "io", ".", "Reader", ",", "byteOrder", "binary", ".", "ByteOrder", ")", "(", "uint32", ",", "error", ")", "{", "var", "buf", "[", "4", "]", "byte", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r"...
// ReadUInt32 reads a uint32 from r.
[ "ReadUInt32", "reads", "a", "uint32", "from", "r", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L16-L22
29,735
twpayne/go-geom
encoding/wkbcommon/binary.go
ReadByte
func ReadByte(r io.Reader) (byte, error) { var buf [1]byte if _, err := r.Read(buf[:]); err != nil { return 0, err } return buf[0], nil }
go
func ReadByte(r io.Reader) (byte, error) { var buf [1]byte if _, err := r.Read(buf[:]); err != nil { return 0, err } return buf[0], nil }
[ "func", "ReadByte", "(", "r", "io", ".", "Reader", ")", "(", "byte", ",", "error", ")", "{", "var", "buf", "[", "1", "]", "byte", "\n", "if", "_", ",", "err", ":=", "r", ".", "Read", "(", "buf", "[", ":", "]", ")", ";", "err", "!=", "nil", ...
// ReadByte reads a byte from r.
[ "ReadByte", "reads", "a", "byte", "from", "r", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L38-L44
29,736
twpayne/go-geom
encoding/wkbcommon/binary.go
WriteUInt32
func WriteUInt32(w io.Writer, byteOrder binary.ByteOrder, value uint32) error { var buf [4]byte byteOrder.PutUint32(buf[:], value) _, err := w.Write(buf[:]) return err }
go
func WriteUInt32(w io.Writer, byteOrder binary.ByteOrder, value uint32) error { var buf [4]byte byteOrder.PutUint32(buf[:], value) _, err := w.Write(buf[:]) return err }
[ "func", "WriteUInt32", "(", "w", "io", ".", "Writer", ",", "byteOrder", "binary", ".", "ByteOrder", ",", "value", "uint32", ")", "error", "{", "var", "buf", "[", "4", "]", "byte", "\n", "byteOrder", ".", "PutUint32", "(", "buf", "[", ":", "]", ",", ...
// WriteUInt32 writes a uint32 to w.
[ "WriteUInt32", "writes", "a", "uint32", "to", "w", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L62-L67
29,737
twpayne/go-geom
encoding/wkbcommon/binary.go
WriteByte
func WriteByte(w io.Writer, value byte) error { var buf [1]byte buf[0] = value _, err := w.Write(buf[:]) return err }
go
func WriteByte(w io.Writer, value byte) error { var buf [1]byte buf[0] = value _, err := w.Write(buf[:]) return err }
[ "func", "WriteByte", "(", "w", "io", ".", "Writer", ",", "value", "byte", ")", "error", "{", "var", "buf", "[", "1", "]", "byte", "\n", "buf", "[", "0", "]", "=", "value", "\n", "_", ",", "err", ":=", "w", ".", "Write", "(", "buf", "[", ":", ...
// WriteByte wrties a byte to w.
[ "WriteByte", "wrties", "a", "byte", "to", "w", "." ]
e21b3afba225b21d05fbcbeb8ece2c79c96554c5
https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L70-L75
29,738
pquerna/ffjson
fflib/v1/buffer_pool.go
poolNum
func poolNum(i int) int { // TODO(pquerna): convert to log2 w/ bsr asm instruction: // <https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns> if i <= 64 { return 0 } else if i <= 128 { return 1 } else if i <= 256 { return 2 } else if i <= 512 { return 3 } else if i <= 1024 { return 4 } els...
go
func poolNum(i int) int { // TODO(pquerna): convert to log2 w/ bsr asm instruction: // <https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns> if i <= 64 { return 0 } else if i <= 128 { return 1 } else if i <= 256 { return 2 } else if i <= 512 { return 3 } else if i <= 1024 { return 4 } els...
[ "func", "poolNum", "(", "i", "int", ")", "int", "{", "// TODO(pquerna): convert to log2 w/ bsr asm instruction:", "// \t<https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns>", "if", "i", "<=", "64", "{", "return", "0", "\n", "}", "else", "if", "i", "<=", "12...
// This returns the pool number that will give a buffer of // at least 'i' bytes.
[ "This", "returns", "the", "pool", "number", "that", "will", "give", "a", "buffer", "of", "at", "least", "i", "bytes", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/buffer_pool.go#L28-L62
29,739
pquerna/ffjson
fflib/v1/buffer_pool.go
Pool
func Pool(b []byte) { if b == nil { return } c := cap(b) // Our smallest buffer is 64 bytes, so we discard smaller buffers. if c < 64 { return } // We need to put the incoming buffer into the NEXT buffer, // since a buffer guarantees AT LEAST the number of bytes available // that is the top of this buffe...
go
func Pool(b []byte) { if b == nil { return } c := cap(b) // Our smallest buffer is 64 bytes, so we discard smaller buffers. if c < 64 { return } // We need to put the incoming buffer into the NEXT buffer, // since a buffer guarantees AT LEAST the number of bytes available // that is the top of this buffe...
[ "func", "Pool", "(", "b", "[", "]", "byte", ")", "{", "if", "b", "==", "nil", "{", "return", "\n", "}", "\n", "c", ":=", "cap", "(", "b", ")", "\n\n", "// Our smallest buffer is 64 bytes, so we discard smaller buffers.", "if", "c", "<", "64", "{", "retur...
// Send a buffer to the Pool to reuse for other instances. // You may no longer utilize the content of the buffer, since it may be used // by other goroutines.
[ "Send", "a", "buffer", "to", "the", "Pool", "to", "reuse", "for", "other", "instances", ".", "You", "may", "no", "longer", "utilize", "the", "content", "of", "the", "buffer", "since", "it", "may", "be", "used", "by", "other", "goroutines", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/buffer_pool.go#L67-L89
29,740
pquerna/ffjson
ffjson/marshal.go
Marshal
func Marshal(v interface{}) ([]byte, error) { f, ok := v.(marshalerFaster) if ok { buf := fflib.Buffer{} err := f.MarshalJSONBuf(&buf) b := buf.Bytes() if err != nil { if len(b) > 0 { Pool(b) } return nil, err } return b, nil } j, ok := v.(json.Marshaler) if ok { return j.MarshalJSON() ...
go
func Marshal(v interface{}) ([]byte, error) { f, ok := v.(marshalerFaster) if ok { buf := fflib.Buffer{} err := f.MarshalJSONBuf(&buf) b := buf.Bytes() if err != nil { if len(b) > 0 { Pool(b) } return nil, err } return b, nil } j, ok := v.(json.Marshaler) if ok { return j.MarshalJSON() ...
[ "func", "Marshal", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "f", ",", "ok", ":=", "v", ".", "(", "marshalerFaster", ")", "\n", "if", "ok", "{", "buf", ":=", "fflib", ".", "Buffer", "{", "}", "\n", "...
// Marshal will act the same way as json.Marshal, except // it will choose the ffjson marshal function before falling // back to using json.Marshal. // Using this function will bypass the internal copying and parsing // the json library normally does, which greatly speeds up encoding time. // It is ok to call this func...
[ "Marshal", "will", "act", "the", "same", "way", "as", "json", ".", "Marshal", "except", "it", "will", "choose", "the", "ffjson", "marshal", "function", "before", "falling", "back", "to", "using", "json", ".", "Marshal", ".", "Using", "this", "function", "w...
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/marshal.go#L42-L62
29,741
pquerna/ffjson
ffjson/marshal.go
Unmarshal
func Unmarshal(data []byte, v interface{}) error { f, ok := v.(unmarshalFaster) if ok { fs := fflib.NewFFLexer(data) return f.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start) } j, ok := v.(json.Unmarshaler) if ok { return j.UnmarshalJSON(data) } return json.Unmarshal(data, v) }
go
func Unmarshal(data []byte, v interface{}) error { f, ok := v.(unmarshalFaster) if ok { fs := fflib.NewFFLexer(data) return f.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start) } j, ok := v.(json.Unmarshaler) if ok { return j.UnmarshalJSON(data) } return json.Unmarshal(data, v) }
[ "func", "Unmarshal", "(", "data", "[", "]", "byte", ",", "v", "interface", "{", "}", ")", "error", "{", "f", ",", "ok", ":=", "v", ".", "(", "unmarshalFaster", ")", "\n", "if", "ok", "{", "fs", ":=", "fflib", ".", "NewFFLexer", "(", "data", ")", ...
// Unmarshal will act the same way as json.Unmarshal, except // it will choose the ffjson unmarshal function before falling // back to using json.Unmarshal. // The overhead of unmarshal is lower than on Marshal, // however this should still provide a speedup for your encoding. // It is ok to call this function even if ...
[ "Unmarshal", "will", "act", "the", "same", "way", "as", "json", ".", "Unmarshal", "except", "it", "will", "choose", "the", "ffjson", "unmarshal", "function", "before", "falling", "back", "to", "using", "json", ".", "Unmarshal", ".", "The", "overhead", "of", ...
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/marshal.go#L84-L96
29,742
pquerna/ffjson
fflib/v1/iota.go
FormatBits2
func FormatBits2(dst FormatBitsWriter, u uint64, base int, neg bool) { if base < 2 || base > len(digits) { panic("strconv: illegal AppendInt/FormatInt base") } // fast path for small common numbers if u <= 10 { if neg { dst.WriteByte('-') } dst.Write(smallNumbers[u]) return } // 2 <= base && base <=...
go
func FormatBits2(dst FormatBitsWriter, u uint64, base int, neg bool) { if base < 2 || base > len(digits) { panic("strconv: illegal AppendInt/FormatInt base") } // fast path for small common numbers if u <= 10 { if neg { dst.WriteByte('-') } dst.Write(smallNumbers[u]) return } // 2 <= base && base <=...
[ "func", "FormatBits2", "(", "dst", "FormatBitsWriter", ",", "u", "uint64", ",", "base", "int", ",", "neg", "bool", ")", "{", "if", "base", "<", "2", "||", "base", ">", "len", "(", "digits", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n"...
// FormatBits2 computes the string representation of u in the given base. // If neg is set, u is treated as negative int64 value. If append_ is // set, the string is appended to dst and the resulting byte slice is // returned as the first result value; otherwise the string is returned // as the second result value. //
[ "FormatBits2", "computes", "the", "string", "representation", "of", "u", "in", "the", "given", "base", ".", "If", "neg", "is", "set", "u", "is", "treated", "as", "negative", "int64", "value", ".", "If", "append_", "is", "set", "the", "string", "is", "app...
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/iota.go#L83-L161
29,743
pquerna/ffjson
fflib/v1/reader.go
Reset
func (r *ffReader) Reset(d []byte) { r.s = d r.i = 0 r.l = len(d) }
go
func (r *ffReader) Reset(d []byte) { r.s = d r.i = 0 r.l = len(d) }
[ "func", "(", "r", "*", "ffReader", ")", "Reset", "(", "d", "[", "]", "byte", ")", "{", "r", ".", "s", "=", "d", "\n", "r", ".", "i", "=", "0", "\n", "r", ".", "l", "=", "len", "(", "d", ")", "\n", "}" ]
// Reset the reader, and add new input.
[ "Reset", "the", "reader", "and", "add", "new", "input", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/reader.go#L52-L56
29,744
pquerna/ffjson
fflib/v1/reader.go
PosWithLine
func (r *ffReader) PosWithLine() (int, int) { currentLine := 1 currentChar := 0 for i := 0; i < r.i; i++ { c := r.s[i] currentChar++ if c == '\n' { currentLine++ currentChar = 0 } } return currentLine, currentChar }
go
func (r *ffReader) PosWithLine() (int, int) { currentLine := 1 currentChar := 0 for i := 0; i < r.i; i++ { c := r.s[i] currentChar++ if c == '\n' { currentLine++ currentChar = 0 } } return currentLine, currentChar }
[ "func", "(", "r", "*", "ffReader", ")", "PosWithLine", "(", ")", "(", "int", ",", "int", ")", "{", "currentLine", ":=", "1", "\n", "currentChar", ":=", "0", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "r", ".", "i", ";", "i", "++", "{", "c"...
// Calcuates the Position with line and line offset, // because this isn't counted for performance reasons, // it will iterate the buffer from the beginning, and should // only be used in error-paths.
[ "Calcuates", "the", "Position", "with", "line", "and", "line", "offset", "because", "this", "isn", "t", "counted", "for", "performance", "reasons", "it", "will", "iterate", "the", "buffer", "from", "the", "beginning", "and", "should", "only", "be", "used", "...
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/reader.go#L62-L76
29,745
pquerna/ffjson
fflib/v1/ftoa.go
formatBits
func formatBits(dst EncodingBuffer, u uint64, base int, neg bool) { if base < 2 || base > len(digits) { panic("strconv: illegal AppendInt/FormatInt base") } // 2 <= base && base <= len(digits) var a [64 + 1]byte // +1 for sign of 64bit value in base 2 i := len(a) if neg { u = -u } // convert bits if bas...
go
func formatBits(dst EncodingBuffer, u uint64, base int, neg bool) { if base < 2 || base > len(digits) { panic("strconv: illegal AppendInt/FormatInt base") } // 2 <= base && base <= len(digits) var a [64 + 1]byte // +1 for sign of 64bit value in base 2 i := len(a) if neg { u = -u } // convert bits if bas...
[ "func", "formatBits", "(", "dst", "EncodingBuffer", ",", "u", "uint64", ",", "base", "int", ",", "neg", "bool", ")", "{", "if", "base", "<", "2", "||", "base", ">", "len", "(", "digits", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", ...
// formatBits computes the string representation of u in the given base. // If neg is set, u is treated as negative int64 value.
[ "formatBits", "computes", "the", "string", "representation", "of", "u", "in", "the", "given", "base", ".", "If", "neg", "is", "set", "u", "is", "treated", "as", "negative", "int64", "value", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/ftoa.go#L464-L542
29,746
pquerna/ffjson
inception/encoder.go
lastConditional
func lastConditional(fields []*StructField) bool { if len(fields) > 0 { f := fields[len(fields)-1] return f.OmitEmpty } return false }
go
func lastConditional(fields []*StructField) bool { if len(fields) > 0 { f := fields[len(fields)-1] return f.OmitEmpty } return false }
[ "func", "lastConditional", "(", "fields", "[", "]", "*", "StructField", ")", "bool", "{", "if", "len", "(", "fields", ")", ">", "0", "{", "f", ":=", "fields", "[", "len", "(", "fields", ")", "-", "1", "]", "\n", "return", "f", ".", "OmitEmpty", "...
// We check if the last field is conditional.
[ "We", "check", "if", "the", "last", "field", "is", "conditional", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/encoder.go#L475-L481
29,747
pquerna/ffjson
fflib/v1/extfloat.go
Normalize
func (f *extFloat) Normalize() (shift uint) { mant, exp := f.mant, f.exp if mant == 0 { return 0 } if mant>>(64-32) == 0 { mant <<= 32 exp -= 32 } if mant>>(64-16) == 0 { mant <<= 16 exp -= 16 } if mant>>(64-8) == 0 { mant <<= 8 exp -= 8 } if mant>>(64-4) == 0 { mant <<= 4 exp -= 4 } if ma...
go
func (f *extFloat) Normalize() (shift uint) { mant, exp := f.mant, f.exp if mant == 0 { return 0 } if mant>>(64-32) == 0 { mant <<= 32 exp -= 32 } if mant>>(64-16) == 0 { mant <<= 16 exp -= 16 } if mant>>(64-8) == 0 { mant <<= 8 exp -= 8 } if mant>>(64-4) == 0 { mant <<= 4 exp -= 4 } if ma...
[ "func", "(", "f", "*", "extFloat", ")", "Normalize", "(", ")", "(", "shift", "uint", ")", "{", "mant", ",", "exp", ":=", "f", ".", "mant", ",", "f", ".", "exp", "\n", "if", "mant", "==", "0", "{", "return", "0", "\n", "}", "\n", "if", "mant",...
// Normalize normalizes f so that the highest bit of the mantissa is // set, and returns the number by which the mantissa was left-shifted.
[ "Normalize", "normalizes", "f", "so", "that", "the", "highest", "bit", "of", "the", "mantissa", "is", "set", "and", "returns", "the", "number", "by", "which", "the", "mantissa", "was", "left", "-", "shifted", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L199-L231
29,748
pquerna/ffjson
fflib/v1/extfloat.go
frexp10Many
func frexp10Many(a, b, c *extFloat) (exp10 int) { exp10, i := c.frexp10() a.Multiply(powersOfTen[i]) b.Multiply(powersOfTen[i]) return }
go
func frexp10Many(a, b, c *extFloat) (exp10 int) { exp10, i := c.frexp10() a.Multiply(powersOfTen[i]) b.Multiply(powersOfTen[i]) return }
[ "func", "frexp10Many", "(", "a", ",", "b", ",", "c", "*", "extFloat", ")", "(", "exp10", "int", ")", "{", "exp10", ",", "i", ":=", "c", ".", "frexp10", "(", ")", "\n", "a", ".", "Multiply", "(", "powersOfTen", "[", "i", "]", ")", "\n", "b", "...
// frexp10Many applies a common shift by a power of ten to a, b, c.
[ "frexp10Many", "applies", "a", "common", "shift", "by", "a", "power", "of", "ten", "to", "a", "b", "c", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L368-L373
29,749
pquerna/ffjson
fflib/v1/extfloat.go
FixedDecimal
func (f *extFloat) FixedDecimal(d *decimalSlice, n int) bool { if f.mant == 0 { d.nd = 0 d.dp = 0 d.neg = f.neg return true } if n == 0 { panic("strconv: internal error: extFloat.FixedDecimal called with n == 0") } // Multiply by an appropriate power of ten to have a reasonable // number to process. f....
go
func (f *extFloat) FixedDecimal(d *decimalSlice, n int) bool { if f.mant == 0 { d.nd = 0 d.dp = 0 d.neg = f.neg return true } if n == 0 { panic("strconv: internal error: extFloat.FixedDecimal called with n == 0") } // Multiply by an appropriate power of ten to have a reasonable // number to process. f....
[ "func", "(", "f", "*", "extFloat", ")", "FixedDecimal", "(", "d", "*", "decimalSlice", ",", "n", "int", ")", "bool", "{", "if", "f", ".", "mant", "==", "0", "{", "d", ".", "nd", "=", "0", "\n", "d", ".", "dp", "=", "0", "\n", "d", ".", "neg...
// FixedDecimal stores in d the first n significant digits // of the decimal representation of f. It returns false // if it cannot be sure of the answer.
[ "FixedDecimal", "stores", "in", "d", "the", "first", "n", "significant", "digits", "of", "the", "decimal", "representation", "of", "f", ".", "It", "returns", "false", "if", "it", "cannot", "be", "sure", "of", "the", "answer", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L378-L486
29,750
pquerna/ffjson
fflib/v1/lexer.go
Reset
func (ffl *FFLexer) Reset(input []byte) { ffl.Token = FFTok_init ffl.Error = FFErr_e_ok ffl.BigError = nil ffl.reader.Reset(input) ffl.lastCurrentChar = 0 ffl.Output.Reset() }
go
func (ffl *FFLexer) Reset(input []byte) { ffl.Token = FFTok_init ffl.Error = FFErr_e_ok ffl.BigError = nil ffl.reader.Reset(input) ffl.lastCurrentChar = 0 ffl.Output.Reset() }
[ "func", "(", "ffl", "*", "FFLexer", ")", "Reset", "(", "input", "[", "]", "byte", ")", "{", "ffl", ".", "Token", "=", "FFTok_init", "\n", "ffl", ".", "Error", "=", "FFErr_e_ok", "\n", "ffl", ".", "BigError", "=", "nil", "\n", "ffl", ".", "reader", ...
// Reset the Lexer and add new input.
[ "Reset", "the", "Lexer", "and", "add", "new", "input", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/lexer.go#L130-L137
29,751
pquerna/ffjson
fflib/v1/decimal.go
Assign
func (a *decimal) Assign(v uint64) { var buf [24]byte // Write reversed decimal in buf. n := 0 for v > 0 { v1 := v / 10 v -= 10 * v1 buf[n] = byte(v + '0') n++ v = v1 } // Reverse again to produce forward decimal in a.d. a.nd = 0 for n--; n >= 0; n-- { a.d[a.nd] = buf[n] a.nd++ } a.dp = a.nd ...
go
func (a *decimal) Assign(v uint64) { var buf [24]byte // Write reversed decimal in buf. n := 0 for v > 0 { v1 := v / 10 v -= 10 * v1 buf[n] = byte(v + '0') n++ v = v1 } // Reverse again to produce forward decimal in a.d. a.nd = 0 for n--; n >= 0; n-- { a.d[a.nd] = buf[n] a.nd++ } a.dp = a.nd ...
[ "func", "(", "a", "*", "decimal", ")", "Assign", "(", "v", "uint64", ")", "{", "var", "buf", "[", "24", "]", "byte", "\n\n", "// Write reversed decimal in buf.", "n", ":=", "0", "\n", "for", "v", ">", "0", "{", "v1", ":=", "v", "/", "10", "\n", "...
// Assign v to a.
[ "Assign", "v", "to", "a", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L81-L102
29,752
pquerna/ffjson
fflib/v1/decimal.go
prefixIsLessThan
func prefixIsLessThan(b []byte, s string) bool { for i := 0; i < len(s); i++ { if i >= len(b) { return true } if b[i] != s[i] { return b[i] < s[i] } } return false }
go
func prefixIsLessThan(b []byte, s string) bool { for i := 0; i < len(s); i++ { if i >= len(b) { return true } if b[i] != s[i] { return b[i] < s[i] } } return false }
[ "func", "prefixIsLessThan", "(", "b", "[", "]", "byte", ",", "s", "string", ")", "bool", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "if", "i", ">=", "len", "(", "b", ")", "{", "return", "true", "\n...
// Is the leading prefix of b lexicographically less than s?
[ "Is", "the", "leading", "prefix", "of", "b", "lexicographically", "less", "than", "s?" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L219-L229
29,753
pquerna/ffjson
fflib/v1/decimal.go
shouldRoundUp
func shouldRoundUp(a *decimal, nd int) bool { if nd < 0 || nd >= a.nd { return false } if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even // if we truncated, a little higher than what's recorded - always round up if a.trunc { return true } return nd > 0 && (a.d[nd-1]-'0')%2 != 0 } ...
go
func shouldRoundUp(a *decimal, nd int) bool { if nd < 0 || nd >= a.nd { return false } if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even // if we truncated, a little higher than what's recorded - always round up if a.trunc { return true } return nd > 0 && (a.d[nd-1]-'0')%2 != 0 } ...
[ "func", "shouldRoundUp", "(", "a", "*", "decimal", ",", "nd", "int", ")", "bool", "{", "if", "nd", "<", "0", "||", "nd", ">=", "a", ".", "nd", "{", "return", "false", "\n", "}", "\n", "if", "a", ".", "d", "[", "nd", "]", "==", "'5'", "&&", ...
// If we chop a at nd digits, should we round up?
[ "If", "we", "chop", "a", "at", "nd", "digits", "should", "we", "round", "up?" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L298-L311
29,754
pquerna/ffjson
fflib/v1/decimal.go
RoundedInteger
func (a *decimal) RoundedInteger() uint64 { if a.dp > 20 { return 0xFFFFFFFFFFFFFFFF } var i int n := uint64(0) for i = 0; i < a.dp && i < a.nd; i++ { n = n*10 + uint64(a.d[i]-'0') } for ; i < a.dp; i++ { n *= 10 } if shouldRoundUp(a, a.dp) { n++ } return n }
go
func (a *decimal) RoundedInteger() uint64 { if a.dp > 20 { return 0xFFFFFFFFFFFFFFFF } var i int n := uint64(0) for i = 0; i < a.dp && i < a.nd; i++ { n = n*10 + uint64(a.d[i]-'0') } for ; i < a.dp; i++ { n *= 10 } if shouldRoundUp(a, a.dp) { n++ } return n }
[ "func", "(", "a", "*", "decimal", ")", "RoundedInteger", "(", ")", "uint64", "{", "if", "a", ".", "dp", ">", "20", "{", "return", "0xFFFFFFFFFFFFFFFF", "\n", "}", "\n", "var", "i", "int", "\n", "n", ":=", "uint64", "(", "0", ")", "\n", "for", "i"...
// Extract integer part, rounded appropriately. // No guarantees about overflow.
[ "Extract", "integer", "part", "rounded", "appropriately", ".", "No", "guarantees", "about", "overflow", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L362-L378
29,755
pquerna/ffjson
inception/writerstack.go
Write
func (w *ConditionalWrite) Write(s string) { w.Queued = append(w.Queued, s) }
go
func (w *ConditionalWrite) Write(s string) { w.Queued = append(w.Queued, s) }
[ "func", "(", "w", "*", "ConditionalWrite", ")", "Write", "(", "s", "string", ")", "{", "w", ".", "Queued", "=", "append", "(", "w", ".", "Queued", ",", "s", ")", "\n", "}" ]
// Write will add a string to be written
[ "Write", "will", "add", "a", "string", "to", "be", "written" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L11-L13
29,756
pquerna/ffjson
inception/writerstack.go
DeleteLast
func (w *ConditionalWrite) DeleteLast() { if len(w.Queued) == 0 { return } w.Queued = w.Queued[:len(w.Queued)-1] }
go
func (w *ConditionalWrite) DeleteLast() { if len(w.Queued) == 0 { return } w.Queued = w.Queued[:len(w.Queued)-1] }
[ "func", "(", "w", "*", "ConditionalWrite", ")", "DeleteLast", "(", ")", "{", "if", "len", "(", "w", ".", "Queued", ")", "==", "0", "{", "return", "\n", "}", "\n", "w", ".", "Queued", "=", "w", ".", "Queued", "[", ":", "len", "(", "w", ".", "Q...
// DeleteLast will delete the last added write
[ "DeleteLast", "will", "delete", "the", "last", "added", "write" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L16-L21
29,757
pquerna/ffjson
inception/writerstack.go
Last
func (w *ConditionalWrite) Last() string { if len(w.Queued) == 0 { return "" } return w.Queued[len(w.Queued)-1] }
go
func (w *ConditionalWrite) Last() string { if len(w.Queued) == 0 { return "" } return w.Queued[len(w.Queued)-1] }
[ "func", "(", "w", "*", "ConditionalWrite", ")", "Last", "(", ")", "string", "{", "if", "len", "(", "w", ".", "Queued", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "w", ".", "Queued", "[", "len", "(", "w", ".", "Queued"...
// Last will return the last added write
[ "Last", "will", "return", "the", "last", "added", "write" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L24-L29
29,758
pquerna/ffjson
inception/writerstack.go
WriteFlush
func (w *ConditionalWrite) WriteFlush(s string) string { w.Write(s) return w.Flush() }
go
func (w *ConditionalWrite) WriteFlush(s string) string { w.Write(s) return w.Flush() }
[ "func", "(", "w", "*", "ConditionalWrite", ")", "WriteFlush", "(", "s", "string", ")", "string", "{", "w", ".", "Write", "(", "s", ")", "\n", "return", "w", ".", "Flush", "(", ")", "\n", "}" ]
// WriteFlush will add a string and return the Flush result for the queue
[ "WriteFlush", "will", "add", "a", "string", "and", "return", "the", "Flush", "result", "for", "the", "queue" ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L54-L57
29,759
pquerna/ffjson
inception/writerstack.go
GetQueued
func (w *ConditionalWrite) GetQueued() string { t := w.Queued s := w.Flush() w.Queued = t return s }
go
func (w *ConditionalWrite) GetQueued() string { t := w.Queued s := w.Flush() w.Queued = t return s }
[ "func", "(", "w", "*", "ConditionalWrite", ")", "GetQueued", "(", ")", "string", "{", "t", ":=", "w", ".", "Queued", "\n", "s", ":=", "w", ".", "Flush", "(", ")", "\n", "w", ".", "Queued", "=", "t", "\n", "return", "s", "\n", "}" ]
// GetQueued will return the current queued content without flushing.
[ "GetQueued", "will", "return", "the", "current", "queued", "content", "without", "flushing", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L60-L65
29,760
pquerna/ffjson
ffjson/decoder.go
Decode
func (d *Decoder) Decode(data []byte, v interface{}) error { f, ok := v.(unmarshalFaster) if ok { if d.fs == nil { d.fs = fflib.NewFFLexer(data) } else { d.fs.Reset(data) } return f.UnmarshalJSONFFLexer(d.fs, fflib.FFParse_map_start) } um, ok := v.(json.Unmarshaler) if ok { return um.UnmarshalJSON...
go
func (d *Decoder) Decode(data []byte, v interface{}) error { f, ok := v.(unmarshalFaster) if ok { if d.fs == nil { d.fs = fflib.NewFFLexer(data) } else { d.fs.Reset(data) } return f.UnmarshalJSONFFLexer(d.fs, fflib.FFParse_map_start) } um, ok := v.(json.Unmarshaler) if ok { return um.UnmarshalJSON...
[ "func", "(", "d", "*", "Decoder", ")", "Decode", "(", "data", "[", "]", "byte", ",", "v", "interface", "{", "}", ")", "error", "{", "f", ",", "ok", ":=", "v", ".", "(", "unmarshalFaster", ")", "\n", "if", "ok", "{", "if", "d", ".", "fs", "=="...
// Decode the data in the supplied data slice.
[ "Decode", "the", "data", "in", "the", "supplied", "data", "slice", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/decoder.go#L41-L57
29,761
pquerna/ffjson
ffjson/decoder.go
DecodeReader
func (d *Decoder) DecodeReader(r io.Reader, v interface{}) error { _, ok := v.(unmarshalFaster) _, ok2 := v.(json.Unmarshaler) if ok || ok2 { data, err := ioutil.ReadAll(r) if err != nil { return err } defer fflib.Pool(data) return d.Decode(data, v) } dec := json.NewDecoder(r) return dec.Decode(v) }
go
func (d *Decoder) DecodeReader(r io.Reader, v interface{}) error { _, ok := v.(unmarshalFaster) _, ok2 := v.(json.Unmarshaler) if ok || ok2 { data, err := ioutil.ReadAll(r) if err != nil { return err } defer fflib.Pool(data) return d.Decode(data, v) } dec := json.NewDecoder(r) return dec.Decode(v) }
[ "func", "(", "d", "*", "Decoder", ")", "DecodeReader", "(", "r", "io", ".", "Reader", ",", "v", "interface", "{", "}", ")", "error", "{", "_", ",", "ok", ":=", "v", ".", "(", "unmarshalFaster", ")", "\n", "_", ",", "ok2", ":=", "v", ".", "(", ...
// Decode the data from the supplied reader. // You should expect that data is read into memory before it is decoded.
[ "Decode", "the", "data", "from", "the", "supplied", "reader", ".", "You", "should", "expect", "that", "data", "is", "read", "into", "memory", "before", "it", "is", "decoded", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/decoder.go#L61-L74
29,762
pquerna/ffjson
fflib/v1/internal/atof.go
readFloat
func readFloat(s []byte) (mantissa uint64, exp int, neg, trunc, ok bool) { const uint64digits = 19 i := 0 // optional sign if i >= len(s) { return } switch { case s[i] == '+': i++ case s[i] == '-': neg = true i++ } // digits sawdot := false sawdigits := false nd := 0 ndMant := 0 dp := 0 for ; ...
go
func readFloat(s []byte) (mantissa uint64, exp int, neg, trunc, ok bool) { const uint64digits = 19 i := 0 // optional sign if i >= len(s) { return } switch { case s[i] == '+': i++ case s[i] == '-': neg = true i++ } // digits sawdot := false sawdigits := false nd := 0 ndMant := 0 dp := 0 for ; ...
[ "func", "readFloat", "(", "s", "[", "]", "byte", ")", "(", "mantissa", "uint64", ",", "exp", "int", ",", "neg", ",", "trunc", ",", "ok", "bool", ")", "{", "const", "uint64digits", "=", "19", "\n", "i", ":=", "0", "\n\n", "// optional sign", "if", "...
// readFloat reads a decimal mantissa and exponent from a float // string representation. It sets ok to false if the number could // not fit return types or is invalid.
[ "readFloat", "reads", "a", "decimal", "mantissa", "and", "exponent", "from", "a", "float", "string", "representation", ".", "It", "sets", "ok", "to", "false", "if", "the", "number", "could", "not", "fit", "return", "types", "or", "is", "invalid", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/internal/atof.go#L176-L270
29,763
pquerna/ffjson
fflib/v1/internal/ftoa.go
appendFloat
func appendFloat(dst []byte, f float64, fmt byte, prec int, bitSize int) []byte { return genericFtoa(dst, f, fmt, prec, bitSize) }
go
func appendFloat(dst []byte, f float64, fmt byte, prec int, bitSize int) []byte { return genericFtoa(dst, f, fmt, prec, bitSize) }
[ "func", "appendFloat", "(", "dst", "[", "]", "byte", ",", "f", "float64", ",", "fmt", "byte", ",", "prec", "int", ",", "bitSize", "int", ")", "[", "]", "byte", "{", "return", "genericFtoa", "(", "dst", ",", "f", ",", "fmt", ",", "prec", ",", "bit...
// AppendFloat appends the string form of the floating-point number f, // as generated by FormatFloat, to dst and returns the extended buffer.
[ "AppendFloat", "appends", "the", "string", "form", "of", "the", "floating", "-", "point", "number", "f", "as", "generated", "by", "FormatFloat", "to", "dst", "and", "returns", "the", "extended", "buffer", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/internal/ftoa.go#L50-L52
29,764
pquerna/ffjson
ffjson/encoder.go
NewEncoder
func NewEncoder(w io.Writer) *Encoder { return &Encoder{w: w, enc: json.NewEncoder(w)} }
go
func NewEncoder(w io.Writer) *Encoder { return &Encoder{w: w, enc: json.NewEncoder(w)} }
[ "func", "NewEncoder", "(", "w", "io", ".", "Writer", ")", "*", "Encoder", "{", "return", "&", "Encoder", "{", "w", ":", "w", ",", "enc", ":", "json", ".", "NewEncoder", "(", "w", ")", "}", "\n", "}" ]
// NewEncoder returns a reusable Encoder. // Output will be written to the supplied writer.
[ "NewEncoder", "returns", "a", "reusable", "Encoder", ".", "Output", "will", "be", "written", "to", "the", "supplied", "writer", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/encoder.go#L50-L52
29,765
pquerna/ffjson
ffjson/encoder.go
Encode
func (e *Encoder) Encode(v interface{}) error { f, ok := v.(marshalerFaster) if ok { e.buf.Reset() err := f.MarshalJSONBuf(&e.buf) if err != nil { return err } _, err = io.Copy(e.w, &e.buf) return err } return e.enc.Encode(v) }
go
func (e *Encoder) Encode(v interface{}) error { f, ok := v.(marshalerFaster) if ok { e.buf.Reset() err := f.MarshalJSONBuf(&e.buf) if err != nil { return err } _, err = io.Copy(e.w, &e.buf) return err } return e.enc.Encode(v) }
[ "func", "(", "e", "*", "Encoder", ")", "Encode", "(", "v", "interface", "{", "}", ")", "error", "{", "f", ",", "ok", ":=", "v", ".", "(", "marshalerFaster", ")", "\n", "if", "ok", "{", "e", ".", "buf", ".", "Reset", "(", ")", "\n", "err", ":=...
// Encode the data in the supplied value to the stream // given on creation. // When the function returns the output has been // written to the stream.
[ "Encode", "the", "data", "in", "the", "supplied", "value", "to", "the", "stream", "given", "on", "creation", ".", "When", "the", "function", "returns", "the", "output", "has", "been", "written", "to", "the", "stream", "." ]
e517b90714f7c0eabe6d2e570a5886ae077d6db6
https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/encoder.go#L58-L72
29,766
araddon/dateparse
parseany.go
MustParse
func MustParse(datestr string) time.Time { p, err := parseTime(datestr, nil) if err != nil { panic(err.Error()) } t, err := p.parse() if err != nil { panic(err.Error()) } return t }
go
func MustParse(datestr string) time.Time { p, err := parseTime(datestr, nil) if err != nil { panic(err.Error()) } t, err := p.parse() if err != nil { panic(err.Error()) } return t }
[ "func", "MustParse", "(", "datestr", "string", ")", "time", ".", "Time", "{", "p", ",", "err", ":=", "parseTime", "(", "datestr", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", ...
// MustParse parse a date, and panic if it can't be parsed. Used for testing. // Not recommended for most use-cases.
[ "MustParse", "parse", "a", "date", "and", "panic", "if", "it", "can", "t", "be", "parsed", ".", "Used", "for", "testing", ".", "Not", "recommended", "for", "most", "use", "-", "cases", "." ]
0d74ffceef83c568c4c47a6e74de8ee5c5955048
https://github.com/araddon/dateparse/blob/0d74ffceef83c568c4c47a6e74de8ee5c5955048/parseany.go#L169-L179
29,767
ulule/limiter
limiter.go
New
func New(store Store, rate Rate, options ...Option) *Limiter { opt := Options{ IPv4Mask: DefaultIPv4Mask, IPv6Mask: DefaultIPv6Mask, TrustForwardHeader: false, } for _, o := range options { o(&opt) } return &Limiter{ Store: store, Rate: rate, Options: opt, } }
go
func New(store Store, rate Rate, options ...Option) *Limiter { opt := Options{ IPv4Mask: DefaultIPv4Mask, IPv6Mask: DefaultIPv6Mask, TrustForwardHeader: false, } for _, o := range options { o(&opt) } return &Limiter{ Store: store, Rate: rate, Options: opt, } }
[ "func", "New", "(", "store", "Store", ",", "rate", "Rate", ",", "options", "...", "Option", ")", "*", "Limiter", "{", "opt", ":=", "Options", "{", "IPv4Mask", ":", "DefaultIPv4Mask", ",", "IPv6Mask", ":", "DefaultIPv6Mask", ",", "TrustForwardHeader", ":", ...
// New returns an instance of Limiter.
[ "New", "returns", "an", "instance", "of", "Limiter", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/limiter.go#L31-L45
29,768
ulule/limiter
limiter.go
Peek
func (limiter *Limiter) Peek(ctx context.Context, key string) (Context, error) { return limiter.Store.Peek(ctx, key, limiter.Rate) }
go
func (limiter *Limiter) Peek(ctx context.Context, key string) (Context, error) { return limiter.Store.Peek(ctx, key, limiter.Rate) }
[ "func", "(", "limiter", "*", "Limiter", ")", "Peek", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "(", "Context", ",", "error", ")", "{", "return", "limiter", ".", "Store", ".", "Peek", "(", "ctx", ",", "key", ",", "limiter", "...
// Peek returns the limit for given identifier, without modification on current values.
[ "Peek", "returns", "the", "limit", "for", "given", "identifier", "without", "modification", "on", "current", "values", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/limiter.go#L53-L55
29,769
ulule/limiter
drivers/middleware/stdlib/middleware.go
Handler
func (middleware *Middleware) Handler(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { context, err := middleware.Limiter.Get(r.Context(), middleware.Limiter.GetIPKey(r)) if err != nil { middleware.OnError(w, r, err) return } w.Header().Add("X-RateLim...
go
func (middleware *Middleware) Handler(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { context, err := middleware.Limiter.Get(r.Context(), middleware.Limiter.GetIPKey(r)) if err != nil { middleware.OnError(w, r, err) return } w.Header().Add("X-RateLim...
[ "func", "(", "middleware", "*", "Middleware", ")", "Handler", "(", "h", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", ...
// Handler the middleware handler.
[ "Handler", "the", "middleware", "handler", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/stdlib/middleware.go#L34-L53
29,770
ulule/limiter
drivers/store/common/context.go
GetContextFromState
func GetContextFromState(now time.Time, rate limiter.Rate, expiration time.Time, count int64) limiter.Context { limit := rate.Limit remaining := int64(0) reached := true if count <= limit { remaining = limit - count reached = false } reset := expiration.Unix() return limiter.Context{ Limit: limit, ...
go
func GetContextFromState(now time.Time, rate limiter.Rate, expiration time.Time, count int64) limiter.Context { limit := rate.Limit remaining := int64(0) reached := true if count <= limit { remaining = limit - count reached = false } reset := expiration.Unix() return limiter.Context{ Limit: limit, ...
[ "func", "GetContextFromState", "(", "now", "time", ".", "Time", ",", "rate", "limiter", ".", "Rate", ",", "expiration", "time", ".", "Time", ",", "count", "int64", ")", "limiter", ".", "Context", "{", "limit", ":=", "rate", ".", "Limit", "\n", "remaining...
// GetContextFromState generate a new limiter.Context from given state.
[ "GetContextFromState", "generate", "a", "new", "limiter", ".", "Context", "from", "given", "state", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/common/context.go#L10-L28
29,771
ulule/limiter
drivers/store/memory/cache.go
Run
func (cleaner *cleaner) Run(cache *Cache) { ticker := time.NewTicker(cleaner.interval) for { select { case <-ticker.C: cache.Clean() case <-cleaner.stop: ticker.Stop() return } } }
go
func (cleaner *cleaner) Run(cache *Cache) { ticker := time.NewTicker(cleaner.interval) for { select { case <-ticker.C: cache.Clean() case <-cleaner.stop: ticker.Stop() return } } }
[ "func", "(", "cleaner", "*", "cleaner", ")", "Run", "(", "cache", "*", "Cache", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "cleaner", ".", "interval", ")", "\n", "for", "{", "select", "{", "case", "<-", "ticker", ".", "C", ":", "cache...
// Run will periodically delete expired keys from given cache until GC notify that it should stop.
[ "Run", "will", "periodically", "delete", "expired", "keys", "from", "given", "cache", "until", "GC", "notify", "that", "it", "should", "stop", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L24-L35
29,772
ulule/limiter
drivers/store/memory/cache.go
startCleaner
func startCleaner(cache *Cache, interval time.Duration) { cleaner := &cleaner{ interval: interval, stop: make(chan bool), } cache.cleaner = cleaner go cleaner.Run(cache) }
go
func startCleaner(cache *Cache, interval time.Duration) { cleaner := &cleaner{ interval: interval, stop: make(chan bool), } cache.cleaner = cleaner go cleaner.Run(cache) }
[ "func", "startCleaner", "(", "cache", "*", "Cache", ",", "interval", "time", ".", "Duration", ")", "{", "cleaner", ":=", "&", "cleaner", "{", "interval", ":", "interval", ",", "stop", ":", "make", "(", "chan", "bool", ")", ",", "}", "\n\n", "cache", ...
// startCleaner will start a cleaner goroutine for given cache.
[ "startCleaner", "will", "start", "a", "cleaner", "goroutine", "for", "given", "cache", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L43-L51
29,773
ulule/limiter
drivers/store/memory/cache.go
Expired
func (counter Counter) Expired() bool { if counter.Expiration == 0 { return false } return time.Now().UnixNano() > counter.Expiration }
go
func (counter Counter) Expired() bool { if counter.Expiration == 0 { return false } return time.Now().UnixNano() > counter.Expiration }
[ "func", "(", "counter", "Counter", ")", "Expired", "(", ")", "bool", "{", "if", "counter", ".", "Expiration", "==", "0", "{", "return", "false", "\n", "}", "\n", "return", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ">", "counter", "."...
// Expired returns true if the counter has expired.
[ "Expired", "returns", "true", "if", "the", "counter", "has", "expired", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L60-L65
29,774
ulule/limiter
drivers/store/memory/cache.go
NewCache
func NewCache(cleanInterval time.Duration) *CacheWrapper { cache := &Cache{ counters: map[string]Counter{}, } wrapper := &CacheWrapper{Cache: cache} if cleanInterval > 0 { startCleaner(cache, cleanInterval) runtime.SetFinalizer(wrapper, stopCleaner) } return wrapper }
go
func NewCache(cleanInterval time.Duration) *CacheWrapper { cache := &Cache{ counters: map[string]Counter{}, } wrapper := &CacheWrapper{Cache: cache} if cleanInterval > 0 { startCleaner(cache, cleanInterval) runtime.SetFinalizer(wrapper, stopCleaner) } return wrapper }
[ "func", "NewCache", "(", "cleanInterval", "time", ".", "Duration", ")", "*", "CacheWrapper", "{", "cache", ":=", "&", "Cache", "{", "counters", ":", "map", "[", "string", "]", "Counter", "{", "}", ",", "}", "\n\n", "wrapper", ":=", "&", "CacheWrapper", ...
// NewCache returns a new cache.
[ "NewCache", "returns", "a", "new", "cache", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L75-L89
29,775
ulule/limiter
drivers/store/memory/cache.go
Increment
func (cache *Cache) Increment(key string, value int64, duration time.Duration) (int64, time.Time) { cache.mutex.Lock() counter, ok := cache.counters[key] if !ok || counter.Expired() { expiration := time.Now().Add(duration).UnixNano() counter = Counter{ Value: value, Expiration: expiration, } cac...
go
func (cache *Cache) Increment(key string, value int64, duration time.Duration) (int64, time.Time) { cache.mutex.Lock() counter, ok := cache.counters[key] if !ok || counter.Expired() { expiration := time.Now().Add(duration).UnixNano() counter = Counter{ Value: value, Expiration: expiration, } cac...
[ "func", "(", "cache", "*", "Cache", ")", "Increment", "(", "key", "string", ",", "value", "int64", ",", "duration", "time", ".", "Duration", ")", "(", "int64", ",", "time", ".", "Time", ")", "{", "cache", ".", "mutex", ".", "Lock", "(", ")", "\n\n"...
// Increment increments given value on key. // If key is undefined or expired, it will create it.
[ "Increment", "increments", "given", "value", "on", "key", ".", "If", "key", "is", "undefined", "or", "expired", "it", "will", "create", "it", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L93-L118
29,776
ulule/limiter
drivers/store/memory/cache.go
Get
func (cache *Cache) Get(key string, duration time.Duration) (int64, time.Time) { cache.mutex.RLock() counter, ok := cache.counters[key] if !ok || counter.Expired() { expiration := time.Now().Add(duration).UnixNano() cache.mutex.RUnlock() return 0, time.Unix(0, expiration) } value := counter.Value expirati...
go
func (cache *Cache) Get(key string, duration time.Duration) (int64, time.Time) { cache.mutex.RLock() counter, ok := cache.counters[key] if !ok || counter.Expired() { expiration := time.Now().Add(duration).UnixNano() cache.mutex.RUnlock() return 0, time.Unix(0, expiration) } value := counter.Value expirati...
[ "func", "(", "cache", "*", "Cache", ")", "Get", "(", "key", "string", ",", "duration", "time", ".", "Duration", ")", "(", "int64", ",", "time", ".", "Time", ")", "{", "cache", ".", "mutex", ".", "RLock", "(", ")", "\n\n", "counter", ",", "ok", ":...
// Get returns key's value and expiration.
[ "Get", "returns", "key", "s", "value", "and", "expiration", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L121-L136
29,777
ulule/limiter
drivers/store/memory/cache.go
Clean
func (cache *Cache) Clean() { now := time.Now().UnixNano() cache.mutex.Lock() for key, counter := range cache.counters { if now > counter.Expiration { delete(cache.counters, key) } } cache.mutex.Unlock() }
go
func (cache *Cache) Clean() { now := time.Now().UnixNano() cache.mutex.Lock() for key, counter := range cache.counters { if now > counter.Expiration { delete(cache.counters, key) } } cache.mutex.Unlock() }
[ "func", "(", "cache", "*", "Cache", ")", "Clean", "(", ")", "{", "now", ":=", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", "\n\n", "cache", ".", "mutex", ".", "Lock", "(", ")", "\n", "for", "key", ",", "counter", ":=", "range", "cac...
// Clean will deleted any expired keys.
[ "Clean", "will", "deleted", "any", "expired", "keys", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/cache.go#L139-L149
29,778
ulule/limiter
drivers/middleware/gin/middleware.go
Handle
func (middleware *Middleware) Handle(c *gin.Context) { key := middleware.KeyGetter(c) context, err := middleware.Limiter.Get(c, key) if err != nil { middleware.OnError(c, err) c.Abort() return } c.Header("X-RateLimit-Limit", strconv.FormatInt(context.Limit, 10)) c.Header("X-RateLimit-Remaining", strconv.Fo...
go
func (middleware *Middleware) Handle(c *gin.Context) { key := middleware.KeyGetter(c) context, err := middleware.Limiter.Get(c, key) if err != nil { middleware.OnError(c, err) c.Abort() return } c.Header("X-RateLimit-Limit", strconv.FormatInt(context.Limit, 10)) c.Header("X-RateLimit-Remaining", strconv.Fo...
[ "func", "(", "middleware", "*", "Middleware", ")", "Handle", "(", "c", "*", "gin", ".", "Context", ")", "{", "key", ":=", "middleware", ".", "KeyGetter", "(", "c", ")", "\n", "context", ",", "err", ":=", "middleware", ".", "Limiter", ".", "Get", "(",...
// Handle gin request.
[ "Handle", "gin", "request", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/gin/middleware.go#L38-L58
29,779
ulule/limiter
drivers/middleware/gin/options.go
WithErrorHandler
func WithErrorHandler(handler ErrorHandler) Option { return option(func(middleware *Middleware) { middleware.OnError = handler }) }
go
func WithErrorHandler(handler ErrorHandler) Option { return option(func(middleware *Middleware) { middleware.OnError = handler }) }
[ "func", "WithErrorHandler", "(", "handler", "ErrorHandler", ")", "Option", "{", "return", "option", "(", "func", "(", "middleware", "*", "Middleware", ")", "{", "middleware", ".", "OnError", "=", "handler", "\n", "}", ")", "\n", "}" ]
// WithErrorHandler will configure the Middleware to use the given ErrorHandler.
[ "WithErrorHandler", "will", "configure", "the", "Middleware", "to", "use", "the", "given", "ErrorHandler", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/gin/options.go#L24-L28
29,780
ulule/limiter
drivers/middleware/gin/options.go
WithLimitReachedHandler
func WithLimitReachedHandler(handler LimitReachedHandler) Option { return option(func(middleware *Middleware) { middleware.OnLimitReached = handler }) }
go
func WithLimitReachedHandler(handler LimitReachedHandler) Option { return option(func(middleware *Middleware) { middleware.OnLimitReached = handler }) }
[ "func", "WithLimitReachedHandler", "(", "handler", "LimitReachedHandler", ")", "Option", "{", "return", "option", "(", "func", "(", "middleware", "*", "Middleware", ")", "{", "middleware", ".", "OnLimitReached", "=", "handler", "\n", "}", ")", "\n", "}" ]
// WithLimitReachedHandler will configure the Middleware to use the given LimitReachedHandler.
[ "WithLimitReachedHandler", "will", "configure", "the", "Middleware", "to", "use", "the", "given", "LimitReachedHandler", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/gin/options.go#L39-L43
29,781
ulule/limiter
drivers/middleware/gin/options.go
WithKeyGetter
func WithKeyGetter(KeyGetter KeyGetter) Option { return option(func(middleware *Middleware) { middleware.KeyGetter = KeyGetter }) }
go
func WithKeyGetter(KeyGetter KeyGetter) Option { return option(func(middleware *Middleware) { middleware.KeyGetter = KeyGetter }) }
[ "func", "WithKeyGetter", "(", "KeyGetter", "KeyGetter", ")", "Option", "{", "return", "option", "(", "func", "(", "middleware", "*", "Middleware", ")", "{", "middleware", ".", "KeyGetter", "=", "KeyGetter", "\n", "}", ")", "\n", "}" ]
// WithKeyGetter will configure the Middleware to use the given KeyGetter
[ "WithKeyGetter", "will", "configure", "the", "Middleware", "to", "use", "the", "given", "KeyGetter" ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/gin/options.go#L54-L58
29,782
ulule/limiter
rate.go
NewRateFromFormatted
func NewRateFromFormatted(formatted string) (Rate, error) { rate := Rate{} values := strings.Split(formatted, "-") if len(values) != 2 { return rate, errors.Errorf("incorrect format '%s'", formatted) } periods := map[string]time.Duration{ "S": time.Second, // Second "M": time.Minute, // Minute "H": time....
go
func NewRateFromFormatted(formatted string) (Rate, error) { rate := Rate{} values := strings.Split(formatted, "-") if len(values) != 2 { return rate, errors.Errorf("incorrect format '%s'", formatted) } periods := map[string]time.Duration{ "S": time.Second, // Second "M": time.Minute, // Minute "H": time....
[ "func", "NewRateFromFormatted", "(", "formatted", "string", ")", "(", "Rate", ",", "error", ")", "{", "rate", ":=", "Rate", "{", "}", "\n\n", "values", ":=", "strings", ".", "Split", "(", "formatted", ",", "\"", "\"", ")", "\n", "if", "len", "(", "va...
// NewRateFromFormatted returns the rate from the formatted version.
[ "NewRateFromFormatted", "returns", "the", "rate", "from", "the", "formatted", "version", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/rate.go#L19-L53
29,783
ulule/limiter
options.go
WithIPv4Mask
func WithIPv4Mask(mask net.IPMask) Option { return func(o *Options) { o.IPv4Mask = mask } }
go
func WithIPv4Mask(mask net.IPMask) Option { return func(o *Options) { o.IPv4Mask = mask } }
[ "func", "WithIPv4Mask", "(", "mask", "net", ".", "IPMask", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "{", "o", ".", "IPv4Mask", "=", "mask", "\n", "}", "\n", "}" ]
// WithIPv4Mask will configure the limiter to use given mask for IPv4 address.
[ "WithIPv4Mask", "will", "configure", "the", "limiter", "to", "use", "given", "mask", "for", "IPv4", "address", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/options.go#L21-L25
29,784
ulule/limiter
options.go
WithIPv6Mask
func WithIPv6Mask(mask net.IPMask) Option { return func(o *Options) { o.IPv6Mask = mask } }
go
func WithIPv6Mask(mask net.IPMask) Option { return func(o *Options) { o.IPv6Mask = mask } }
[ "func", "WithIPv6Mask", "(", "mask", "net", ".", "IPMask", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "{", "o", ".", "IPv6Mask", "=", "mask", "\n", "}", "\n", "}" ]
// WithIPv6Mask will configure the limiter to use given mask for IPv6 address.
[ "WithIPv6Mask", "will", "configure", "the", "limiter", "to", "use", "given", "mask", "for", "IPv6", "address", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/options.go#L28-L32
29,785
ulule/limiter
drivers/middleware/stdlib/options.go
DefaultErrorHandler
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error) { panic(err) }
go
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error) { panic(err) }
[ "func", "DefaultErrorHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "err", "error", ")", "{", "panic", "(", "err", ")", "\n", "}" ]
// DefaultErrorHandler is the default ErrorHandler used by a new Middleware.
[ "DefaultErrorHandler", "is", "the", "default", "ErrorHandler", "used", "by", "a", "new", "Middleware", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/stdlib/options.go#L29-L31
29,786
ulule/limiter
drivers/middleware/stdlib/options.go
DefaultLimitReachedHandler
func DefaultLimitReachedHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Limit exceeded", http.StatusTooManyRequests) }
go
func DefaultLimitReachedHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Limit exceeded", http.StatusTooManyRequests) }
[ "func", "DefaultLimitReachedHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusTooManyRequests", ")", "\n", "}" ]
// DefaultLimitReachedHandler is the default LimitReachedHandler used by a new Middleware.
[ "DefaultLimitReachedHandler", "is", "the", "default", "LimitReachedHandler", "used", "by", "a", "new", "Middleware", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/middleware/stdlib/options.go#L44-L46
29,787
ulule/limiter
drivers/store/redis/store.go
NewStore
func NewStore(client Client) (limiter.Store, error) { return NewStoreWithOptions(client, limiter.StoreOptions{ Prefix: limiter.DefaultPrefix, CleanUpInterval: limiter.DefaultCleanUpInterval, MaxRetry: limiter.DefaultMaxRetry, }) }
go
func NewStore(client Client) (limiter.Store, error) { return NewStoreWithOptions(client, limiter.StoreOptions{ Prefix: limiter.DefaultPrefix, CleanUpInterval: limiter.DefaultCleanUpInterval, MaxRetry: limiter.DefaultMaxRetry, }) }
[ "func", "NewStore", "(", "client", "Client", ")", "(", "limiter", ".", "Store", ",", "error", ")", "{", "return", "NewStoreWithOptions", "(", "client", ",", "limiter", ".", "StoreOptions", "{", "Prefix", ":", "limiter", ".", "DefaultPrefix", ",", "CleanUpInt...
// NewStore returns an instance of redis store with defaults.
[ "NewStore", "returns", "an", "instance", "of", "redis", "store", "with", "defaults", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L37-L43
29,788
ulule/limiter
drivers/store/redis/store.go
NewStoreWithOptions
func NewStoreWithOptions(client Client, options limiter.StoreOptions) (limiter.Store, error) { store := &Store{ client: client, Prefix: options.Prefix, MaxRetry: options.MaxRetry, } if store.MaxRetry <= 0 { store.MaxRetry = 1 } _, err := store.ping() if err != nil { return nil, err } return sto...
go
func NewStoreWithOptions(client Client, options limiter.StoreOptions) (limiter.Store, error) { store := &Store{ client: client, Prefix: options.Prefix, MaxRetry: options.MaxRetry, } if store.MaxRetry <= 0 { store.MaxRetry = 1 } _, err := store.ping() if err != nil { return nil, err } return sto...
[ "func", "NewStoreWithOptions", "(", "client", "Client", ",", "options", "limiter", ".", "StoreOptions", ")", "(", "limiter", ".", "Store", ",", "error", ")", "{", "store", ":=", "&", "Store", "{", "client", ":", "client", ",", "Prefix", ":", "options", "...
// NewStoreWithOptions returns an instance of redis store with options.
[ "NewStoreWithOptions", "returns", "an", "instance", "of", "redis", "store", "with", "options", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L46-L63
29,789
ulule/limiter
drivers/store/redis/store.go
peekValue
func peekValue(rtx *libredis.Tx, key string) (int64, time.Duration, error) { pipe := rtx.Pipeline() value := pipe.Get(key) expire := pipe.PTTL(key) _, err := pipe.Exec() if err != nil && err != libredis.Nil { return 0, 0, err } count, err := value.Int64() if err != nil && err != libredis.Nil { return 0, 0...
go
func peekValue(rtx *libredis.Tx, key string) (int64, time.Duration, error) { pipe := rtx.Pipeline() value := pipe.Get(key) expire := pipe.PTTL(key) _, err := pipe.Exec() if err != nil && err != libredis.Nil { return 0, 0, err } count, err := value.Int64() if err != nil && err != libredis.Nil { return 0, 0...
[ "func", "peekValue", "(", "rtx", "*", "libredis", ".", "Tx", ",", "key", "string", ")", "(", "int64", ",", "time", ".", "Duration", ",", "error", ")", "{", "pipe", ":=", "rtx", ".", "Pipeline", "(", ")", "\n", "value", ":=", "pipe", ".", "Get", "...
// peekValue will retrieve the counter and its expiration for given key.
[ "peekValue", "will", "retrieve", "the", "counter", "and", "its", "expiration", "for", "given", "key", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L149-L170
29,790
ulule/limiter
drivers/store/redis/store.go
setValue
func setValue(rtx *libredis.Tx, key string, expiration time.Duration) (bool, error) { value := rtx.SetNX(key, 1, expiration) created, err := value.Result() if err != nil { return false, err } return created, nil }
go
func setValue(rtx *libredis.Tx, key string, expiration time.Duration) (bool, error) { value := rtx.SetNX(key, 1, expiration) created, err := value.Result() if err != nil { return false, err } return created, nil }
[ "func", "setValue", "(", "rtx", "*", "libredis", ".", "Tx", ",", "key", "string", ",", "expiration", "time", ".", "Duration", ")", "(", "bool", ",", "error", ")", "{", "value", ":=", "rtx", ".", "SetNX", "(", "key", ",", "1", ",", "expiration", ")"...
// setValue will try to initialize a new counter if given key doesn't exists.
[ "setValue", "will", "try", "to", "initialize", "a", "new", "counter", "if", "given", "key", "doesn", "t", "exists", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L184-L193
29,791
ulule/limiter
drivers/store/redis/store.go
updateValue
func updateValue(rtx *libredis.Tx, key string, expiration time.Duration) (int64, time.Duration, error) { pipe := rtx.Pipeline() value := pipe.Incr(key) expire := pipe.PTTL(key) _, err := pipe.Exec() if err != nil { return 0, 0, err } count, err := value.Result() if err != nil { return 0, 0, err } ttl, ...
go
func updateValue(rtx *libredis.Tx, key string, expiration time.Duration) (int64, time.Duration, error) { pipe := rtx.Pipeline() value := pipe.Incr(key) expire := pipe.PTTL(key) _, err := pipe.Exec() if err != nil { return 0, 0, err } count, err := value.Result() if err != nil { return 0, 0, err } ttl, ...
[ "func", "updateValue", "(", "rtx", "*", "libredis", ".", "Tx", ",", "key", "string", ",", "expiration", "time", ".", "Duration", ")", "(", "int64", ",", "time", ".", "Duration", ",", "error", ")", "{", "pipe", ":=", "rtx", ".", "Pipeline", "(", ")", ...
// updateValue will try to increment the counter identified by given key.
[ "updateValue", "will", "try", "to", "increment", "the", "counter", "identified", "by", "given", "key", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L213-L252
29,792
ulule/limiter
drivers/store/redis/store.go
ping
func (store *Store) ping() (bool, error) { cmd := store.client.Ping() pong, err := cmd.Result() if err != nil { return false, errors.Wrap(err, "limiter: cannot ping redis server") } return (pong == "PONG"), nil }
go
func (store *Store) ping() (bool, error) { cmd := store.client.Ping() pong, err := cmd.Result() if err != nil { return false, errors.Wrap(err, "limiter: cannot ping redis server") } return (pong == "PONG"), nil }
[ "func", "(", "store", "*", "Store", ")", "ping", "(", ")", "(", "bool", ",", "error", ")", "{", "cmd", ":=", "store", ".", "client", ".", "Ping", "(", ")", "\n\n", "pong", ",", "err", ":=", "cmd", ".", "Result", "(", ")", "\n", "if", "err", "...
// ping checks if redis is alive.
[ "ping", "checks", "if", "redis", "is", "alive", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/redis/store.go#L255-L264
29,793
ulule/limiter
drivers/store/memory/store.go
NewStore
func NewStore() limiter.Store { return NewStoreWithOptions(limiter.StoreOptions{ Prefix: limiter.DefaultPrefix, CleanUpInterval: limiter.DefaultCleanUpInterval, }) }
go
func NewStore() limiter.Store { return NewStoreWithOptions(limiter.StoreOptions{ Prefix: limiter.DefaultPrefix, CleanUpInterval: limiter.DefaultCleanUpInterval, }) }
[ "func", "NewStore", "(", ")", "limiter", ".", "Store", "{", "return", "NewStoreWithOptions", "(", "limiter", ".", "StoreOptions", "{", "Prefix", ":", "limiter", ".", "DefaultPrefix", ",", "CleanUpInterval", ":", "limiter", ".", "DefaultCleanUpInterval", ",", "}"...
// NewStore creates a new instance of memory store with defaults.
[ "NewStore", "creates", "a", "new", "instance", "of", "memory", "store", "with", "defaults", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/store.go#L21-L26
29,794
ulule/limiter
drivers/store/memory/store.go
NewStoreWithOptions
func NewStoreWithOptions(options limiter.StoreOptions) limiter.Store { return &Store{ Prefix: options.Prefix, cache: NewCache(options.CleanUpInterval), } }
go
func NewStoreWithOptions(options limiter.StoreOptions) limiter.Store { return &Store{ Prefix: options.Prefix, cache: NewCache(options.CleanUpInterval), } }
[ "func", "NewStoreWithOptions", "(", "options", "limiter", ".", "StoreOptions", ")", "limiter", ".", "Store", "{", "return", "&", "Store", "{", "Prefix", ":", "options", ".", "Prefix", ",", "cache", ":", "NewCache", "(", "options", ".", "CleanUpInterval", ")"...
// NewStoreWithOptions creates a new instance of memory store with options.
[ "NewStoreWithOptions", "creates", "a", "new", "instance", "of", "memory", "store", "with", "options", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/drivers/store/memory/store.go#L29-L34
29,795
ulule/limiter
network.go
GetIPKey
func (limiter *Limiter) GetIPKey(r *http.Request) string { return limiter.GetIPWithMask(r).String() }
go
func (limiter *Limiter) GetIPKey(r *http.Request) string { return limiter.GetIPWithMask(r).String() }
[ "func", "(", "limiter", "*", "Limiter", ")", "GetIPKey", "(", "r", "*", "http", ".", "Request", ")", "string", "{", "return", "limiter", ".", "GetIPWithMask", "(", "r", ")", ".", "String", "(", ")", "\n", "}" ]
// GetIPKey extracts IP from request and returns hashed IP to use as store key.
[ "GetIPKey", "extracts", "IP", "from", "request", "and", "returns", "hashed", "IP", "to", "use", "as", "store", "key", "." ]
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/network.go#L27-L29
29,796
ulule/limiter
network.go
GetIP
func GetIP(r *http.Request, options ...Options) net.IP { if len(options) >= 1 && options[0].TrustForwardHeader { ip := r.Header.Get("X-Forwarded-For") if ip != "" { parts := strings.SplitN(ip, ",", 2) part := strings.TrimSpace(parts[0]) return net.ParseIP(part) } ip = strings.TrimSpace(r.Header.Get("...
go
func GetIP(r *http.Request, options ...Options) net.IP { if len(options) >= 1 && options[0].TrustForwardHeader { ip := r.Header.Get("X-Forwarded-For") if ip != "" { parts := strings.SplitN(ip, ",", 2) part := strings.TrimSpace(parts[0]) return net.ParseIP(part) } ip = strings.TrimSpace(r.Header.Get("...
[ "func", "GetIP", "(", "r", "*", "http", ".", "Request", ",", "options", "...", "Options", ")", "net", ".", "IP", "{", "if", "len", "(", "options", ")", ">=", "1", "&&", "options", "[", "0", "]", ".", "TrustForwardHeader", "{", "ip", ":=", "r", "....
// GetIP returns IP address from request. // If options is defined and TrustForwardHeader is true, it will lookup IP in // X-Forwarded-For and X-Real-IP headers.
[ "GetIP", "returns", "IP", "address", "from", "request", ".", "If", "options", "is", "defined", "and", "TrustForwardHeader", "is", "true", "it", "will", "lookup", "IP", "in", "X", "-", "Forwarded", "-", "For", "and", "X", "-", "Real", "-", "IP", "headers"...
d1a9972e76c234debd9f4cf39c847ea174f0faa4
https://github.com/ulule/limiter/blob/d1a9972e76c234debd9f4cf39c847ea174f0faa4/network.go#L34-L56
29,797
ory/fosite
internal/token_handler.go
NewMockTokenEndpointHandler
func NewMockTokenEndpointHandler(ctrl *gomock.Controller) *MockTokenEndpointHandler { mock := &MockTokenEndpointHandler{ctrl: ctrl} mock.recorder = &MockTokenEndpointHandlerMockRecorder{mock} return mock }
go
func NewMockTokenEndpointHandler(ctrl *gomock.Controller) *MockTokenEndpointHandler { mock := &MockTokenEndpointHandler{ctrl: ctrl} mock.recorder = &MockTokenEndpointHandlerMockRecorder{mock} return mock }
[ "func", "NewMockTokenEndpointHandler", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockTokenEndpointHandler", "{", "mock", ":=", "&", "MockTokenEndpointHandler", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockTokenEndp...
// NewMockTokenEndpointHandler creates a new mock instance
[ "NewMockTokenEndpointHandler", "creates", "a", "new", "mock", "instance" ]
27bbe0033273157ea449310c064675127e2550e6
https://github.com/ory/fosite/blob/27bbe0033273157ea449310c064675127e2550e6/internal/token_handler.go#L28-L32
29,798
ory/fosite
internal/token_handler.go
HandleTokenEndpointRequest
func (m *MockTokenEndpointHandler) HandleTokenEndpointRequest(arg0 context.Context, arg1 fosite.AccessRequester) error { ret := m.ctrl.Call(m, "HandleTokenEndpointRequest", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockTokenEndpointHandler) HandleTokenEndpointRequest(arg0 context.Context, arg1 fosite.AccessRequester) error { ret := m.ctrl.Call(m, "HandleTokenEndpointRequest", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockTokenEndpointHandler", ")", "HandleTokenEndpointRequest", "(", "arg0", "context", ".", "Context", ",", "arg1", "fosite", ".", "AccessRequester", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"",...
// HandleTokenEndpointRequest mocks base method
[ "HandleTokenEndpointRequest", "mocks", "base", "method" ]
27bbe0033273157ea449310c064675127e2550e6
https://github.com/ory/fosite/blob/27bbe0033273157ea449310c064675127e2550e6/internal/token_handler.go#L40-L44
29,799
ory/fosite
internal/token_handler.go
PopulateTokenEndpointResponse
func (m *MockTokenEndpointHandler) PopulateTokenEndpointResponse(arg0 context.Context, arg1 fosite.AccessRequester, arg2 fosite.AccessResponder) error { ret := m.ctrl.Call(m, "PopulateTokenEndpointResponse", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockTokenEndpointHandler) PopulateTokenEndpointResponse(arg0 context.Context, arg1 fosite.AccessRequester, arg2 fosite.AccessResponder) error { ret := m.ctrl.Call(m, "PopulateTokenEndpointResponse", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockTokenEndpointHandler", ")", "PopulateTokenEndpointResponse", "(", "arg0", "context", ".", "Context", ",", "arg1", "fosite", ".", "AccessRequester", ",", "arg2", "fosite", ".", "AccessResponder", ")", "error", "{", "ret", ":=", "m", ...
// PopulateTokenEndpointResponse mocks base method
[ "PopulateTokenEndpointResponse", "mocks", "base", "method" ]
27bbe0033273157ea449310c064675127e2550e6
https://github.com/ory/fosite/blob/27bbe0033273157ea449310c064675127e2550e6/internal/token_handler.go#L52-L56