repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
faiface/pixel | geometry.go | H | func (r Rect) H() float64 {
return r.Max.Y - r.Min.Y
} | go | func (r Rect) H() float64 {
return r.Max.Y - r.Min.Y
} | [
"func",
"(",
"r",
"Rect",
")",
"H",
"(",
")",
"float64",
"{",
"return",
"r",
".",
"Max",
".",
"Y",
"-",
"r",
".",
"Min",
".",
"Y",
"\n",
"}"
] | // H returns the height of the Rect. | [
"H",
"returns",
"the",
"height",
"of",
"the",
"Rect",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L521-L523 | train |
faiface/pixel | geometry.go | Edges | func (r Rect) Edges() [4]Line {
corners := r.Vertices()
return [4]Line{
{A: corners[0], B: corners[1]},
{A: corners[1], B: corners[2]},
{A: corners[2], B: corners[3]},
{A: corners[3], B: corners[0]},
}
} | go | func (r Rect) Edges() [4]Line {
corners := r.Vertices()
return [4]Line{
{A: corners[0], B: corners[1]},
{A: corners[1], B: corners[2]},
{A: corners[2], B: corners[3]},
{A: corners[3], B: corners[0]},
}
} | [
"func",
"(",
"r",
"Rect",
")",
"Edges",
"(",
")",
"[",
"4",
"]",
"Line",
"{",
"corners",
":=",
"r",
".",
"Vertices",
"(",
")",
"\n",
"return",
"[",
"4",
"]",
"Line",
"{",
"{",
"A",
":",
"corners",
"[",
"0",
"]",
",",
"B",
":",
"corners",
"[",
"1",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"1",
"]",
",",
"B",
":",
"corners",
"[",
"2",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"2",
"]",
",",
"B",
":",
"corners",
"[",
"3",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"3",
"]",
",",
"B",
":",
"corners",
"[",
"0",
"]",
"}",
",",
"}",
"\n",
"}"
] | // Edges will return the four lines which make up the edges of the rectangle. | [
"Edges",
"will",
"return",
"the",
"four",
"lines",
"which",
"make",
"up",
"the",
"edges",
"of",
"the",
"rectangle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L536-L545 | train |
faiface/pixel | geometry.go | ResizedMin | func (r Rect) ResizedMin(size Vec) Rect {
return Rect{
Min: r.Min,
Max: r.Min.Add(size),
}
} | go | func (r Rect) ResizedMin(size Vec) Rect {
return Rect{
Min: r.Min,
Max: r.Min.Add(size),
}
} | [
"func",
"(",
"r",
"Rect",
")",
"ResizedMin",
"(",
"size",
"Vec",
")",
"Rect",
"{",
"return",
"Rect",
"{",
"Min",
":",
"r",
".",
"Min",
",",
"Max",
":",
"r",
".",
"Min",
".",
"Add",
"(",
"size",
")",
",",
"}",
"\n",
"}"
] | // ResizedMin returns the Rect resized to the given size while keeping the position of the Rect's
// Min.
//
// Sizes of zero area are safe here. | [
"ResizedMin",
"returns",
"the",
"Rect",
"resized",
"to",
"the",
"given",
"size",
"while",
"keeping",
"the",
"position",
"of",
"the",
"Rect",
"s",
"Min",
".",
"Sizes",
"of",
"zero",
"area",
"are",
"safe",
"here",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L584-L589 | train |
faiface/pixel | geometry.go | Union | func (r Rect) Union(s Rect) Rect {
return R(
math.Min(r.Min.X, s.Min.X),
math.Min(r.Min.Y, s.Min.Y),
math.Max(r.Max.X, s.Max.X),
math.Max(r.Max.Y, s.Max.Y),
)
} | go | func (r Rect) Union(s Rect) Rect {
return R(
math.Min(r.Min.X, s.Min.X),
math.Min(r.Min.Y, s.Min.Y),
math.Max(r.Max.X, s.Max.X),
math.Max(r.Max.Y, s.Max.Y),
)
} | [
"func",
"(",
"r",
"Rect",
")",
"Union",
"(",
"s",
"Rect",
")",
"Rect",
"{",
"return",
"R",
"(",
"math",
".",
"Min",
"(",
"r",
".",
"Min",
".",
"X",
",",
"s",
".",
"Min",
".",
"X",
")",
",",
"math",
".",
"Min",
"(",
"r",
".",
"Min",
".",
"Y",
",",
"s",
".",
"Min",
".",
"Y",
")",
",",
"math",
".",
"Max",
"(",
"r",
".",
"Max",
".",
"X",
",",
"s",
".",
"Max",
".",
"X",
")",
",",
"math",
".",
"Max",
"(",
"r",
".",
"Max",
".",
"Y",
",",
"s",
".",
"Max",
".",
"Y",
")",
",",
")",
"\n",
"}"
] | // Union returns the minimal Rect which covers both r and s. Rects r and s must be normalized. | [
"Union",
"returns",
"the",
"minimal",
"Rect",
"which",
"covers",
"both",
"r",
"and",
"s",
".",
"Rects",
"r",
"and",
"s",
"must",
"be",
"normalized",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L597-L604 | train |
faiface/pixel | geometry.go | IntersectionPoints | func (r Rect) IntersectionPoints(l Line) []Vec {
// Use map keys to ensure unique points
pointMap := make(map[Vec]struct{})
for _, edge := range r.Edges() {
if intersect, ok := l.Intersect(edge); ok {
pointMap[intersect] = struct{}{}
}
}
points := make([]Vec, 0, len(pointMap))
for point := range pointMap {
points = append(points, point)
}
// Order the points
if len(points) == 2 {
if points[1].To(l.A).Len() < points[0].To(l.A).Len() {
return []Vec{points[1], points[0]}
}
}
return points
} | go | func (r Rect) IntersectionPoints(l Line) []Vec {
// Use map keys to ensure unique points
pointMap := make(map[Vec]struct{})
for _, edge := range r.Edges() {
if intersect, ok := l.Intersect(edge); ok {
pointMap[intersect] = struct{}{}
}
}
points := make([]Vec, 0, len(pointMap))
for point := range pointMap {
points = append(points, point)
}
// Order the points
if len(points) == 2 {
if points[1].To(l.A).Len() < points[0].To(l.A).Len() {
return []Vec{points[1], points[0]}
}
}
return points
} | [
"func",
"(",
"r",
"Rect",
")",
"IntersectionPoints",
"(",
"l",
"Line",
")",
"[",
"]",
"Vec",
"{",
"pointMap",
":=",
"make",
"(",
"map",
"[",
"Vec",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"edge",
":=",
"range",
"r",
".",
"Edges",
"(",
")",
"{",
"if",
"intersect",
",",
"ok",
":=",
"l",
".",
"Intersect",
"(",
"edge",
")",
";",
"ok",
"{",
"pointMap",
"[",
"intersect",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"points",
":=",
"make",
"(",
"[",
"]",
"Vec",
",",
"0",
",",
"len",
"(",
"pointMap",
")",
")",
"\n",
"for",
"point",
":=",
"range",
"pointMap",
"{",
"points",
"=",
"append",
"(",
"points",
",",
"point",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"points",
")",
"==",
"2",
"{",
"if",
"points",
"[",
"1",
"]",
".",
"To",
"(",
"l",
".",
"A",
")",
".",
"Len",
"(",
")",
"<",
"points",
"[",
"0",
"]",
".",
"To",
"(",
"l",
".",
"A",
")",
".",
"Len",
"(",
")",
"{",
"return",
"[",
"]",
"Vec",
"{",
"points",
"[",
"1",
"]",
",",
"points",
"[",
"0",
"]",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"points",
"\n",
"}"
] | // IntersectionPoints returns all the points where the Rect intersects with the line provided. This can be zero, one or
// two points, depending on the location of the shapes. The points of intersection will be returned in order of
// closest-to-l.A to closest-to-l.B. | [
"IntersectionPoints",
"returns",
"all",
"the",
"points",
"where",
"the",
"Rect",
"intersects",
"with",
"the",
"line",
"provided",
".",
"This",
"can",
"be",
"zero",
"one",
"or",
"two",
"points",
"depending",
"on",
"the",
"location",
"of",
"the",
"shapes",
".",
"The",
"points",
"of",
"intersection",
"will",
"be",
"returned",
"in",
"order",
"of",
"closest",
"-",
"to",
"-",
"l",
".",
"A",
"to",
"closest",
"-",
"to",
"-",
"l",
".",
"B",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L642-L665 | train |
faiface/pixel | geometry.go | Vertices | func (r Rect) Vertices() [4]Vec {
return [4]Vec{
r.Min,
V(r.Min.X, r.Max.Y),
r.Max,
V(r.Max.X, r.Min.Y),
}
} | go | func (r Rect) Vertices() [4]Vec {
return [4]Vec{
r.Min,
V(r.Min.X, r.Max.Y),
r.Max,
V(r.Max.X, r.Min.Y),
}
} | [
"func",
"(",
"r",
"Rect",
")",
"Vertices",
"(",
")",
"[",
"4",
"]",
"Vec",
"{",
"return",
"[",
"4",
"]",
"Vec",
"{",
"r",
".",
"Min",
",",
"V",
"(",
"r",
".",
"Min",
".",
"X",
",",
"r",
".",
"Max",
".",
"Y",
")",
",",
"r",
".",
"Max",
",",
"V",
"(",
"r",
".",
"Max",
".",
"X",
",",
"r",
".",
"Min",
".",
"Y",
")",
",",
"}",
"\n",
"}"
] | // Vertices returns a slice of the four corners which make up the rectangle. | [
"Vertices",
"returns",
"a",
"slice",
"of",
"the",
"four",
"corners",
"which",
"make",
"up",
"the",
"rectangle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L668-L675 | train |
faiface/pixel | geometry.go | C | func C(center Vec, radius float64) Circle {
return Circle{
Center: center,
Radius: radius,
}
} | go | func C(center Vec, radius float64) Circle {
return Circle{
Center: center,
Radius: radius,
}
} | [
"func",
"C",
"(",
"center",
"Vec",
",",
"radius",
"float64",
")",
"Circle",
"{",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"radius",
",",
"}",
"\n",
"}"
] | // C returns a new Circle with the given radius and center coordinates.
//
// Note that a negative radius is valid. | [
"C",
"returns",
"a",
"new",
"Circle",
"with",
"the",
"given",
"radius",
"and",
"center",
"coordinates",
".",
"Note",
"that",
"a",
"negative",
"radius",
"is",
"valid",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L688-L693 | train |
faiface/pixel | geometry.go | Area | func (c Circle) Area() float64 {
return math.Pi * math.Pow(c.Radius, 2)
} | go | func (c Circle) Area() float64 {
return math.Pi * math.Pow(c.Radius, 2)
} | [
"func",
"(",
"c",
"Circle",
")",
"Area",
"(",
")",
"float64",
"{",
"return",
"math",
".",
"Pi",
"*",
"math",
".",
"Pow",
"(",
"c",
".",
"Radius",
",",
"2",
")",
"\n",
"}"
] | // Area returns the area of the Circle. | [
"Area",
"returns",
"the",
"area",
"of",
"the",
"Circle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L716-L718 | train |
faiface/pixel | geometry.go | Moved | func (c Circle) Moved(delta Vec) Circle {
return Circle{
Center: c.Center.Add(delta),
Radius: c.Radius,
}
} | go | func (c Circle) Moved(delta Vec) Circle {
return Circle{
Center: c.Center.Add(delta),
Radius: c.Radius,
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Moved",
"(",
"delta",
"Vec",
")",
"Circle",
"{",
"return",
"Circle",
"{",
"Center",
":",
"c",
".",
"Center",
".",
"Add",
"(",
"delta",
")",
",",
"Radius",
":",
"c",
".",
"Radius",
",",
"}",
"\n",
"}"
] | // Moved returns the Circle moved by the given vector delta. | [
"Moved",
"returns",
"the",
"Circle",
"moved",
"by",
"the",
"given",
"vector",
"delta",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L721-L726 | train |
faiface/pixel | geometry.go | maxCircle | func maxCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return d
}
return c
} | go | func maxCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return d
}
return c
} | [
"func",
"maxCircle",
"(",
"c",
",",
"d",
"Circle",
")",
"Circle",
"{",
"if",
"c",
".",
"Radius",
"<",
"d",
".",
"Radius",
"{",
"return",
"d",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // maxCircle will return the larger circle based on the radius. | [
"maxCircle",
"will",
"return",
"the",
"larger",
"circle",
"based",
"on",
"the",
"radius",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L753-L758 | train |
faiface/pixel | geometry.go | minCircle | func minCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return c
}
return d
} | go | func minCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return c
}
return d
} | [
"func",
"minCircle",
"(",
"c",
",",
"d",
"Circle",
")",
"Circle",
"{",
"if",
"c",
".",
"Radius",
"<",
"d",
".",
"Radius",
"{",
"return",
"c",
"\n",
"}",
"\n",
"return",
"d",
"\n",
"}"
] | // minCircle will return the smaller circle based on the radius. | [
"minCircle",
"will",
"return",
"the",
"smaller",
"circle",
"based",
"on",
"the",
"radius",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L761-L766 | train |
faiface/pixel | geometry.go | Union | func (c Circle) Union(d Circle) Circle {
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
// Get distance between centers
dist := c.Center.To(d.Center).Len()
// If the bigger Circle encompasses the smaller one, we have the result
if dist+smallerC.Radius <= biggerC.Radius {
return biggerC
}
// Calculate radius for encompassing Circle
r := (dist + biggerC.Radius + smallerC.Radius) / 2
// Calculate center for encompassing Circle
theta := .5 + (biggerC.Radius-smallerC.Radius)/(2*dist)
center := Lerp(smallerC.Center, biggerC.Center, theta)
return Circle{
Center: center,
Radius: r,
}
} | go | func (c Circle) Union(d Circle) Circle {
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
// Get distance between centers
dist := c.Center.To(d.Center).Len()
// If the bigger Circle encompasses the smaller one, we have the result
if dist+smallerC.Radius <= biggerC.Radius {
return biggerC
}
// Calculate radius for encompassing Circle
r := (dist + biggerC.Radius + smallerC.Radius) / 2
// Calculate center for encompassing Circle
theta := .5 + (biggerC.Radius-smallerC.Radius)/(2*dist)
center := Lerp(smallerC.Center, biggerC.Center, theta)
return Circle{
Center: center,
Radius: r,
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Union",
"(",
"d",
"Circle",
")",
"Circle",
"{",
"biggerC",
":=",
"maxCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"smallerC",
":=",
"minCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"dist",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"\n",
"if",
"dist",
"+",
"smallerC",
".",
"Radius",
"<=",
"biggerC",
".",
"Radius",
"{",
"return",
"biggerC",
"\n",
"}",
"\n",
"r",
":=",
"(",
"dist",
"+",
"biggerC",
".",
"Radius",
"+",
"smallerC",
".",
"Radius",
")",
"/",
"2",
"\n",
"theta",
":=",
".5",
"+",
"(",
"biggerC",
".",
"Radius",
"-",
"smallerC",
".",
"Radius",
")",
"/",
"(",
"2",
"*",
"dist",
")",
"\n",
"center",
":=",
"Lerp",
"(",
"smallerC",
".",
"Center",
",",
"biggerC",
".",
"Center",
",",
"theta",
")",
"\n",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"r",
",",
"}",
"\n",
"}"
] | // Union returns the minimal Circle which covers both `c` and `d`. | [
"Union",
"returns",
"the",
"minimal",
"Circle",
"which",
"covers",
"both",
"c",
"and",
"d",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L769-L792 | train |
faiface/pixel | geometry.go | Intersect | func (c Circle) Intersect(d Circle) Circle {
// Check if one of the circles encompasses the other; if so, return that one
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
return biggerC
}
// Calculate the midpoint between the two radii
// Distance between centers
dist := c.Center.To(d.Center).Len()
// Difference between radii
diff := dist - (c.Radius + d.Radius)
// Distance from c.Center to the weighted midpoint
distToMidpoint := c.Radius + 0.5*diff
// Weighted midpoint
center := Lerp(c.Center, d.Center, distToMidpoint/dist)
// No need to calculate radius if the circles do not overlap
if c.Center.To(d.Center).Len() >= c.Radius+d.Radius {
return C(center, 0)
}
radius := c.Center.To(d.Center).Len() - (c.Radius + d.Radius)
return Circle{
Center: center,
Radius: math.Abs(radius),
}
} | go | func (c Circle) Intersect(d Circle) Circle {
// Check if one of the circles encompasses the other; if so, return that one
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
return biggerC
}
// Calculate the midpoint between the two radii
// Distance between centers
dist := c.Center.To(d.Center).Len()
// Difference between radii
diff := dist - (c.Radius + d.Radius)
// Distance from c.Center to the weighted midpoint
distToMidpoint := c.Radius + 0.5*diff
// Weighted midpoint
center := Lerp(c.Center, d.Center, distToMidpoint/dist)
// No need to calculate radius if the circles do not overlap
if c.Center.To(d.Center).Len() >= c.Radius+d.Radius {
return C(center, 0)
}
radius := c.Center.To(d.Center).Len() - (c.Radius + d.Radius)
return Circle{
Center: center,
Radius: math.Abs(radius),
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Intersect",
"(",
"d",
"Circle",
")",
"Circle",
"{",
"biggerC",
":=",
"maxCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"smallerC",
":=",
"minCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"if",
"biggerC",
".",
"Radius",
">=",
"biggerC",
".",
"Center",
".",
"To",
"(",
"smallerC",
".",
"Center",
")",
".",
"Len",
"(",
")",
"+",
"smallerC",
".",
"Radius",
"{",
"return",
"biggerC",
"\n",
"}",
"\n",
"dist",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"\n",
"diff",
":=",
"dist",
"-",
"(",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
")",
"\n",
"distToMidpoint",
":=",
"c",
".",
"Radius",
"+",
"0.5",
"*",
"diff",
"\n",
"center",
":=",
"Lerp",
"(",
"c",
".",
"Center",
",",
"d",
".",
"Center",
",",
"distToMidpoint",
"/",
"dist",
")",
"\n",
"if",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
">=",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
"{",
"return",
"C",
"(",
"center",
",",
"0",
")",
"\n",
"}",
"\n",
"radius",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"-",
"(",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
")",
"\n",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"math",
".",
"Abs",
"(",
"radius",
")",
",",
"}",
"\n",
"}"
] | // Intersect returns the maximal Circle which is covered by both `c` and `d`.
//
// If `c` and `d` don't overlap, this function returns a zero-sized circle at the centerpoint between the two Circle's
// centers. | [
"Intersect",
"returns",
"the",
"maximal",
"Circle",
"which",
"is",
"covered",
"by",
"both",
"c",
"and",
"d",
".",
"If",
"c",
"and",
"d",
"don",
"t",
"overlap",
"this",
"function",
"returns",
"a",
"zero",
"-",
"sized",
"circle",
"at",
"the",
"centerpoint",
"between",
"the",
"two",
"Circle",
"s",
"centers",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L798-L828 | train |
faiface/pixel | geometry.go | Moved | func (m Matrix) Moved(delta Vec) Matrix {
m[4], m[5] = m[4]+delta.X, m[5]+delta.Y
return m
} | go | func (m Matrix) Moved(delta Vec) Matrix {
m[4], m[5] = m[4]+delta.X, m[5]+delta.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"Moved",
"(",
"delta",
"Vec",
")",
"Matrix",
"{",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"delta",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"delta",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // Moved moves everything by the delta vector. | [
"Moved",
"moves",
"everything",
"by",
"the",
"delta",
"vector",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1038-L1041 | train |
faiface/pixel | geometry.go | ScaledXY | func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix {
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m[0], m[2], m[4] = m[0]*scale.X, m[2]*scale.X, m[4]*scale.X
m[1], m[3], m[5] = m[1]*scale.Y, m[3]*scale.Y, m[5]*scale.Y
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | go | func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix {
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m[0], m[2], m[4] = m[0]*scale.X, m[2]*scale.X, m[4]*scale.X
m[1], m[3], m[5] = m[1]*scale.Y, m[3]*scale.Y, m[5]*scale.Y
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"ScaledXY",
"(",
"around",
"Vec",
",",
"scale",
"Vec",
")",
"Matrix",
"{",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"-",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"-",
"around",
".",
"Y",
"\n",
"m",
"[",
"0",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"4",
"]",
"=",
"m",
"[",
"0",
"]",
"*",
"scale",
".",
"X",
",",
"m",
"[",
"2",
"]",
"*",
"scale",
".",
"X",
",",
"m",
"[",
"4",
"]",
"*",
"scale",
".",
"X",
"\n",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"3",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"1",
"]",
"*",
"scale",
".",
"Y",
",",
"m",
"[",
"3",
"]",
"*",
"scale",
".",
"Y",
",",
"m",
"[",
"5",
"]",
"*",
"scale",
".",
"Y",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"around",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // ScaledXY scales everything around a given point by the scale factor in each axis respectively. | [
"ScaledXY",
"scales",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"scale",
"factor",
"in",
"each",
"axis",
"respectively",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1044-L1050 | train |
faiface/pixel | geometry.go | Scaled | func (m Matrix) Scaled(around Vec, scale float64) Matrix {
return m.ScaledXY(around, V(scale, scale))
} | go | func (m Matrix) Scaled(around Vec, scale float64) Matrix {
return m.ScaledXY(around, V(scale, scale))
} | [
"func",
"(",
"m",
"Matrix",
")",
"Scaled",
"(",
"around",
"Vec",
",",
"scale",
"float64",
")",
"Matrix",
"{",
"return",
"m",
".",
"ScaledXY",
"(",
"around",
",",
"V",
"(",
"scale",
",",
"scale",
")",
")",
"\n",
"}"
] | // Scaled scales everything around a given point by the scale factor. | [
"Scaled",
"scales",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"scale",
"factor",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1053-L1055 | train |
faiface/pixel | geometry.go | Rotated | func (m Matrix) Rotated(around Vec, angle float64) Matrix {
sint, cost := math.Sincos(angle)
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m = m.Chained(Matrix{cost, sint, -sint, cost, 0, 0})
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | go | func (m Matrix) Rotated(around Vec, angle float64) Matrix {
sint, cost := math.Sincos(angle)
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m = m.Chained(Matrix{cost, sint, -sint, cost, 0, 0})
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"Rotated",
"(",
"around",
"Vec",
",",
"angle",
"float64",
")",
"Matrix",
"{",
"sint",
",",
"cost",
":=",
"math",
".",
"Sincos",
"(",
"angle",
")",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"-",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"-",
"around",
".",
"Y",
"\n",
"m",
"=",
"m",
".",
"Chained",
"(",
"Matrix",
"{",
"cost",
",",
"sint",
",",
"-",
"sint",
",",
"cost",
",",
"0",
",",
"0",
"}",
")",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"around",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // Rotated rotates everything around a given point by the given angle in radians. | [
"Rotated",
"rotates",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"given",
"angle",
"in",
"radians",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1058-L1064 | train |
faiface/pixel | geometry.go | Chained | func (m Matrix) Chained(next Matrix) Matrix {
return Matrix{
next[0]*m[0] + next[2]*m[1],
next[1]*m[0] + next[3]*m[1],
next[0]*m[2] + next[2]*m[3],
next[1]*m[2] + next[3]*m[3],
next[0]*m[4] + next[2]*m[5] + next[4],
next[1]*m[4] + next[3]*m[5] + next[5],
}
} | go | func (m Matrix) Chained(next Matrix) Matrix {
return Matrix{
next[0]*m[0] + next[2]*m[1],
next[1]*m[0] + next[3]*m[1],
next[0]*m[2] + next[2]*m[3],
next[1]*m[2] + next[3]*m[3],
next[0]*m[4] + next[2]*m[5] + next[4],
next[1]*m[4] + next[3]*m[5] + next[5],
}
} | [
"func",
"(",
"m",
"Matrix",
")",
"Chained",
"(",
"next",
"Matrix",
")",
"Matrix",
"{",
"return",
"Matrix",
"{",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"0",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"1",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"0",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"1",
"]",
",",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"2",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"3",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"2",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"3",
"]",
",",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"4",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"5",
"]",
"+",
"next",
"[",
"4",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"4",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"5",
"]",
"+",
"next",
"[",
"5",
"]",
",",
"}",
"\n",
"}"
] | // Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied
// after the transformations of this Matrix. | [
"Chained",
"adds",
"another",
"Matrix",
"to",
"this",
"one",
".",
"All",
"tranformations",
"by",
"the",
"next",
"Matrix",
"will",
"be",
"applied",
"after",
"the",
"transformations",
"of",
"this",
"Matrix",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1068-L1077 | train |
faiface/pixel | text/text.go | BoundsOf | func (txt *Text) BoundsOf(s string) pixel.Rect {
dot := txt.Dot
prevR := txt.prevR
bounds := pixel.Rect{}
for _, r := range s {
var control bool
dot, control = txt.controlRune(r, dot)
if control {
continue
}
var b pixel.Rect
_, _, b, dot = txt.Atlas().DrawRune(prevR, r, dot)
if bounds.W()*bounds.H() == 0 {
bounds = b
} else {
bounds = bounds.Union(b)
}
prevR = r
}
return bounds
} | go | func (txt *Text) BoundsOf(s string) pixel.Rect {
dot := txt.Dot
prevR := txt.prevR
bounds := pixel.Rect{}
for _, r := range s {
var control bool
dot, control = txt.controlRune(r, dot)
if control {
continue
}
var b pixel.Rect
_, _, b, dot = txt.Atlas().DrawRune(prevR, r, dot)
if bounds.W()*bounds.H() == 0 {
bounds = b
} else {
bounds = bounds.Union(b)
}
prevR = r
}
return bounds
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"BoundsOf",
"(",
"s",
"string",
")",
"pixel",
".",
"Rect",
"{",
"dot",
":=",
"txt",
".",
"Dot",
"\n",
"prevR",
":=",
"txt",
".",
"prevR",
"\n",
"bounds",
":=",
"pixel",
".",
"Rect",
"{",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"var",
"control",
"bool",
"\n",
"dot",
",",
"control",
"=",
"txt",
".",
"controlRune",
"(",
"r",
",",
"dot",
")",
"\n",
"if",
"control",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"b",
"pixel",
".",
"Rect",
"\n",
"_",
",",
"_",
",",
"b",
",",
"dot",
"=",
"txt",
".",
"Atlas",
"(",
")",
".",
"DrawRune",
"(",
"prevR",
",",
"r",
",",
"dot",
")",
"\n",
"if",
"bounds",
".",
"W",
"(",
")",
"*",
"bounds",
".",
"H",
"(",
")",
"==",
"0",
"{",
"bounds",
"=",
"b",
"\n",
"}",
"else",
"{",
"bounds",
"=",
"bounds",
".",
"Union",
"(",
"b",
")",
"\n",
"}",
"\n",
"prevR",
"=",
"r",
"\n",
"}",
"\n",
"return",
"bounds",
"\n",
"}"
] | // BoundsOf returns the bounding box of s if it was to be written to the Text right now. | [
"BoundsOf",
"returns",
"the",
"bounding",
"box",
"of",
"s",
"if",
"it",
"was",
"to",
"be",
"written",
"to",
"the",
"Text",
"right",
"now",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L158-L183 | train |
faiface/pixel | text/text.go | Clear | func (txt *Text) Clear() {
txt.prevR = -1
txt.bounds = pixel.Rect{}
txt.tris.SetLen(0)
txt.dirty = true
txt.Dot = txt.Orig
} | go | func (txt *Text) Clear() {
txt.prevR = -1
txt.bounds = pixel.Rect{}
txt.tris.SetLen(0)
txt.dirty = true
txt.Dot = txt.Orig
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"Clear",
"(",
")",
"{",
"txt",
".",
"prevR",
"=",
"-",
"1",
"\n",
"txt",
".",
"bounds",
"=",
"pixel",
".",
"Rect",
"{",
"}",
"\n",
"txt",
".",
"tris",
".",
"SetLen",
"(",
"0",
")",
"\n",
"txt",
".",
"dirty",
"=",
"true",
"\n",
"txt",
".",
"Dot",
"=",
"txt",
".",
"Orig",
"\n",
"}"
] | // Clear removes all written text from the Text. The Dot field is reset to Orig. | [
"Clear",
"removes",
"all",
"written",
"text",
"from",
"the",
"Text",
".",
"The",
"Dot",
"field",
"is",
"reset",
"to",
"Orig",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L186-L192 | train |
faiface/pixel | text/text.go | WriteByte | func (txt *Text) WriteByte(c byte) error {
txt.buf = append(txt.buf, c)
txt.drawBuf()
return nil
} | go | func (txt *Text) WriteByte(c byte) error {
txt.buf = append(txt.buf, c)
txt.drawBuf()
return nil
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"WriteByte",
"(",
"c",
"byte",
")",
"error",
"{",
"txt",
".",
"buf",
"=",
"append",
"(",
"txt",
".",
"buf",
",",
"c",
")",
"\n",
"txt",
".",
"drawBuf",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // WriteByte writes a byte to the Text. This method never fails, always returns nil.
//
// Writing a multi-byte rune byte-by-byte is perfectly supported. | [
"WriteByte",
"writes",
"a",
"byte",
"to",
"the",
"Text",
".",
"This",
"method",
"never",
"fails",
"always",
"returns",
"nil",
".",
"Writing",
"a",
"multi",
"-",
"byte",
"rune",
"byte",
"-",
"by",
"-",
"byte",
"is",
"perfectly",
"supported",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L211-L215 | train |
faiface/pixel | text/text.go | Draw | func (txt *Text) Draw(t pixel.Target, matrix pixel.Matrix) {
txt.DrawColorMask(t, matrix, nil)
} | go | func (txt *Text) Draw(t pixel.Target, matrix pixel.Matrix) {
txt.DrawColorMask(t, matrix, nil)
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"Draw",
"(",
"t",
"pixel",
".",
"Target",
",",
"matrix",
"pixel",
".",
"Matrix",
")",
"{",
"txt",
".",
"DrawColorMask",
"(",
"t",
",",
"matrix",
",",
"nil",
")",
"\n",
"}"
] | // Draw draws all text written to the Text to the provided Target. The text is transformed by the
// provided Matrix.
//
// This method is equivalent to calling DrawColorMask with nil color mask.
//
// If there's a lot of text written to the Text, changing a matrix or a color mask often might hurt
// performance. Consider using your Target's SetMatrix or SetColorMask methods if available. | [
"Draw",
"draws",
"all",
"text",
"written",
"to",
"the",
"Text",
"to",
"the",
"provided",
"Target",
".",
"The",
"text",
"is",
"transformed",
"by",
"the",
"provided",
"Matrix",
".",
"This",
"method",
"is",
"equivalent",
"to",
"calling",
"DrawColorMask",
"with",
"nil",
"color",
"mask",
".",
"If",
"there",
"s",
"a",
"lot",
"of",
"text",
"written",
"to",
"the",
"Text",
"changing",
"a",
"matrix",
"or",
"a",
"color",
"mask",
"often",
"might",
"hurt",
"performance",
".",
"Consider",
"using",
"your",
"Target",
"s",
"SetMatrix",
"or",
"SetColorMask",
"methods",
"if",
"available",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L233-L235 | train |
faiface/pixel | text/text.go | DrawColorMask | func (txt *Text) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.Color) {
if matrix != txt.mat {
txt.mat = matrix
txt.dirty = true
}
if mask == nil {
mask = pixel.Alpha(1)
}
rgba := pixel.ToRGBA(mask)
if rgba != txt.col {
txt.col = rgba
txt.dirty = true
}
if txt.dirty {
txt.trans.SetLen(txt.tris.Len())
txt.trans.Update(&txt.tris)
for i := range txt.trans {
txt.trans[i].Position = txt.mat.Project(txt.trans[i].Position)
txt.trans[i].Color = txt.trans[i].Color.Mul(txt.col)
}
txt.transD.Dirty()
txt.dirty = false
}
txt.transD.Draw(t)
} | go | func (txt *Text) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.Color) {
if matrix != txt.mat {
txt.mat = matrix
txt.dirty = true
}
if mask == nil {
mask = pixel.Alpha(1)
}
rgba := pixel.ToRGBA(mask)
if rgba != txt.col {
txt.col = rgba
txt.dirty = true
}
if txt.dirty {
txt.trans.SetLen(txt.tris.Len())
txt.trans.Update(&txt.tris)
for i := range txt.trans {
txt.trans[i].Position = txt.mat.Project(txt.trans[i].Position)
txt.trans[i].Color = txt.trans[i].Color.Mul(txt.col)
}
txt.transD.Dirty()
txt.dirty = false
}
txt.transD.Draw(t)
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"DrawColorMask",
"(",
"t",
"pixel",
".",
"Target",
",",
"matrix",
"pixel",
".",
"Matrix",
",",
"mask",
"color",
".",
"Color",
")",
"{",
"if",
"matrix",
"!=",
"txt",
".",
"mat",
"{",
"txt",
".",
"mat",
"=",
"matrix",
"\n",
"txt",
".",
"dirty",
"=",
"true",
"\n",
"}",
"\n",
"if",
"mask",
"==",
"nil",
"{",
"mask",
"=",
"pixel",
".",
"Alpha",
"(",
"1",
")",
"\n",
"}",
"\n",
"rgba",
":=",
"pixel",
".",
"ToRGBA",
"(",
"mask",
")",
"\n",
"if",
"rgba",
"!=",
"txt",
".",
"col",
"{",
"txt",
".",
"col",
"=",
"rgba",
"\n",
"txt",
".",
"dirty",
"=",
"true",
"\n",
"}",
"\n",
"if",
"txt",
".",
"dirty",
"{",
"txt",
".",
"trans",
".",
"SetLen",
"(",
"txt",
".",
"tris",
".",
"Len",
"(",
")",
")",
"\n",
"txt",
".",
"trans",
".",
"Update",
"(",
"&",
"txt",
".",
"tris",
")",
"\n",
"for",
"i",
":=",
"range",
"txt",
".",
"trans",
"{",
"txt",
".",
"trans",
"[",
"i",
"]",
".",
"Position",
"=",
"txt",
".",
"mat",
".",
"Project",
"(",
"txt",
".",
"trans",
"[",
"i",
"]",
".",
"Position",
")",
"\n",
"txt",
".",
"trans",
"[",
"i",
"]",
".",
"Color",
"=",
"txt",
".",
"trans",
"[",
"i",
"]",
".",
"Color",
".",
"Mul",
"(",
"txt",
".",
"col",
")",
"\n",
"}",
"\n",
"txt",
".",
"transD",
".",
"Dirty",
"(",
")",
"\n",
"txt",
".",
"dirty",
"=",
"false",
"\n",
"}",
"\n",
"txt",
".",
"transD",
".",
"Draw",
"(",
"t",
")",
"\n",
"}"
] | // DrawColorMask draws all text written to the Text to the provided Target. The text is transformed
// by the provided Matrix and masked by the provided color mask.
//
// If there's a lot of text written to the Text, changing a matrix or a color mask often might hurt
// performance. Consider using your Target's SetMatrix or SetColorMask methods if available. | [
"DrawColorMask",
"draws",
"all",
"text",
"written",
"to",
"the",
"Text",
"to",
"the",
"provided",
"Target",
".",
"The",
"text",
"is",
"transformed",
"by",
"the",
"provided",
"Matrix",
"and",
"masked",
"by",
"the",
"provided",
"color",
"mask",
".",
"If",
"there",
"s",
"a",
"lot",
"of",
"text",
"written",
"to",
"the",
"Text",
"changing",
"a",
"matrix",
"or",
"a",
"color",
"mask",
"often",
"might",
"hurt",
"performance",
".",
"Consider",
"using",
"your",
"Target",
"s",
"SetMatrix",
"or",
"SetColorMask",
"methods",
"if",
"available",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L242-L270 | train |
faiface/pixel | data.go | Slice | func (td *TrianglesData) Slice(i, j int) Triangles {
s := TrianglesData((*td)[i:j])
return &s
} | go | func (td *TrianglesData) Slice(i, j int) Triangles {
s := TrianglesData((*td)[i:j])
return &s
} | [
"func",
"(",
"td",
"*",
"TrianglesData",
")",
"Slice",
"(",
"i",
",",
"j",
"int",
")",
"Triangles",
"{",
"s",
":=",
"TrianglesData",
"(",
"(",
"*",
"td",
")",
"[",
"i",
":",
"j",
"]",
")",
"\n",
"return",
"&",
"s",
"\n",
"}"
] | // Slice returns a sub-Triangles of this TrianglesData. | [
"Slice",
"returns",
"a",
"sub",
"-",
"Triangles",
"of",
"this",
"TrianglesData",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L64-L67 | train |
faiface/pixel | data.go | Update | func (td *TrianglesData) Update(t Triangles) {
if td.Len() != t.Len() {
panic(fmt.Errorf("(%T).Update: invalid triangles length", td))
}
td.updateData(t)
} | go | func (td *TrianglesData) Update(t Triangles) {
if td.Len() != t.Len() {
panic(fmt.Errorf("(%T).Update: invalid triangles length", td))
}
td.updateData(t)
} | [
"func",
"(",
"td",
"*",
"TrianglesData",
")",
"Update",
"(",
"t",
"Triangles",
")",
"{",
"if",
"td",
".",
"Len",
"(",
")",
"!=",
"t",
".",
"Len",
"(",
")",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"(%T).Update: invalid triangles length\"",
",",
"td",
")",
")",
"\n",
"}",
"\n",
"td",
".",
"updateData",
"(",
"t",
")",
"\n",
"}"
] | // Update copies vertex properties from the supplied Triangles into this TrianglesData.
//
// TrianglesPosition, TrianglesColor and TrianglesTexture are supported. | [
"Update",
"copies",
"vertex",
"properties",
"from",
"the",
"supplied",
"Triangles",
"into",
"this",
"TrianglesData",
".",
"TrianglesPosition",
"TrianglesColor",
"and",
"TrianglesTexture",
"are",
"supported",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L97-L102 | train |
faiface/pixel | data.go | Copy | func (td *TrianglesData) Copy() Triangles {
copyTd := MakeTrianglesData(td.Len())
copyTd.Update(td)
return copyTd
} | go | func (td *TrianglesData) Copy() Triangles {
copyTd := MakeTrianglesData(td.Len())
copyTd.Update(td)
return copyTd
} | [
"func",
"(",
"td",
"*",
"TrianglesData",
")",
"Copy",
"(",
")",
"Triangles",
"{",
"copyTd",
":=",
"MakeTrianglesData",
"(",
"td",
".",
"Len",
"(",
")",
")",
"\n",
"copyTd",
".",
"Update",
"(",
"td",
")",
"\n",
"return",
"copyTd",
"\n",
"}"
] | // Copy returns an exact independent copy of this TrianglesData. | [
"Copy",
"returns",
"an",
"exact",
"independent",
"copy",
"of",
"this",
"TrianglesData",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L105-L109 | train |
faiface/pixel | data.go | Picture | func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64) {
return (*td)[i].Picture, (*td)[i].Intensity
} | go | func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64) {
return (*td)[i].Picture, (*td)[i].Intensity
} | [
"func",
"(",
"td",
"*",
"TrianglesData",
")",
"Picture",
"(",
"i",
"int",
")",
"(",
"pic",
"Vec",
",",
"intensity",
"float64",
")",
"{",
"return",
"(",
"*",
"td",
")",
"[",
"i",
"]",
".",
"Picture",
",",
"(",
"*",
"td",
")",
"[",
"i",
"]",
".",
"Intensity",
"\n",
"}"
] | // Picture returns the picture property of i-th vertex. | [
"Picture",
"returns",
"the",
"picture",
"property",
"of",
"i",
"-",
"th",
"vertex",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L122-L124 | train |
faiface/pixel | data.go | MakePictureData | func MakePictureData(rect Rect) *PictureData {
w := int(math.Ceil(rect.Max.X)) - int(math.Floor(rect.Min.X))
h := int(math.Ceil(rect.Max.Y)) - int(math.Floor(rect.Min.Y))
pd := &PictureData{
Stride: w,
Rect: rect,
}
pd.Pix = make([]color.RGBA, w*h)
return pd
} | go | func MakePictureData(rect Rect) *PictureData {
w := int(math.Ceil(rect.Max.X)) - int(math.Floor(rect.Min.X))
h := int(math.Ceil(rect.Max.Y)) - int(math.Floor(rect.Min.Y))
pd := &PictureData{
Stride: w,
Rect: rect,
}
pd.Pix = make([]color.RGBA, w*h)
return pd
} | [
"func",
"MakePictureData",
"(",
"rect",
"Rect",
")",
"*",
"PictureData",
"{",
"w",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"rect",
".",
"Max",
".",
"X",
")",
")",
"-",
"int",
"(",
"math",
".",
"Floor",
"(",
"rect",
".",
"Min",
".",
"X",
")",
")",
"\n",
"h",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"rect",
".",
"Max",
".",
"Y",
")",
")",
"-",
"int",
"(",
"math",
".",
"Floor",
"(",
"rect",
".",
"Min",
".",
"Y",
")",
")",
"\n",
"pd",
":=",
"&",
"PictureData",
"{",
"Stride",
":",
"w",
",",
"Rect",
":",
"rect",
",",
"}",
"\n",
"pd",
".",
"Pix",
"=",
"make",
"(",
"[",
"]",
"color",
".",
"RGBA",
",",
"w",
"*",
"h",
")",
"\n",
"return",
"pd",
"\n",
"}"
] | // MakePictureData creates a zero-initialized PictureData covering the given rectangle. | [
"MakePictureData",
"creates",
"a",
"zero",
"-",
"initialized",
"PictureData",
"covering",
"the",
"given",
"rectangle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L144-L153 | train |
faiface/pixel | data.go | PictureDataFromImage | func PictureDataFromImage(img image.Image) *PictureData {
rgba := image.NewRGBA(img.Bounds())
draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
verticalFlip(rgba)
pd := MakePictureData(R(
float64(rgba.Bounds().Min.X),
float64(rgba.Bounds().Min.Y),
float64(rgba.Bounds().Max.X),
float64(rgba.Bounds().Max.Y),
))
for i := range pd.Pix {
pd.Pix[i].R = rgba.Pix[i*4+0]
pd.Pix[i].G = rgba.Pix[i*4+1]
pd.Pix[i].B = rgba.Pix[i*4+2]
pd.Pix[i].A = rgba.Pix[i*4+3]
}
return pd
} | go | func PictureDataFromImage(img image.Image) *PictureData {
rgba := image.NewRGBA(img.Bounds())
draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
verticalFlip(rgba)
pd := MakePictureData(R(
float64(rgba.Bounds().Min.X),
float64(rgba.Bounds().Min.Y),
float64(rgba.Bounds().Max.X),
float64(rgba.Bounds().Max.Y),
))
for i := range pd.Pix {
pd.Pix[i].R = rgba.Pix[i*4+0]
pd.Pix[i].G = rgba.Pix[i*4+1]
pd.Pix[i].B = rgba.Pix[i*4+2]
pd.Pix[i].A = rgba.Pix[i*4+3]
}
return pd
} | [
"func",
"PictureDataFromImage",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"PictureData",
"{",
"rgba",
":=",
"image",
".",
"NewRGBA",
"(",
"img",
".",
"Bounds",
"(",
")",
")",
"\n",
"draw",
".",
"Draw",
"(",
"rgba",
",",
"rgba",
".",
"Bounds",
"(",
")",
",",
"img",
",",
"img",
".",
"Bounds",
"(",
")",
".",
"Min",
",",
"draw",
".",
"Src",
")",
"\n",
"verticalFlip",
"(",
"rgba",
")",
"\n",
"pd",
":=",
"MakePictureData",
"(",
"R",
"(",
"float64",
"(",
"rgba",
".",
"Bounds",
"(",
")",
".",
"Min",
".",
"X",
")",
",",
"float64",
"(",
"rgba",
".",
"Bounds",
"(",
")",
".",
"Min",
".",
"Y",
")",
",",
"float64",
"(",
"rgba",
".",
"Bounds",
"(",
")",
".",
"Max",
".",
"X",
")",
",",
"float64",
"(",
"rgba",
".",
"Bounds",
"(",
")",
".",
"Max",
".",
"Y",
")",
",",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"pd",
".",
"Pix",
"{",
"pd",
".",
"Pix",
"[",
"i",
"]",
".",
"R",
"=",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"0",
"]",
"\n",
"pd",
".",
"Pix",
"[",
"i",
"]",
".",
"G",
"=",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"1",
"]",
"\n",
"pd",
".",
"Pix",
"[",
"i",
"]",
".",
"B",
"=",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"2",
"]",
"\n",
"pd",
".",
"Pix",
"[",
"i",
"]",
".",
"A",
"=",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"3",
"]",
"\n",
"}",
"\n",
"return",
"pd",
"\n",
"}"
] | // PictureDataFromImage converts an image.Image into PictureData.
//
// The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds. | [
"PictureDataFromImage",
"converts",
"an",
"image",
".",
"Image",
"into",
"PictureData",
".",
"The",
"resulting",
"PictureData",
"s",
"Bounds",
"will",
"be",
"the",
"equivalent",
"of",
"the",
"supplied",
"image",
".",
"Image",
"s",
"Bounds",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L173-L194 | train |
faiface/pixel | data.go | Image | func (pd *PictureData) Image() *image.RGBA {
bounds := image.Rect(
int(math.Floor(pd.Rect.Min.X)),
int(math.Floor(pd.Rect.Min.Y)),
int(math.Ceil(pd.Rect.Max.X)),
int(math.Ceil(pd.Rect.Max.Y)),
)
rgba := image.NewRGBA(bounds)
i := 0
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
off := pd.Index(V(float64(x), float64(y)))
rgba.Pix[i*4+0] = pd.Pix[off].R
rgba.Pix[i*4+1] = pd.Pix[off].G
rgba.Pix[i*4+2] = pd.Pix[off].B
rgba.Pix[i*4+3] = pd.Pix[off].A
i++
}
}
verticalFlip(rgba)
return rgba
} | go | func (pd *PictureData) Image() *image.RGBA {
bounds := image.Rect(
int(math.Floor(pd.Rect.Min.X)),
int(math.Floor(pd.Rect.Min.Y)),
int(math.Ceil(pd.Rect.Max.X)),
int(math.Ceil(pd.Rect.Max.Y)),
)
rgba := image.NewRGBA(bounds)
i := 0
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
off := pd.Index(V(float64(x), float64(y)))
rgba.Pix[i*4+0] = pd.Pix[off].R
rgba.Pix[i*4+1] = pd.Pix[off].G
rgba.Pix[i*4+2] = pd.Pix[off].B
rgba.Pix[i*4+3] = pd.Pix[off].A
i++
}
}
verticalFlip(rgba)
return rgba
} | [
"func",
"(",
"pd",
"*",
"PictureData",
")",
"Image",
"(",
")",
"*",
"image",
".",
"RGBA",
"{",
"bounds",
":=",
"image",
".",
"Rect",
"(",
"int",
"(",
"math",
".",
"Floor",
"(",
"pd",
".",
"Rect",
".",
"Min",
".",
"X",
")",
")",
",",
"int",
"(",
"math",
".",
"Floor",
"(",
"pd",
".",
"Rect",
".",
"Min",
".",
"Y",
")",
")",
",",
"int",
"(",
"math",
".",
"Ceil",
"(",
"pd",
".",
"Rect",
".",
"Max",
".",
"X",
")",
")",
",",
"int",
"(",
"math",
".",
"Ceil",
"(",
"pd",
".",
"Rect",
".",
"Max",
".",
"Y",
")",
")",
",",
")",
"\n",
"rgba",
":=",
"image",
".",
"NewRGBA",
"(",
"bounds",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"y",
":=",
"bounds",
".",
"Min",
".",
"Y",
";",
"y",
"<",
"bounds",
".",
"Max",
".",
"Y",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"bounds",
".",
"Min",
".",
"X",
";",
"x",
"<",
"bounds",
".",
"Max",
".",
"X",
";",
"x",
"++",
"{",
"off",
":=",
"pd",
".",
"Index",
"(",
"V",
"(",
"float64",
"(",
"x",
")",
",",
"float64",
"(",
"y",
")",
")",
")",
"\n",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"0",
"]",
"=",
"pd",
".",
"Pix",
"[",
"off",
"]",
".",
"R",
"\n",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"1",
"]",
"=",
"pd",
".",
"Pix",
"[",
"off",
"]",
".",
"G",
"\n",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"2",
"]",
"=",
"pd",
".",
"Pix",
"[",
"off",
"]",
".",
"B",
"\n",
"rgba",
".",
"Pix",
"[",
"i",
"*",
"4",
"+",
"3",
"]",
"=",
"pd",
".",
"Pix",
"[",
"off",
"]",
".",
"A",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"verticalFlip",
"(",
"rgba",
")",
"\n",
"return",
"rgba",
"\n",
"}"
] | // Image converts PictureData into an image.RGBA.
//
// The resulting image.RGBA's Bounds will be equivalent of the PictureData's Bounds. | [
"Image",
"converts",
"PictureData",
"into",
"an",
"image",
".",
"RGBA",
".",
"The",
"resulting",
"image",
".",
"RGBA",
"s",
"Bounds",
"will",
"be",
"equivalent",
"of",
"the",
"PictureData",
"s",
"Bounds",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L233-L257 | train |
faiface/pixel | data.go | Index | func (pd *PictureData) Index(at Vec) int {
at = at.Sub(pd.Rect.Min.Map(math.Floor))
x, y := int(at.X), int(at.Y)
return y*pd.Stride + x
} | go | func (pd *PictureData) Index(at Vec) int {
at = at.Sub(pd.Rect.Min.Map(math.Floor))
x, y := int(at.X), int(at.Y)
return y*pd.Stride + x
} | [
"func",
"(",
"pd",
"*",
"PictureData",
")",
"Index",
"(",
"at",
"Vec",
")",
"int",
"{",
"at",
"=",
"at",
".",
"Sub",
"(",
"pd",
".",
"Rect",
".",
"Min",
".",
"Map",
"(",
"math",
".",
"Floor",
")",
")",
"\n",
"x",
",",
"y",
":=",
"int",
"(",
"at",
".",
"X",
")",
",",
"int",
"(",
"at",
".",
"Y",
")",
"\n",
"return",
"y",
"*",
"pd",
".",
"Stride",
"+",
"x",
"\n",
"}"
] | // Index returns the index of the pixel at the specified position inside the Pix slice. | [
"Index",
"returns",
"the",
"index",
"of",
"the",
"pixel",
"at",
"the",
"specified",
"position",
"inside",
"the",
"Pix",
"slice",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L260-L264 | train |
faiface/pixel | data.go | Color | func (pd *PictureData) Color(at Vec) RGBA {
if !pd.Rect.Contains(at) {
return RGBA{0, 0, 0, 0}
}
return ToRGBA(pd.Pix[pd.Index(at)])
} | go | func (pd *PictureData) Color(at Vec) RGBA {
if !pd.Rect.Contains(at) {
return RGBA{0, 0, 0, 0}
}
return ToRGBA(pd.Pix[pd.Index(at)])
} | [
"func",
"(",
"pd",
"*",
"PictureData",
")",
"Color",
"(",
"at",
"Vec",
")",
"RGBA",
"{",
"if",
"!",
"pd",
".",
"Rect",
".",
"Contains",
"(",
"at",
")",
"{",
"return",
"RGBA",
"{",
"0",
",",
"0",
",",
"0",
",",
"0",
"}",
"\n",
"}",
"\n",
"return",
"ToRGBA",
"(",
"pd",
".",
"Pix",
"[",
"pd",
".",
"Index",
"(",
"at",
")",
"]",
")",
"\n",
"}"
] | // Color returns the color located at the given position. | [
"Color",
"returns",
"the",
"color",
"located",
"at",
"the",
"given",
"position",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/data.go#L272-L277 | train |
graph-gophers/graphql-go | introspection.go | ToJSON | func (s *Schema) ToJSON() ([]byte, error) {
result := s.exec(context.Background(), introspectionQuery, "", nil, &resolvable.Schema{
Query: &resolvable.Object{},
Schema: *s.schema,
})
if len(result.Errors) != 0 {
panic(result.Errors[0])
}
return json.MarshalIndent(result.Data, "", "\t")
} | go | func (s *Schema) ToJSON() ([]byte, error) {
result := s.exec(context.Background(), introspectionQuery, "", nil, &resolvable.Schema{
Query: &resolvable.Object{},
Schema: *s.schema,
})
if len(result.Errors) != 0 {
panic(result.Errors[0])
}
return json.MarshalIndent(result.Data, "", "\t")
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"ToJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"result",
":=",
"s",
".",
"exec",
"(",
"context",
".",
"Background",
"(",
")",
",",
"introspectionQuery",
",",
"\"\"",
",",
"nil",
",",
"&",
"resolvable",
".",
"Schema",
"{",
"Query",
":",
"&",
"resolvable",
".",
"Object",
"{",
"}",
",",
"Schema",
":",
"*",
"s",
".",
"schema",
",",
"}",
")",
"\n",
"if",
"len",
"(",
"result",
".",
"Errors",
")",
"!=",
"0",
"{",
"panic",
"(",
"result",
".",
"Errors",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"MarshalIndent",
"(",
"result",
".",
"Data",
",",
"\"\"",
",",
"\"\\t\"",
")",
"\n",
"}"
] | // ToJSON encodes the schema in a JSON format used by tools like Relay. | [
"ToJSON",
"encodes",
"the",
"schema",
"in",
"a",
"JSON",
"format",
"used",
"by",
"tools",
"like",
"Relay",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/introspection.go#L17-L26 | train |
graph-gophers/graphql-go | graphql.go | MustParseSchema | func MustParseSchema(schemaString string, resolver interface{}, opts ...SchemaOpt) *Schema {
s, err := ParseSchema(schemaString, resolver, opts...)
if err != nil {
panic(err)
}
return s
} | go | func MustParseSchema(schemaString string, resolver interface{}, opts ...SchemaOpt) *Schema {
s, err := ParseSchema(schemaString, resolver, opts...)
if err != nil {
panic(err)
}
return s
} | [
"func",
"MustParseSchema",
"(",
"schemaString",
"string",
",",
"resolver",
"interface",
"{",
"}",
",",
"opts",
"...",
"SchemaOpt",
")",
"*",
"Schema",
"{",
"s",
",",
"err",
":=",
"ParseSchema",
"(",
"schemaString",
",",
"resolver",
",",
"opts",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // MustParseSchema calls ParseSchema and panics on error. | [
"MustParseSchema",
"calls",
"ParseSchema",
"and",
"panics",
"on",
"error",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/graphql.go#L52-L58 | train |
graph-gophers/graphql-go | graphql.go | Tracer | func Tracer(tracer trace.Tracer) SchemaOpt {
return func(s *Schema) {
s.tracer = tracer
}
} | go | func Tracer(tracer trace.Tracer) SchemaOpt {
return func(s *Schema) {
s.tracer = tracer
}
} | [
"func",
"Tracer",
"(",
"tracer",
"trace",
".",
"Tracer",
")",
"SchemaOpt",
"{",
"return",
"func",
"(",
"s",
"*",
"Schema",
")",
"{",
"s",
".",
"tracer",
"=",
"tracer",
"\n",
"}",
"\n",
"}"
] | // Tracer is used to trace queries and fields. It defaults to trace.OpenTracingTracer. | [
"Tracer",
"is",
"used",
"to",
"trace",
"queries",
"and",
"fields",
".",
"It",
"defaults",
"to",
"trace",
".",
"OpenTracingTracer",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/graphql.go#L109-L113 | train |
graph-gophers/graphql-go | graphql.go | ValidationTracer | func ValidationTracer(tracer trace.ValidationTracer) SchemaOpt {
return func(s *Schema) {
s.validationTracer = tracer
}
} | go | func ValidationTracer(tracer trace.ValidationTracer) SchemaOpt {
return func(s *Schema) {
s.validationTracer = tracer
}
} | [
"func",
"ValidationTracer",
"(",
"tracer",
"trace",
".",
"ValidationTracer",
")",
"SchemaOpt",
"{",
"return",
"func",
"(",
"s",
"*",
"Schema",
")",
"{",
"s",
".",
"validationTracer",
"=",
"tracer",
"\n",
"}",
"\n",
"}"
] | // ValidationTracer is used to trace validation errors. It defaults to trace.NoopValidationTracer. | [
"ValidationTracer",
"is",
"used",
"to",
"trace",
"validation",
"errors",
".",
"It",
"defaults",
"to",
"trace",
".",
"NoopValidationTracer",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/graphql.go#L116-L120 | train |
graph-gophers/graphql-go | graphql.go | Logger | func Logger(logger log.Logger) SchemaOpt {
return func(s *Schema) {
s.logger = logger
}
} | go | func Logger(logger log.Logger) SchemaOpt {
return func(s *Schema) {
s.logger = logger
}
} | [
"func",
"Logger",
"(",
"logger",
"log",
".",
"Logger",
")",
"SchemaOpt",
"{",
"return",
"func",
"(",
"s",
"*",
"Schema",
")",
"{",
"s",
".",
"logger",
"=",
"logger",
"\n",
"}",
"\n",
"}"
] | // Logger is used to log panics during query execution. It defaults to exec.DefaultLogger. | [
"Logger",
"is",
"used",
"to",
"log",
"panics",
"during",
"query",
"execution",
".",
"It",
"defaults",
"to",
"exec",
".",
"DefaultLogger",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/graphql.go#L123-L127 | train |
graph-gophers/graphql-go | graphql.go | Validate | func (s *Schema) Validate(queryString string) []*errors.QueryError {
doc, qErr := query.Parse(queryString)
if qErr != nil {
return []*errors.QueryError{qErr}
}
return validation.Validate(s.schema, doc, s.maxDepth)
} | go | func (s *Schema) Validate(queryString string) []*errors.QueryError {
doc, qErr := query.Parse(queryString)
if qErr != nil {
return []*errors.QueryError{qErr}
}
return validation.Validate(s.schema, doc, s.maxDepth)
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Validate",
"(",
"queryString",
"string",
")",
"[",
"]",
"*",
"errors",
".",
"QueryError",
"{",
"doc",
",",
"qErr",
":=",
"query",
".",
"Parse",
"(",
"queryString",
")",
"\n",
"if",
"qErr",
"!=",
"nil",
"{",
"return",
"[",
"]",
"*",
"errors",
".",
"QueryError",
"{",
"qErr",
"}",
"\n",
"}",
"\n",
"return",
"validation",
".",
"Validate",
"(",
"s",
".",
"schema",
",",
"doc",
",",
"s",
".",
"maxDepth",
")",
"\n",
"}"
] | // Validate validates the given query with the schema. | [
"Validate",
"validates",
"the",
"given",
"query",
"with",
"the",
"schema",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/graphql.go#L146-L153 | train |
graph-gophers/graphql-go | time.go | UnmarshalGraphQL | func (t *Time) UnmarshalGraphQL(input interface{}) error {
switch input := input.(type) {
case time.Time:
t.Time = input
return nil
case string:
var err error
t.Time, err = time.Parse(time.RFC3339, input)
return err
case int:
t.Time = time.Unix(int64(input), 0)
return nil
case float64:
t.Time = time.Unix(int64(input), 0)
return nil
default:
return fmt.Errorf("wrong type")
}
} | go | func (t *Time) UnmarshalGraphQL(input interface{}) error {
switch input := input.(type) {
case time.Time:
t.Time = input
return nil
case string:
var err error
t.Time, err = time.Parse(time.RFC3339, input)
return err
case int:
t.Time = time.Unix(int64(input), 0)
return nil
case float64:
t.Time = time.Unix(int64(input), 0)
return nil
default:
return fmt.Errorf("wrong type")
}
} | [
"func",
"(",
"t",
"*",
"Time",
")",
"UnmarshalGraphQL",
"(",
"input",
"interface",
"{",
"}",
")",
"error",
"{",
"switch",
"input",
":=",
"input",
".",
"(",
"type",
")",
"{",
"case",
"time",
".",
"Time",
":",
"t",
".",
"Time",
"=",
"input",
"\n",
"return",
"nil",
"\n",
"case",
"string",
":",
"var",
"err",
"error",
"\n",
"t",
".",
"Time",
",",
"err",
"=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339",
",",
"input",
")",
"\n",
"return",
"err",
"\n",
"case",
"int",
":",
"t",
".",
"Time",
"=",
"time",
".",
"Unix",
"(",
"int64",
"(",
"input",
")",
",",
"0",
")",
"\n",
"return",
"nil",
"\n",
"case",
"float64",
":",
"t",
".",
"Time",
"=",
"time",
".",
"Unix",
"(",
"int64",
"(",
"input",
")",
",",
"0",
")",
"\n",
"return",
"nil",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"wrong type\"",
")",
"\n",
"}",
"\n",
"}"
] | // UnmarshalGraphQL is a custom unmarshaler for Time
//
// This function will be called whenever you use the
// time scalar as an input | [
"UnmarshalGraphQL",
"is",
"a",
"custom",
"unmarshaler",
"for",
"Time",
"This",
"function",
"will",
"be",
"called",
"whenever",
"you",
"use",
"the",
"time",
"scalar",
"as",
"an",
"input"
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/time.go#L25-L43 | train |
graph-gophers/graphql-go | internal/schema/schema.go | Resolve | func (s *Schema) Resolve(name string) common.Type {
return s.Types[name]
} | go | func (s *Schema) Resolve(name string) common.Type {
return s.Types[name]
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Resolve",
"(",
"name",
"string",
")",
"common",
".",
"Type",
"{",
"return",
"s",
".",
"Types",
"[",
"name",
"]",
"\n",
"}"
] | // Resolve a named type in the schema by its name. | [
"Resolve",
"a",
"named",
"type",
"in",
"the",
"schema",
"by",
"its",
"name",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/internal/schema/schema.go#L53-L55 | train |
graph-gophers/graphql-go | internal/schema/schema.go | Get | func (l FieldList) Get(name string) *Field {
for _, f := range l {
if f.Name == name {
return f
}
}
return nil
} | go | func (l FieldList) Get(name string) *Field {
for _, f := range l {
if f.Name == name {
return f
}
}
return nil
} | [
"func",
"(",
"l",
"FieldList",
")",
"Get",
"(",
"name",
"string",
")",
"*",
"Field",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"l",
"{",
"if",
"f",
".",
"Name",
"==",
"name",
"{",
"return",
"f",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Get iterates over the field list, returning a pointer-to-Field when the field name matches the
// provided `name` argument.
// Returns nil when no field was found by that name. | [
"Get",
"iterates",
"over",
"the",
"field",
"list",
"returning",
"a",
"pointer",
"-",
"to",
"-",
"Field",
"when",
"the",
"field",
"name",
"matches",
"the",
"provided",
"name",
"argument",
".",
"Returns",
"nil",
"when",
"no",
"field",
"was",
"found",
"by",
"that",
"name",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/internal/schema/schema.go#L170-L177 | train |
graph-gophers/graphql-go | internal/schema/schema.go | Names | func (l FieldList) Names() []string {
names := make([]string, len(l))
for i, f := range l {
names[i] = f.Name
}
return names
} | go | func (l FieldList) Names() []string {
names := make([]string, len(l))
for i, f := range l {
names[i] = f.Name
}
return names
} | [
"func",
"(",
"l",
"FieldList",
")",
"Names",
"(",
")",
"[",
"]",
"string",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"l",
")",
")",
"\n",
"for",
"i",
",",
"f",
":=",
"range",
"l",
"{",
"names",
"[",
"i",
"]",
"=",
"f",
".",
"Name",
"\n",
"}",
"\n",
"return",
"names",
"\n",
"}"
] | // Names returns a string slice of the field names in the FieldList. | [
"Names",
"returns",
"a",
"string",
"slice",
"of",
"the",
"field",
"names",
"in",
"the",
"FieldList",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/internal/schema/schema.go#L180-L186 | train |
graph-gophers/graphql-go | internal/schema/schema.go | New | func New() *Schema {
s := &Schema{
entryPointNames: make(map[string]string),
Types: make(map[string]NamedType),
Directives: make(map[string]*DirectiveDecl),
}
for n, t := range Meta.Types {
s.Types[n] = t
}
for n, d := range Meta.Directives {
s.Directives[n] = d
}
return s
} | go | func New() *Schema {
s := &Schema{
entryPointNames: make(map[string]string),
Types: make(map[string]NamedType),
Directives: make(map[string]*DirectiveDecl),
}
for n, t := range Meta.Types {
s.Types[n] = t
}
for n, d := range Meta.Directives {
s.Directives[n] = d
}
return s
} | [
"func",
"New",
"(",
")",
"*",
"Schema",
"{",
"s",
":=",
"&",
"Schema",
"{",
"entryPointNames",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"Types",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"NamedType",
")",
",",
"Directives",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"DirectiveDecl",
")",
",",
"}",
"\n",
"for",
"n",
",",
"t",
":=",
"range",
"Meta",
".",
"Types",
"{",
"s",
".",
"Types",
"[",
"n",
"]",
"=",
"t",
"\n",
"}",
"\n",
"for",
"n",
",",
"d",
":=",
"range",
"Meta",
".",
"Directives",
"{",
"s",
".",
"Directives",
"[",
"n",
"]",
"=",
"d",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // New initializes an instance of Schema. | [
"New",
"initializes",
"an",
"instance",
"of",
"Schema",
"."
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/internal/schema/schema.go#L235-L248 | train |
graph-gophers/graphql-go | log/log.go | LogPanic | func (l *DefaultLogger) LogPanic(_ context.Context, value interface{}) {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Printf("graphql: panic occurred: %v\n%s", value, buf)
} | go | func (l *DefaultLogger) LogPanic(_ context.Context, value interface{}) {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Printf("graphql: panic occurred: %v\n%s", value, buf)
} | [
"func",
"(",
"l",
"*",
"DefaultLogger",
")",
"LogPanic",
"(",
"_",
"context",
".",
"Context",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"const",
"size",
"=",
"64",
"<<",
"10",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"buf",
"=",
"buf",
"[",
":",
"runtime",
".",
"Stack",
"(",
"buf",
",",
"false",
")",
"]",
"\n",
"log",
".",
"Printf",
"(",
"\"graphql: panic occurred: %v\\n%s\"",
",",
"\\n",
",",
"value",
")",
"\n",
"}"
] | // LogPanic is used to log recovered panic values that occur during query execution | [
"LogPanic",
"is",
"used",
"to",
"log",
"recovered",
"panic",
"values",
"that",
"occur",
"during",
"query",
"execution"
] | 3e8838d4614c12ab337e796548521744f921e05d | https://github.com/graph-gophers/graphql-go/blob/3e8838d4614c12ab337e796548521744f921e05d/log/log.go#L18-L23 | train |
xeipuuv/gojsonschema | validation.go | Validate | func Validate(ls JSONLoader, ld JSONLoader) (*Result, error) {
// load schema
schema, err := NewSchema(ls)
if err != nil {
return nil, err
}
return schema.Validate(ld)
} | go | func Validate(ls JSONLoader, ld JSONLoader) (*Result, error) {
// load schema
schema, err := NewSchema(ls)
if err != nil {
return nil, err
}
return schema.Validate(ld)
} | [
"func",
"Validate",
"(",
"ls",
"JSONLoader",
",",
"ld",
"JSONLoader",
")",
"(",
"*",
"Result",
",",
"error",
")",
"{",
"schema",
",",
"err",
":=",
"NewSchema",
"(",
"ls",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"schema",
".",
"Validate",
"(",
"ld",
")",
"\n",
"}"
] | // Validate loads and validates a JSON schema | [
"Validate",
"loads",
"and",
"validates",
"a",
"JSON",
"schema"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/validation.go#L39-L46 | train |
xeipuuv/gojsonschema | validation.go | Validate | func (v *Schema) Validate(l JSONLoader) (*Result, error) {
root, err := l.LoadJSON()
if err != nil {
return nil, err
}
return v.validateDocument(root), nil
} | go | func (v *Schema) Validate(l JSONLoader) (*Result, error) {
root, err := l.LoadJSON()
if err != nil {
return nil, err
}
return v.validateDocument(root), nil
} | [
"func",
"(",
"v",
"*",
"Schema",
")",
"Validate",
"(",
"l",
"JSONLoader",
")",
"(",
"*",
"Result",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"l",
".",
"LoadJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"v",
".",
"validateDocument",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // Validate loads and validates a JSON document | [
"Validate",
"loads",
"and",
"validates",
"a",
"JSON",
"document"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/validation.go#L49-L55 | train |
xeipuuv/gojsonschema | jsonLoader.go | Open | func (o osFileSystem) Open(name string) (http.File, error) {
return o(name)
} | go | func (o osFileSystem) Open(name string) (http.File, error) {
return o(name)
} | [
"func",
"(",
"o",
"osFileSystem",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"http",
".",
"File",
",",
"error",
")",
"{",
"return",
"o",
"(",
"name",
")",
"\n",
"}"
] | // Opens a file with the given name | [
"Opens",
"a",
"file",
"with",
"the",
"given",
"name"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/jsonLoader.go#L89-L91 | train |
xeipuuv/gojsonschema | jsonLoader.go | NewReferenceLoaderFileSystem | func NewReferenceLoaderFileSystem(source string, fs http.FileSystem) JSONLoader {
return &jsonReferenceLoader{
fs: fs,
source: source,
}
} | go | func NewReferenceLoaderFileSystem(source string, fs http.FileSystem) JSONLoader {
return &jsonReferenceLoader{
fs: fs,
source: source,
}
} | [
"func",
"NewReferenceLoaderFileSystem",
"(",
"source",
"string",
",",
"fs",
"http",
".",
"FileSystem",
")",
"JSONLoader",
"{",
"return",
"&",
"jsonReferenceLoader",
"{",
"fs",
":",
"fs",
",",
"source",
":",
"source",
",",
"}",
"\n",
"}"
] | // NewReferenceLoaderFileSystem returns a JSON reference loader using the given source and file system. | [
"NewReferenceLoaderFileSystem",
"returns",
"a",
"JSON",
"reference",
"loader",
"using",
"the",
"given",
"source",
"and",
"file",
"system",
"."
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/jsonLoader.go#L124-L129 | train |
xeipuuv/gojsonschema | jsonLoader.go | NewReaderLoader | func NewReaderLoader(source io.Reader) (JSONLoader, io.Reader) {
buf := &bytes.Buffer{}
return &jsonIOLoader{buf: buf}, io.TeeReader(source, buf)
} | go | func NewReaderLoader(source io.Reader) (JSONLoader, io.Reader) {
buf := &bytes.Buffer{}
return &jsonIOLoader{buf: buf}, io.TeeReader(source, buf)
} | [
"func",
"NewReaderLoader",
"(",
"source",
"io",
".",
"Reader",
")",
"(",
"JSONLoader",
",",
"io",
".",
"Reader",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"return",
"&",
"jsonIOLoader",
"{",
"buf",
":",
"buf",
"}",
",",
"io",
".",
"TeeReader",
"(",
"source",
",",
"buf",
")",
"\n",
"}"
] | // NewReaderLoader creates a new JSON loader using the provided io.Reader | [
"NewReaderLoader",
"creates",
"a",
"new",
"JSON",
"loader",
"using",
"the",
"provided",
"io",
".",
"Reader"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/jsonLoader.go#L313-L316 | train |
xeipuuv/gojsonschema | jsonLoader.go | NewWriterLoader | func NewWriterLoader(source io.Writer) (JSONLoader, io.Writer) {
buf := &bytes.Buffer{}
return &jsonIOLoader{buf: buf}, io.MultiWriter(source, buf)
} | go | func NewWriterLoader(source io.Writer) (JSONLoader, io.Writer) {
buf := &bytes.Buffer{}
return &jsonIOLoader{buf: buf}, io.MultiWriter(source, buf)
} | [
"func",
"NewWriterLoader",
"(",
"source",
"io",
".",
"Writer",
")",
"(",
"JSONLoader",
",",
"io",
".",
"Writer",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"return",
"&",
"jsonIOLoader",
"{",
"buf",
":",
"buf",
"}",
",",
"io",
".",
"MultiWriter",
"(",
"source",
",",
"buf",
")",
"\n",
"}"
] | // NewWriterLoader creates a new JSON loader using the provided io.Writer | [
"NewWriterLoader",
"creates",
"a",
"new",
"JSON",
"loader",
"using",
"the",
"provided",
"io",
".",
"Writer"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/jsonLoader.go#L319-L322 | train |
xeipuuv/gojsonschema | format_checkers.go | Add | func (c *FormatCheckerChain) Add(name string, f FormatChecker) *FormatCheckerChain {
lock.Lock()
c.formatters[name] = f
lock.Unlock()
return c
} | go | func (c *FormatCheckerChain) Add(name string, f FormatChecker) *FormatCheckerChain {
lock.Lock()
c.formatters[name] = f
lock.Unlock()
return c
} | [
"func",
"(",
"c",
"*",
"FormatCheckerChain",
")",
"Add",
"(",
"name",
"string",
",",
"f",
"FormatChecker",
")",
"*",
"FormatCheckerChain",
"{",
"lock",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"formatters",
"[",
"name",
"]",
"=",
"f",
"\n",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Add adds a FormatChecker to the FormatCheckerChain
// The name used will be the value used for the format key in your json schema | [
"Add",
"adds",
"a",
"FormatChecker",
"to",
"the",
"FormatCheckerChain",
"The",
"name",
"used",
"will",
"be",
"the",
"value",
"used",
"for",
"the",
"format",
"key",
"in",
"your",
"json",
"schema"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L149-L155 | train |
xeipuuv/gojsonschema | format_checkers.go | Has | func (c *FormatCheckerChain) Has(name string) bool {
lock.Lock()
_, ok := c.formatters[name]
lock.Unlock()
return ok
} | go | func (c *FormatCheckerChain) Has(name string) bool {
lock.Lock()
_, ok := c.formatters[name]
lock.Unlock()
return ok
} | [
"func",
"(",
"c",
"*",
"FormatCheckerChain",
")",
"Has",
"(",
"name",
"string",
")",
"bool",
"{",
"lock",
".",
"Lock",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"c",
".",
"formatters",
"[",
"name",
"]",
"\n",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // Has checks to see if the FormatCheckerChain holds a FormatChecker with the given name | [
"Has",
"checks",
"to",
"see",
"if",
"the",
"FormatCheckerChain",
"holds",
"a",
"FormatChecker",
"with",
"the",
"given",
"name"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L167-L173 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (c *FormatCheckerChain) IsFormat(name string, input interface{}) bool {
lock.Lock()
f, ok := c.formatters[name]
lock.Unlock()
if !ok {
return false
}
return f.IsFormat(input)
} | go | func (c *FormatCheckerChain) IsFormat(name string, input interface{}) bool {
lock.Lock()
f, ok := c.formatters[name]
lock.Unlock()
if !ok {
return false
}
return f.IsFormat(input)
} | [
"func",
"(",
"c",
"*",
"FormatCheckerChain",
")",
"IsFormat",
"(",
"name",
"string",
",",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"lock",
".",
"Lock",
"(",
")",
"\n",
"f",
",",
"ok",
":=",
"c",
".",
"formatters",
"[",
"name",
"]",
"\n",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"f",
".",
"IsFormat",
"(",
"input",
")",
"\n",
"}"
] | // IsFormat will check an input against a FormatChecker with the given name
// to see if it is the correct format | [
"IsFormat",
"will",
"check",
"an",
"input",
"against",
"a",
"FormatChecker",
"with",
"the",
"given",
"name",
"to",
"see",
"if",
"it",
"is",
"the",
"correct",
"format"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L177-L187 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f EmailFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
_, err := mail.ParseAddress(asString)
return err == nil
} | go | func (f EmailFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
_, err := mail.ParseAddress(asString)
return err == nil
} | [
"func",
"(",
"f",
"EmailFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"mail",
".",
"ParseAddress",
"(",
"asString",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted e-mail address | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"e",
"-",
"mail",
"address"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L190-L198 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f IPV4FormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
// Credit: https://github.com/asaskevich/govalidator
ip := net.ParseIP(asString)
return ip != nil && strings.Contains(asString, ".")
} | go | func (f IPV4FormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
// Credit: https://github.com/asaskevich/govalidator
ip := net.ParseIP(asString)
return ip != nil && strings.Contains(asString, ".")
} | [
"func",
"(",
"f",
"IPV4FormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"asString",
")",
"\n",
"return",
"ip",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"asString",
",",
"\".\"",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted IPv4-address | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"IPv4",
"-",
"address"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L201-L210 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f URIFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
u, err := url.Parse(asString)
if err != nil || u.Scheme == "" {
return false
}
return !strings.Contains(asString, `\`)
} | go | func (f URIFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
u, err := url.Parse(asString)
if err != nil || u.Scheme == "" {
return false
}
return !strings.Contains(asString, `\`)
} | [
"func",
"(",
"f",
"URIFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"asString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"u",
".",
"Scheme",
"==",
"\"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"!",
"strings",
".",
"Contains",
"(",
"asString",
",",
"`\\`",
")",
"\n",
"}"
] | // IsFormat checks if input is correctly formatted URI with a valid Scheme per RFC3986 | [
"IsFormat",
"checks",
"if",
"input",
"is",
"correctly",
"formatted",
"URI",
"with",
"a",
"valid",
"Scheme",
"per",
"RFC3986"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L274-L287 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f URIReferenceFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
_, err := url.Parse(asString)
return err == nil && !strings.Contains(asString, `\`)
} | go | func (f URIReferenceFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
_, err := url.Parse(asString)
return err == nil && !strings.Contains(asString, `\`)
} | [
"func",
"(",
"f",
"URIReferenceFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"asString",
")",
"\n",
"return",
"err",
"==",
"nil",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"asString",
",",
"`\\`",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted URI or relative-reference per RFC3986 | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"URI",
"or",
"relative",
"-",
"reference",
"per",
"RFC3986"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L290-L298 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f URITemplateFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
u, err := url.Parse(asString)
if err != nil || strings.Contains(asString, `\`) {
return false
}
return rxURITemplate.MatchString(u.Path)
} | go | func (f URITemplateFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
u, err := url.Parse(asString)
if err != nil || strings.Contains(asString, `\`) {
return false
}
return rxURITemplate.MatchString(u.Path)
} | [
"func",
"(",
"f",
"URITemplateFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"asString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"strings",
".",
"Contains",
"(",
"asString",
",",
"`\\`",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rxURITemplate",
".",
"MatchString",
"(",
"u",
".",
"Path",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted URI template per RFC6570 | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"URI",
"template",
"per",
"RFC6570"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L301-L313 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f HostnameFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxHostname.MatchString(asString) && len(asString) < 256
} | go | func (f HostnameFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxHostname.MatchString(asString) && len(asString) < 256
} | [
"func",
"(",
"f",
"HostnameFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rxHostname",
".",
"MatchString",
"(",
"asString",
")",
"&&",
"len",
"(",
"asString",
")",
"<",
"256",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted hostname | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"hostname"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L316-L323 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f UUIDFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxUUID.MatchString(asString)
} | go | func (f UUIDFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxUUID.MatchString(asString)
} | [
"func",
"(",
"f",
"UUIDFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rxUUID",
".",
"MatchString",
"(",
"asString",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted UUID | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"UUID"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L326-L333 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f RegexFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
if asString == "" {
return true
}
_, err := regexp.Compile(asString)
return err == nil
} | go | func (f RegexFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
if asString == "" {
return true
}
_, err := regexp.Compile(asString)
return err == nil
} | [
"func",
"(",
"f",
"RegexFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"asString",
"==",
"\"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"asString",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted regular expression | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"regular",
"expression"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L336-L347 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f JSONPointerFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxJSONPointer.MatchString(asString)
} | go | func (f JSONPointerFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxJSONPointer.MatchString(asString)
} | [
"func",
"(",
"f",
"JSONPointerFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rxJSONPointer",
".",
"MatchString",
"(",
"asString",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted JSON Pointer per RFC6901 | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"JSON",
"Pointer",
"per",
"RFC6901"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L350-L357 | train |
xeipuuv/gojsonschema | format_checkers.go | IsFormat | func (f RelativeJSONPointerFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxRelJSONPointer.MatchString(asString)
} | go | func (f RelativeJSONPointerFormatChecker) IsFormat(input interface{}) bool {
asString, ok := input.(string)
if !ok {
return false
}
return rxRelJSONPointer.MatchString(asString)
} | [
"func",
"(",
"f",
"RelativeJSONPointerFormatChecker",
")",
"IsFormat",
"(",
"input",
"interface",
"{",
"}",
")",
"bool",
"{",
"asString",
",",
"ok",
":=",
"input",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rxRelJSONPointer",
".",
"MatchString",
"(",
"asString",
")",
"\n",
"}"
] | // IsFormat checks if input is a correctly formatted relative JSON Pointer | [
"IsFormat",
"checks",
"if",
"input",
"is",
"a",
"correctly",
"formatted",
"relative",
"JSON",
"Pointer"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/format_checkers.go#L360-L367 | train |
xeipuuv/gojsonschema | jsonContext.go | String | func (c *JsonContext) String(del ...string) string {
byteArr := make([]byte, 0, c.stringLen())
buf := bytes.NewBuffer(byteArr)
c.writeStringToBuffer(buf, del)
return buf.String()
} | go | func (c *JsonContext) String(del ...string) string {
byteArr := make([]byte, 0, c.stringLen())
buf := bytes.NewBuffer(byteArr)
c.writeStringToBuffer(buf, del)
return buf.String()
} | [
"func",
"(",
"c",
"*",
"JsonContext",
")",
"String",
"(",
"del",
"...",
"string",
")",
"string",
"{",
"byteArr",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"c",
".",
"stringLen",
"(",
")",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"byteArr",
")",
"\n",
"c",
".",
"writeStringToBuffer",
"(",
"buf",
",",
"del",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // String displays the context in reverse.
// This plays well with the data structure's persistent nature with
// Cons and a json document's tree structure. | [
"String",
"displays",
"the",
"context",
"in",
"reverse",
".",
"This",
"plays",
"well",
"with",
"the",
"data",
"structure",
"s",
"persistent",
"nature",
"with",
"Cons",
"and",
"a",
"json",
"document",
"s",
"tree",
"structure",
"."
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/jsonContext.go#L43-L49 | train |
xeipuuv/gojsonschema | result.go | String | func (v ResultErrorFields) String() string {
// as a fallback, the value is displayed go style
valueString := fmt.Sprintf("%v", v.value)
// marshal the go value value to json
if v.value == nil {
valueString = TYPE_NULL
} else {
if vs, err := marshalToJSONString(v.value); err == nil {
if vs == nil {
valueString = TYPE_NULL
} else {
valueString = *vs
}
}
}
return formatErrorDescription(Locale.ErrorFormat(), ErrorDetails{
"context": v.context.String(),
"description": v.description,
"value": valueString,
"field": v.Field(),
})
} | go | func (v ResultErrorFields) String() string {
// as a fallback, the value is displayed go style
valueString := fmt.Sprintf("%v", v.value)
// marshal the go value value to json
if v.value == nil {
valueString = TYPE_NULL
} else {
if vs, err := marshalToJSONString(v.value); err == nil {
if vs == nil {
valueString = TYPE_NULL
} else {
valueString = *vs
}
}
}
return formatErrorDescription(Locale.ErrorFormat(), ErrorDetails{
"context": v.context.String(),
"description": v.description,
"value": valueString,
"field": v.Field(),
})
} | [
"func",
"(",
"v",
"ResultErrorFields",
")",
"String",
"(",
")",
"string",
"{",
"valueString",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%v\"",
",",
"v",
".",
"value",
")",
"\n",
"if",
"v",
".",
"value",
"==",
"nil",
"{",
"valueString",
"=",
"TYPE_NULL",
"\n",
"}",
"else",
"{",
"if",
"vs",
",",
"err",
":=",
"marshalToJSONString",
"(",
"v",
".",
"value",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"vs",
"==",
"nil",
"{",
"valueString",
"=",
"TYPE_NULL",
"\n",
"}",
"else",
"{",
"valueString",
"=",
"*",
"vs",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"formatErrorDescription",
"(",
"Locale",
".",
"ErrorFormat",
"(",
")",
",",
"ErrorDetails",
"{",
"\"context\"",
":",
"v",
".",
"context",
".",
"String",
"(",
")",
",",
"\"description\"",
":",
"v",
".",
"description",
",",
"\"value\"",
":",
"valueString",
",",
"\"field\"",
":",
"v",
".",
"Field",
"(",
")",
",",
"}",
")",
"\n",
"}"
] | // String returns a string representation of the error | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"error"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/result.go#L159-L182 | train |
xeipuuv/gojsonschema | result.go | mergeErrors | func (v *Result) mergeErrors(otherResult *Result) {
v.errors = append(v.errors, otherResult.Errors()...)
v.score += otherResult.score
} | go | func (v *Result) mergeErrors(otherResult *Result) {
v.errors = append(v.errors, otherResult.Errors()...)
v.score += otherResult.score
} | [
"func",
"(",
"v",
"*",
"Result",
")",
"mergeErrors",
"(",
"otherResult",
"*",
"Result",
")",
"{",
"v",
".",
"errors",
"=",
"append",
"(",
"v",
".",
"errors",
",",
"otherResult",
".",
"Errors",
"(",
")",
"...",
")",
"\n",
"v",
".",
"score",
"+=",
"otherResult",
".",
"score",
"\n",
"}"
] | // Used to copy errors from a sub-schema to the main one | [
"Used",
"to",
"copy",
"errors",
"from",
"a",
"sub",
"-",
"schema",
"to",
"the",
"main",
"one"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/result.go#L213-L216 | train |
xeipuuv/gojsonschema | utils.go | indexStringInSlice | func indexStringInSlice(s []string, what string) int {
for i := range s {
if s[i] == what {
return i
}
}
return -1
} | go | func indexStringInSlice(s []string, what string) int {
for i := range s {
if s[i] == what {
return i
}
}
return -1
} | [
"func",
"indexStringInSlice",
"(",
"s",
"[",
"]",
"string",
",",
"what",
"string",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"s",
"{",
"if",
"s",
"[",
"i",
"]",
"==",
"what",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] | // indexStringInSlice returns the index of the first instance of 'what' in s or -1 if it is not found in s. | [
"indexStringInSlice",
"returns",
"the",
"index",
"of",
"the",
"first",
"instance",
"of",
"what",
"in",
"s",
"or",
"-",
"1",
"if",
"it",
"is",
"not",
"found",
"in",
"s",
"."
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/utils.go#L66-L73 | train |
xeipuuv/gojsonschema | schemaLoader.go | NewSchemaLoader | func NewSchemaLoader() *SchemaLoader {
ps := &SchemaLoader{
pool: &schemaPool{
schemaPoolDocuments: make(map[string]*schemaPoolDocument),
},
AutoDetect: true,
Validate: false,
Draft: Hybrid,
}
ps.pool.autoDetect = &ps.AutoDetect
return ps
} | go | func NewSchemaLoader() *SchemaLoader {
ps := &SchemaLoader{
pool: &schemaPool{
schemaPoolDocuments: make(map[string]*schemaPoolDocument),
},
AutoDetect: true,
Validate: false,
Draft: Hybrid,
}
ps.pool.autoDetect = &ps.AutoDetect
return ps
} | [
"func",
"NewSchemaLoader",
"(",
")",
"*",
"SchemaLoader",
"{",
"ps",
":=",
"&",
"SchemaLoader",
"{",
"pool",
":",
"&",
"schemaPool",
"{",
"schemaPoolDocuments",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"schemaPoolDocument",
")",
",",
"}",
",",
"AutoDetect",
":",
"true",
",",
"Validate",
":",
"false",
",",
"Draft",
":",
"Hybrid",
",",
"}",
"\n",
"ps",
".",
"pool",
".",
"autoDetect",
"=",
"&",
"ps",
".",
"AutoDetect",
"\n",
"return",
"ps",
"\n",
"}"
] | // NewSchemaLoader creates a new NewSchemaLoader | [
"NewSchemaLoader",
"creates",
"a",
"new",
"NewSchemaLoader"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/schemaLoader.go#L33-L46 | train |
xeipuuv/gojsonschema | schemaLoader.go | AddSchema | func (sl *SchemaLoader) AddSchema(url string, loader JSONLoader) error {
ref, err := gojsonreference.NewJsonReference(url)
if err != nil {
return err
}
doc, err := loader.LoadJSON()
if err != nil {
return err
}
if sl.Validate {
if err := sl.validateMetaschema(doc); err != nil {
return err
}
}
return sl.pool.parseReferences(doc, ref, true)
} | go | func (sl *SchemaLoader) AddSchema(url string, loader JSONLoader) error {
ref, err := gojsonreference.NewJsonReference(url)
if err != nil {
return err
}
doc, err := loader.LoadJSON()
if err != nil {
return err
}
if sl.Validate {
if err := sl.validateMetaschema(doc); err != nil {
return err
}
}
return sl.pool.parseReferences(doc, ref, true)
} | [
"func",
"(",
"sl",
"*",
"SchemaLoader",
")",
"AddSchema",
"(",
"url",
"string",
",",
"loader",
"JSONLoader",
")",
"error",
"{",
"ref",
",",
"err",
":=",
"gojsonreference",
".",
"NewJsonReference",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"doc",
",",
"err",
":=",
"loader",
".",
"LoadJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"sl",
".",
"Validate",
"{",
"if",
"err",
":=",
"sl",
".",
"validateMetaschema",
"(",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"sl",
".",
"pool",
".",
"parseReferences",
"(",
"doc",
",",
"ref",
",",
"true",
")",
"\n",
"}"
] | //AddSchema adds a schema under the provided URL to the schema cache | [
"AddSchema",
"adds",
"a",
"schema",
"under",
"the",
"provided",
"URL",
"to",
"the",
"schema",
"cache"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/schemaLoader.go#L123-L144 | train |
xeipuuv/gojsonschema | schemaLoader.go | Compile | func (sl *SchemaLoader) Compile(rootSchema JSONLoader) (*Schema, error) {
ref, err := rootSchema.JsonReference()
if err != nil {
return nil, err
}
d := Schema{}
d.pool = sl.pool
d.pool.jsonLoaderFactory = rootSchema.LoaderFactory()
d.documentReference = ref
d.referencePool = newSchemaReferencePool()
var doc interface{}
if ref.String() != "" {
// Get document from schema pool
spd, err := d.pool.GetDocument(d.documentReference)
if err != nil {
return nil, err
}
doc = spd.Document
} else {
// Load JSON directly
doc, err = rootSchema.LoadJSON()
if err != nil {
return nil, err
}
// References need only be parsed if loading JSON directly
// as pool.GetDocument already does this for us if loading by reference
err = sl.pool.parseReferences(doc, ref, true)
if err != nil {
return nil, err
}
}
if sl.Validate {
if err := sl.validateMetaschema(doc); err != nil {
return nil, err
}
}
draft := sl.Draft
if sl.AutoDetect {
_, detectedDraft, err := parseSchemaURL(doc)
if err != nil {
return nil, err
}
if detectedDraft != nil {
draft = *detectedDraft
}
}
err = d.parse(doc, draft)
if err != nil {
return nil, err
}
return &d, nil
} | go | func (sl *SchemaLoader) Compile(rootSchema JSONLoader) (*Schema, error) {
ref, err := rootSchema.JsonReference()
if err != nil {
return nil, err
}
d := Schema{}
d.pool = sl.pool
d.pool.jsonLoaderFactory = rootSchema.LoaderFactory()
d.documentReference = ref
d.referencePool = newSchemaReferencePool()
var doc interface{}
if ref.String() != "" {
// Get document from schema pool
spd, err := d.pool.GetDocument(d.documentReference)
if err != nil {
return nil, err
}
doc = spd.Document
} else {
// Load JSON directly
doc, err = rootSchema.LoadJSON()
if err != nil {
return nil, err
}
// References need only be parsed if loading JSON directly
// as pool.GetDocument already does this for us if loading by reference
err = sl.pool.parseReferences(doc, ref, true)
if err != nil {
return nil, err
}
}
if sl.Validate {
if err := sl.validateMetaschema(doc); err != nil {
return nil, err
}
}
draft := sl.Draft
if sl.AutoDetect {
_, detectedDraft, err := parseSchemaURL(doc)
if err != nil {
return nil, err
}
if detectedDraft != nil {
draft = *detectedDraft
}
}
err = d.parse(doc, draft)
if err != nil {
return nil, err
}
return &d, nil
} | [
"func",
"(",
"sl",
"*",
"SchemaLoader",
")",
"Compile",
"(",
"rootSchema",
"JSONLoader",
")",
"(",
"*",
"Schema",
",",
"error",
")",
"{",
"ref",
",",
"err",
":=",
"rootSchema",
".",
"JsonReference",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"d",
":=",
"Schema",
"{",
"}",
"\n",
"d",
".",
"pool",
"=",
"sl",
".",
"pool",
"\n",
"d",
".",
"pool",
".",
"jsonLoaderFactory",
"=",
"rootSchema",
".",
"LoaderFactory",
"(",
")",
"\n",
"d",
".",
"documentReference",
"=",
"ref",
"\n",
"d",
".",
"referencePool",
"=",
"newSchemaReferencePool",
"(",
")",
"\n",
"var",
"doc",
"interface",
"{",
"}",
"\n",
"if",
"ref",
".",
"String",
"(",
")",
"!=",
"\"\"",
"{",
"spd",
",",
"err",
":=",
"d",
".",
"pool",
".",
"GetDocument",
"(",
"d",
".",
"documentReference",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"doc",
"=",
"spd",
".",
"Document",
"\n",
"}",
"else",
"{",
"doc",
",",
"err",
"=",
"rootSchema",
".",
"LoadJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"sl",
".",
"pool",
".",
"parseReferences",
"(",
"doc",
",",
"ref",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"sl",
".",
"Validate",
"{",
"if",
"err",
":=",
"sl",
".",
"validateMetaschema",
"(",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"draft",
":=",
"sl",
".",
"Draft",
"\n",
"if",
"sl",
".",
"AutoDetect",
"{",
"_",
",",
"detectedDraft",
",",
"err",
":=",
"parseSchemaURL",
"(",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"detectedDraft",
"!=",
"nil",
"{",
"draft",
"=",
"*",
"detectedDraft",
"\n",
"}",
"\n",
"}",
"\n",
"err",
"=",
"d",
".",
"parse",
"(",
"doc",
",",
"draft",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"d",
",",
"nil",
"\n",
"}"
] | // Compile loads and compiles a schema | [
"Compile",
"loads",
"and",
"compiles",
"a",
"schema"
] | 354ad34c2300dd6e84920ac70b41487336219e43 | https://github.com/xeipuuv/gojsonschema/blob/354ad34c2300dd6e84920ac70b41487336219e43/schemaLoader.go#L147-L206 | train |
letsencrypt/boulder | mocks/mocks.go | GetRegistration | func (sa *StorageAuthority) GetRegistration(_ context.Context, id int64) (core.Registration, error) {
if id == 100 {
// Tag meaning "Missing"
return core.Registration{}, errors.New("missing")
}
if id == 101 {
// Tag meaning "Malformed"
return core.Registration{}, nil
}
if id == 102 {
// Tag meaning "Not Found"
return core.Registration{}, berrors.NotFoundError("Dave's not here man")
}
keyJSON := []byte(test1KeyPublicJSON)
var parsedKey jose.JSONWebKey
err := parsedKey.UnmarshalJSON(keyJSON)
if err != nil {
return core.Registration{}, err
}
contacts := []string{"mailto:person@mail.com"}
goodReg := core.Registration{
ID: id,
Key: &parsedKey,
Agreement: agreementURL,
Contact: &contacts,
Status: core.StatusValid,
}
// Return a populated registration with contacts for ID == 1 or ID == 5
if id == 1 || id == 5 {
return goodReg, nil
}
var test2KeyPublic jose.JSONWebKey
_ = test2KeyPublic.UnmarshalJSON([]byte(test2KeyPublicJSON))
if id == 2 {
goodReg.Key = &test2KeyPublic
return goodReg, nil
}
var test3KeyPublic jose.JSONWebKey
_ = test3KeyPublic.UnmarshalJSON([]byte(test3KeyPublicJSON))
// deactivated registration
if id == 3 {
goodReg.Key = &test3KeyPublic
goodReg.Status = core.StatusDeactivated
return goodReg, nil
}
var test4KeyPublic jose.JSONWebKey
_ = test4KeyPublic.UnmarshalJSON([]byte(test4KeyPublicJSON))
if id == 4 {
goodReg.Key = &test4KeyPublic
return goodReg, nil
}
// ID 6 == an account without the agreement set
if id == 6 {
goodReg.Agreement = ""
return goodReg, nil
}
goodReg.InitialIP = net.ParseIP("5.6.7.8")
goodReg.CreatedAt = time.Date(2003, 9, 27, 0, 0, 0, 0, time.UTC)
return goodReg, nil
} | go | func (sa *StorageAuthority) GetRegistration(_ context.Context, id int64) (core.Registration, error) {
if id == 100 {
// Tag meaning "Missing"
return core.Registration{}, errors.New("missing")
}
if id == 101 {
// Tag meaning "Malformed"
return core.Registration{}, nil
}
if id == 102 {
// Tag meaning "Not Found"
return core.Registration{}, berrors.NotFoundError("Dave's not here man")
}
keyJSON := []byte(test1KeyPublicJSON)
var parsedKey jose.JSONWebKey
err := parsedKey.UnmarshalJSON(keyJSON)
if err != nil {
return core.Registration{}, err
}
contacts := []string{"mailto:person@mail.com"}
goodReg := core.Registration{
ID: id,
Key: &parsedKey,
Agreement: agreementURL,
Contact: &contacts,
Status: core.StatusValid,
}
// Return a populated registration with contacts for ID == 1 or ID == 5
if id == 1 || id == 5 {
return goodReg, nil
}
var test2KeyPublic jose.JSONWebKey
_ = test2KeyPublic.UnmarshalJSON([]byte(test2KeyPublicJSON))
if id == 2 {
goodReg.Key = &test2KeyPublic
return goodReg, nil
}
var test3KeyPublic jose.JSONWebKey
_ = test3KeyPublic.UnmarshalJSON([]byte(test3KeyPublicJSON))
// deactivated registration
if id == 3 {
goodReg.Key = &test3KeyPublic
goodReg.Status = core.StatusDeactivated
return goodReg, nil
}
var test4KeyPublic jose.JSONWebKey
_ = test4KeyPublic.UnmarshalJSON([]byte(test4KeyPublicJSON))
if id == 4 {
goodReg.Key = &test4KeyPublic
return goodReg, nil
}
// ID 6 == an account without the agreement set
if id == 6 {
goodReg.Agreement = ""
return goodReg, nil
}
goodReg.InitialIP = net.ParseIP("5.6.7.8")
goodReg.CreatedAt = time.Date(2003, 9, 27, 0, 0, 0, 0, time.UTC)
return goodReg, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetRegistration",
"(",
"_",
"context",
".",
"Context",
",",
"id",
"int64",
")",
"(",
"core",
".",
"Registration",
",",
"error",
")",
"{",
"if",
"id",
"==",
"100",
"{",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"missing\"",
")",
"\n",
"}",
"\n",
"if",
"id",
"==",
"101",
"{",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"id",
"==",
"102",
"{",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"Dave's not here man\"",
")",
"\n",
"}",
"\n",
"keyJSON",
":=",
"[",
"]",
"byte",
"(",
"test1KeyPublicJSON",
")",
"\n",
"var",
"parsedKey",
"jose",
".",
"JSONWebKey",
"\n",
"err",
":=",
"parsedKey",
".",
"UnmarshalJSON",
"(",
"keyJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"contacts",
":=",
"[",
"]",
"string",
"{",
"\"mailto:person@mail.com\"",
"}",
"\n",
"goodReg",
":=",
"core",
".",
"Registration",
"{",
"ID",
":",
"id",
",",
"Key",
":",
"&",
"parsedKey",
",",
"Agreement",
":",
"agreementURL",
",",
"Contact",
":",
"&",
"contacts",
",",
"Status",
":",
"core",
".",
"StatusValid",
",",
"}",
"\n",
"if",
"id",
"==",
"1",
"||",
"id",
"==",
"5",
"{",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n",
"var",
"test2KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test2KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test2KeyPublicJSON",
")",
")",
"\n",
"if",
"id",
"==",
"2",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test2KeyPublic",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n",
"var",
"test3KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test3KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test3KeyPublicJSON",
")",
")",
"\n",
"if",
"id",
"==",
"3",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test3KeyPublic",
"\n",
"goodReg",
".",
"Status",
"=",
"core",
".",
"StatusDeactivated",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n",
"var",
"test4KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test4KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test4KeyPublicJSON",
")",
")",
"\n",
"if",
"id",
"==",
"4",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test4KeyPublic",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n",
"if",
"id",
"==",
"6",
"{",
"goodReg",
".",
"Agreement",
"=",
"\"\"",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n",
"goodReg",
".",
"InitialIP",
"=",
"net",
".",
"ParseIP",
"(",
"\"5.6.7.8\"",
")",
"\n",
"goodReg",
".",
"CreatedAt",
"=",
"time",
".",
"Date",
"(",
"2003",
",",
"9",
",",
"27",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"time",
".",
"UTC",
")",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}"
] | // GetRegistration is a mock | [
"GetRegistration",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L75-L142 | train |
letsencrypt/boulder | mocks/mocks.go | GetAuthorization | func (sa *StorageAuthority) GetAuthorization(_ context.Context, id string) (core.Authorization, error) {
authz := core.Authorization{
ID: "valid",
Status: core.StatusValid,
RegistrationID: 1,
Identifier: core.AcmeIdentifier{Type: "dns", Value: "not-an-example.com"},
Challenges: []core.Challenge{
{
ID: 23,
Token: "token",
Type: "dns",
},
},
}
// Strip a leading `/` to make working with fake URLs in signed JWS tests easier.
id = strings.TrimPrefix(id, "/")
if id == "valid" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/valid/23"
return authz, nil
} else if id == "pending" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.Status = core.StatusPending
return authz, nil
} else if id == "expired" {
exp := sa.clk.Now().AddDate(0, -1, 0)
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/expired/23"
return authz, nil
} else if id == "error_result" {
return core.Authorization{}, fmt.Errorf("Unspecified database error")
} else if id == "diff_acct" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.RegistrationID = 2
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/valid/23"
return authz, nil
}
return core.Authorization{}, berrors.NotFoundError("no authorization found with id %q", id)
} | go | func (sa *StorageAuthority) GetAuthorization(_ context.Context, id string) (core.Authorization, error) {
authz := core.Authorization{
ID: "valid",
Status: core.StatusValid,
RegistrationID: 1,
Identifier: core.AcmeIdentifier{Type: "dns", Value: "not-an-example.com"},
Challenges: []core.Challenge{
{
ID: 23,
Token: "token",
Type: "dns",
},
},
}
// Strip a leading `/` to make working with fake URLs in signed JWS tests easier.
id = strings.TrimPrefix(id, "/")
if id == "valid" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/valid/23"
return authz, nil
} else if id == "pending" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.Status = core.StatusPending
return authz, nil
} else if id == "expired" {
exp := sa.clk.Now().AddDate(0, -1, 0)
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/expired/23"
return authz, nil
} else if id == "error_result" {
return core.Authorization{}, fmt.Errorf("Unspecified database error")
} else if id == "diff_acct" {
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.RegistrationID = 2
authz.Expires = &exp
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/valid/23"
return authz, nil
}
return core.Authorization{}, berrors.NotFoundError("no authorization found with id %q", id)
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetAuthorization",
"(",
"_",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"core",
".",
"Authorization",
",",
"error",
")",
"{",
"authz",
":=",
"core",
".",
"Authorization",
"{",
"ID",
":",
"\"valid\"",
",",
"Status",
":",
"core",
".",
"StatusValid",
",",
"RegistrationID",
":",
"1",
",",
"Identifier",
":",
"core",
".",
"AcmeIdentifier",
"{",
"Type",
":",
"\"dns\"",
",",
"Value",
":",
"\"not-an-example.com\"",
"}",
",",
"Challenges",
":",
"[",
"]",
"core",
".",
"Challenge",
"{",
"{",
"ID",
":",
"23",
",",
"Token",
":",
"\"token\"",
",",
"Type",
":",
"\"dns\"",
",",
"}",
",",
"}",
",",
"}",
"\n",
"id",
"=",
"strings",
".",
"TrimPrefix",
"(",
"id",
",",
"\"/\"",
")",
"\n",
"if",
"id",
"==",
"\"valid\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"http://localhost:4300/acme/challenge/valid/23\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"pending\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Status",
"=",
"core",
".",
"StatusPending",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"expired\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"0",
",",
"-",
"1",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"http://localhost:4300/acme/challenge/expired/23\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"error_result\"",
"{",
"return",
"core",
".",
"Authorization",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"Unspecified database error\"",
")",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"diff_acct\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"RegistrationID",
"=",
"2",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"http://localhost:4300/acme/challenge/valid/23\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"\n",
"return",
"core",
".",
"Authorization",
"{",
"}",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"no authorization found with id %q\"",
",",
"id",
")",
"\n",
"}"
] | // GetAuthorization is a mock | [
"GetAuthorization",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L239-L282 | train |
letsencrypt/boulder | mocks/mocks.go | RevokeAuthorizationsByDomain | func (sa *StorageAuthority) RevokeAuthorizationsByDomain(_ context.Context, ident core.AcmeIdentifier) (int64, int64, error) {
return 0, 0, nil
} | go | func (sa *StorageAuthority) RevokeAuthorizationsByDomain(_ context.Context, ident core.AcmeIdentifier) (int64, int64, error) {
return 0, 0, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"RevokeAuthorizationsByDomain",
"(",
"_",
"context",
".",
"Context",
",",
"ident",
"core",
".",
"AcmeIdentifier",
")",
"(",
"int64",
",",
"int64",
",",
"error",
")",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}"
] | // RevokeAuthorizationsByDomain is a mock | [
"RevokeAuthorizationsByDomain",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L285-L287 | train |
letsencrypt/boulder | mocks/mocks.go | GetCertificate | func (sa *StorageAuthority) GetCertificate(_ context.Context, serial string) (core.Certificate, error) {
// Serial ee == 238.crt
if serial == "0000000000000000000000000000000000ee" {
certPemBytes, _ := ioutil.ReadFile("test/238.crt")
certBlock, _ := pem.Decode(certPemBytes)
return core.Certificate{
RegistrationID: 1,
DER: certBlock.Bytes,
}, nil
} else if serial == "0000000000000000000000000000000000b2" {
certPemBytes, _ := ioutil.ReadFile("test/178.crt")
certBlock, _ := pem.Decode(certPemBytes)
return core.Certificate{
RegistrationID: 1,
DER: certBlock.Bytes,
}, nil
} else {
return core.Certificate{}, errors.New("No cert")
}
} | go | func (sa *StorageAuthority) GetCertificate(_ context.Context, serial string) (core.Certificate, error) {
// Serial ee == 238.crt
if serial == "0000000000000000000000000000000000ee" {
certPemBytes, _ := ioutil.ReadFile("test/238.crt")
certBlock, _ := pem.Decode(certPemBytes)
return core.Certificate{
RegistrationID: 1,
DER: certBlock.Bytes,
}, nil
} else if serial == "0000000000000000000000000000000000b2" {
certPemBytes, _ := ioutil.ReadFile("test/178.crt")
certBlock, _ := pem.Decode(certPemBytes)
return core.Certificate{
RegistrationID: 1,
DER: certBlock.Bytes,
}, nil
} else {
return core.Certificate{}, errors.New("No cert")
}
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetCertificate",
"(",
"_",
"context",
".",
"Context",
",",
"serial",
"string",
")",
"(",
"core",
".",
"Certificate",
",",
"error",
")",
"{",
"if",
"serial",
"==",
"\"0000000000000000000000000000000000ee\"",
"{",
"certPemBytes",
",",
"_",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"test/238.crt\"",
")",
"\n",
"certBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"certPemBytes",
")",
"\n",
"return",
"core",
".",
"Certificate",
"{",
"RegistrationID",
":",
"1",
",",
"DER",
":",
"certBlock",
".",
"Bytes",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"serial",
"==",
"\"0000000000000000000000000000000000b2\"",
"{",
"certPemBytes",
",",
"_",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"test/178.crt\"",
")",
"\n",
"certBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"certPemBytes",
")",
"\n",
"return",
"core",
".",
"Certificate",
"{",
"RegistrationID",
":",
"1",
",",
"DER",
":",
"certBlock",
".",
"Bytes",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"core",
".",
"Certificate",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"No cert\"",
")",
"\n",
"}",
"\n",
"}"
] | // GetCertificate is a mock | [
"GetCertificate",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L290-L309 | train |
letsencrypt/boulder | mocks/mocks.go | GetCertificateStatus | func (sa *StorageAuthority) GetCertificateStatus(_ context.Context, serial string) (core.CertificateStatus, error) {
// Serial ee == 238.crt
if serial == "0000000000000000000000000000000000ee" {
return core.CertificateStatus{
Status: core.OCSPStatusGood,
}, nil
} else if serial == "0000000000000000000000000000000000b2" {
return core.CertificateStatus{
Status: core.OCSPStatusRevoked,
}, nil
} else {
return core.CertificateStatus{}, errors.New("No cert status")
}
} | go | func (sa *StorageAuthority) GetCertificateStatus(_ context.Context, serial string) (core.CertificateStatus, error) {
// Serial ee == 238.crt
if serial == "0000000000000000000000000000000000ee" {
return core.CertificateStatus{
Status: core.OCSPStatusGood,
}, nil
} else if serial == "0000000000000000000000000000000000b2" {
return core.CertificateStatus{
Status: core.OCSPStatusRevoked,
}, nil
} else {
return core.CertificateStatus{}, errors.New("No cert status")
}
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetCertificateStatus",
"(",
"_",
"context",
".",
"Context",
",",
"serial",
"string",
")",
"(",
"core",
".",
"CertificateStatus",
",",
"error",
")",
"{",
"if",
"serial",
"==",
"\"0000000000000000000000000000000000ee\"",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"Status",
":",
"core",
".",
"OCSPStatusGood",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"serial",
"==",
"\"0000000000000000000000000000000000b2\"",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"Status",
":",
"core",
".",
"OCSPStatusRevoked",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"No cert status\"",
")",
"\n",
"}",
"\n",
"}"
] | // GetCertificateStatus is a mock | [
"GetCertificateStatus",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L312-L325 | train |
letsencrypt/boulder | mocks/mocks.go | AddCertificate | func (sa *StorageAuthority) AddCertificate(_ context.Context, certDER []byte, regID int64, _ []byte, _ *time.Time) (digest string, err error) {
return
} | go | func (sa *StorageAuthority) AddCertificate(_ context.Context, certDER []byte, regID int64, _ []byte, _ *time.Time) (digest string, err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"AddCertificate",
"(",
"_",
"context",
".",
"Context",
",",
"certDER",
"[",
"]",
"byte",
",",
"regID",
"int64",
",",
"_",
"[",
"]",
"byte",
",",
"_",
"*",
"time",
".",
"Time",
")",
"(",
"digest",
"string",
",",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // AddCertificate is a mock | [
"AddCertificate",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L328-L330 | train |
letsencrypt/boulder | mocks/mocks.go | FinalizeAuthorization | func (sa *StorageAuthority) FinalizeAuthorization(_ context.Context, authz core.Authorization) (err error) {
return
} | go | func (sa *StorageAuthority) FinalizeAuthorization(_ context.Context, authz core.Authorization) (err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"FinalizeAuthorization",
"(",
"_",
"context",
".",
"Context",
",",
"authz",
"core",
".",
"Authorization",
")",
"(",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // FinalizeAuthorization is a mock | [
"FinalizeAuthorization",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L333-L335 | train |
letsencrypt/boulder | mocks/mocks.go | MarkCertificateRevoked | func (sa *StorageAuthority) MarkCertificateRevoked(_ context.Context, serial string, reasonCode revocation.Reason) (err error) {
return
} | go | func (sa *StorageAuthority) MarkCertificateRevoked(_ context.Context, serial string, reasonCode revocation.Reason) (err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"MarkCertificateRevoked",
"(",
"_",
"context",
".",
"Context",
",",
"serial",
"string",
",",
"reasonCode",
"revocation",
".",
"Reason",
")",
"(",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // MarkCertificateRevoked is a mock | [
"MarkCertificateRevoked",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L338-L340 | train |
letsencrypt/boulder | mocks/mocks.go | NewPendingAuthorization | func (sa *StorageAuthority) NewPendingAuthorization(_ context.Context, authz core.Authorization) (core.Authorization, error) {
return authz, nil
} | go | func (sa *StorageAuthority) NewPendingAuthorization(_ context.Context, authz core.Authorization) (core.Authorization, error) {
return authz, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"NewPendingAuthorization",
"(",
"_",
"context",
".",
"Context",
",",
"authz",
"core",
".",
"Authorization",
")",
"(",
"core",
".",
"Authorization",
",",
"error",
")",
"{",
"return",
"authz",
",",
"nil",
"\n",
"}"
] | // NewPendingAuthorization is a mock | [
"NewPendingAuthorization",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L343-L345 | train |
letsencrypt/boulder | mocks/mocks.go | NewRegistration | func (sa *StorageAuthority) NewRegistration(_ context.Context, reg core.Registration) (regR core.Registration, err error) {
return
} | go | func (sa *StorageAuthority) NewRegistration(_ context.Context, reg core.Registration) (regR core.Registration, err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"NewRegistration",
"(",
"_",
"context",
".",
"Context",
",",
"reg",
"core",
".",
"Registration",
")",
"(",
"regR",
"core",
".",
"Registration",
",",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // NewRegistration is a mock | [
"NewRegistration",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L348-L350 | train |
letsencrypt/boulder | mocks/mocks.go | UpdateRegistration | func (sa *StorageAuthority) UpdateRegistration(_ context.Context, reg core.Registration) (err error) {
return
} | go | func (sa *StorageAuthority) UpdateRegistration(_ context.Context, reg core.Registration) (err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"UpdateRegistration",
"(",
"_",
"context",
".",
"Context",
",",
"reg",
"core",
".",
"Registration",
")",
"(",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // UpdateRegistration is a mock | [
"UpdateRegistration",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L353-L355 | train |
letsencrypt/boulder | mocks/mocks.go | CountFQDNSets | func (sa *StorageAuthority) CountFQDNSets(_ context.Context, since time.Duration, names []string) (int64, error) {
return 0, nil
} | go | func (sa *StorageAuthority) CountFQDNSets(_ context.Context, since time.Duration, names []string) (int64, error) {
return 0, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountFQDNSets",
"(",
"_",
"context",
".",
"Context",
",",
"since",
"time",
".",
"Duration",
",",
"names",
"[",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // CountFQDNSets is a mock | [
"CountFQDNSets",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L358-L360 | train |
letsencrypt/boulder | mocks/mocks.go | FQDNSetExists | func (sa *StorageAuthority) FQDNSetExists(_ context.Context, names []string) (bool, error) {
return false, nil
} | go | func (sa *StorageAuthority) FQDNSetExists(_ context.Context, names []string) (bool, error) {
return false, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"FQDNSetExists",
"(",
"_",
"context",
".",
"Context",
",",
"names",
"[",
"]",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // FQDNSetExists is a mock | [
"FQDNSetExists",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L363-L365 | train |
letsencrypt/boulder | mocks/mocks.go | GetValidAuthorizations | func (sa *StorageAuthority) GetValidAuthorizations(_ context.Context, regID int64, names []string, now time.Time) (map[string]*core.Authorization, error) {
if regID == 1 {
auths := make(map[string]*core.Authorization)
for _, name := range names {
if sa.authorizedDomains[name] || name == "not-an-example.com" {
exp := now.AddDate(100, 0, 0)
auths[name] = &core.Authorization{
Status: core.StatusValid,
RegistrationID: 1,
Expires: &exp,
Identifier: core.AcmeIdentifier{
Type: "dns",
Value: name,
},
Challenges: []core.Challenge{
{
Status: core.StatusValid,
ID: 23,
Type: core.ChallengeTypeDNS01,
},
},
}
}
}
return auths, nil
} else if regID == 2 {
return map[string]*core.Authorization{}, nil
} else if regID == 5 || regID == 4 {
return map[string]*core.Authorization{"bad.example.com": nil}, nil
}
return nil, nil
} | go | func (sa *StorageAuthority) GetValidAuthorizations(_ context.Context, regID int64, names []string, now time.Time) (map[string]*core.Authorization, error) {
if regID == 1 {
auths := make(map[string]*core.Authorization)
for _, name := range names {
if sa.authorizedDomains[name] || name == "not-an-example.com" {
exp := now.AddDate(100, 0, 0)
auths[name] = &core.Authorization{
Status: core.StatusValid,
RegistrationID: 1,
Expires: &exp,
Identifier: core.AcmeIdentifier{
Type: "dns",
Value: name,
},
Challenges: []core.Challenge{
{
Status: core.StatusValid,
ID: 23,
Type: core.ChallengeTypeDNS01,
},
},
}
}
}
return auths, nil
} else if regID == 2 {
return map[string]*core.Authorization{}, nil
} else if regID == 5 || regID == 4 {
return map[string]*core.Authorization{"bad.example.com": nil}, nil
}
return nil, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetValidAuthorizations",
"(",
"_",
"context",
".",
"Context",
",",
"regID",
"int64",
",",
"names",
"[",
"]",
"string",
",",
"now",
"time",
".",
"Time",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"core",
".",
"Authorization",
",",
"error",
")",
"{",
"if",
"regID",
"==",
"1",
"{",
"auths",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"core",
".",
"Authorization",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"if",
"sa",
".",
"authorizedDomains",
"[",
"name",
"]",
"||",
"name",
"==",
"\"not-an-example.com\"",
"{",
"exp",
":=",
"now",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"auths",
"[",
"name",
"]",
"=",
"&",
"core",
".",
"Authorization",
"{",
"Status",
":",
"core",
".",
"StatusValid",
",",
"RegistrationID",
":",
"1",
",",
"Expires",
":",
"&",
"exp",
",",
"Identifier",
":",
"core",
".",
"AcmeIdentifier",
"{",
"Type",
":",
"\"dns\"",
",",
"Value",
":",
"name",
",",
"}",
",",
"Challenges",
":",
"[",
"]",
"core",
".",
"Challenge",
"{",
"{",
"Status",
":",
"core",
".",
"StatusValid",
",",
"ID",
":",
"23",
",",
"Type",
":",
"core",
".",
"ChallengeTypeDNS01",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"auths",
",",
"nil",
"\n",
"}",
"else",
"if",
"regID",
"==",
"2",
"{",
"return",
"map",
"[",
"string",
"]",
"*",
"core",
".",
"Authorization",
"{",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"regID",
"==",
"5",
"||",
"regID",
"==",
"4",
"{",
"return",
"map",
"[",
"string",
"]",
"*",
"core",
".",
"Authorization",
"{",
"\"bad.example.com\"",
":",
"nil",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // GetValidAuthorizations is a mock | [
"GetValidAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L382-L413 | train |
letsencrypt/boulder | mocks/mocks.go | CountCertificatesByNames | func (sa *StorageAuthority) CountCertificatesByNames(_ context.Context, _ []string, _, _ time.Time) (ret []*sapb.CountByNames_MapElement, err error) {
return
} | go | func (sa *StorageAuthority) CountCertificatesByNames(_ context.Context, _ []string, _, _ time.Time) (ret []*sapb.CountByNames_MapElement, err error) {
return
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountCertificatesByNames",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"[",
"]",
"string",
",",
"_",
",",
"_",
"time",
".",
"Time",
")",
"(",
"ret",
"[",
"]",
"*",
"sapb",
".",
"CountByNames_MapElement",
",",
"err",
"error",
")",
"{",
"return",
"\n",
"}"
] | // CountCertificatesByNames is a mock | [
"CountCertificatesByNames",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L416-L418 | train |
letsencrypt/boulder | mocks/mocks.go | CountRegistrationsByIP | func (sa *StorageAuthority) CountRegistrationsByIP(_ context.Context, _ net.IP, _, _ time.Time) (int, error) {
return 0, nil
} | go | func (sa *StorageAuthority) CountRegistrationsByIP(_ context.Context, _ net.IP, _, _ time.Time) (int, error) {
return 0, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountRegistrationsByIP",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"net",
".",
"IP",
",",
"_",
",",
"_",
"time",
".",
"Time",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // CountRegistrationsByIP is a mock | [
"CountRegistrationsByIP",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L426-L428 | train |
letsencrypt/boulder | mocks/mocks.go | CountPendingAuthorizations | func (sa *StorageAuthority) CountPendingAuthorizations(_ context.Context, _ int64) (int, error) {
return 0, nil
} | go | func (sa *StorageAuthority) CountPendingAuthorizations(_ context.Context, _ int64) (int, error) {
return 0, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountPendingAuthorizations",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"int64",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // CountPendingAuthorizations is a mock | [
"CountPendingAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L436-L438 | train |
letsencrypt/boulder | mocks/mocks.go | CountOrders | func (sa *StorageAuthority) CountOrders(_ context.Context, _ int64, _, _ time.Time) (int, error) {
return 0, nil
} | go | func (sa *StorageAuthority) CountOrders(_ context.Context, _ int64, _, _ time.Time) (int, error) {
return 0, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountOrders",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"int64",
",",
"_",
",",
"_",
"time",
".",
"Time",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // CountOrders is a mock | [
"CountOrders",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L441-L443 | train |
letsencrypt/boulder | mocks/mocks.go | DeactivateAuthorization | func (sa *StorageAuthority) DeactivateAuthorization(_ context.Context, _ string) error {
return nil
} | go | func (sa *StorageAuthority) DeactivateAuthorization(_ context.Context, _ string) error {
return nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"DeactivateAuthorization",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"string",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // DeactivateAuthorization is a mock | [
"DeactivateAuthorization",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L446-L448 | train |
letsencrypt/boulder | mocks/mocks.go | DeactivateRegistration | func (sa *StorageAuthority) DeactivateRegistration(_ context.Context, _ int64) error {
return nil
} | go | func (sa *StorageAuthority) DeactivateRegistration(_ context.Context, _ int64) error {
return nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"DeactivateRegistration",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"int64",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // DeactivateRegistration is a mock | [
"DeactivateRegistration",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L451-L453 | train |
letsencrypt/boulder | mocks/mocks.go | NewOrder | func (sa *StorageAuthority) NewOrder(_ context.Context, order *corepb.Order) (*corepb.Order, error) {
return order, nil
} | go | func (sa *StorageAuthority) NewOrder(_ context.Context, order *corepb.Order) (*corepb.Order, error) {
return order, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"NewOrder",
"(",
"_",
"context",
".",
"Context",
",",
"order",
"*",
"corepb",
".",
"Order",
")",
"(",
"*",
"corepb",
".",
"Order",
",",
"error",
")",
"{",
"return",
"order",
",",
"nil",
"\n",
"}"
] | // NewOrder is a mock | [
"NewOrder",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L456-L458 | train |
letsencrypt/boulder | mocks/mocks.go | SetOrderProcessing | func (sa *StorageAuthority) SetOrderProcessing(_ context.Context, order *corepb.Order) error {
return nil
} | go | func (sa *StorageAuthority) SetOrderProcessing(_ context.Context, order *corepb.Order) error {
return nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"SetOrderProcessing",
"(",
"_",
"context",
".",
"Context",
",",
"order",
"*",
"corepb",
".",
"Order",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // SetOrderProcessing is a mock | [
"SetOrderProcessing",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L461-L463 | train |
letsencrypt/boulder | mocks/mocks.go | GetOrder | func (sa *StorageAuthority) GetOrder(_ context.Context, req *sapb.OrderRequest) (*corepb.Order, error) {
if *req.Id == 2 {
return nil, berrors.NotFoundError("bad")
} else if *req.Id == 3 {
return nil, errors.New("very bad")
}
status := string(core.StatusValid)
one := int64(1)
serial := "serial"
exp := sa.clk.Now().AddDate(30, 0, 0).Unix()
validOrder := &corepb.Order{
Id: req.Id,
RegistrationID: &one,
Expires: &exp,
Names: []string{"example.com"},
Status: &status,
Authorizations: []string{"hello"},
CertificateSerial: &serial,
Error: nil,
}
// Order ID doesn't have a certificate serial yet
if *req.Id == 4 {
pending := string(core.StatusPending)
validOrder.Status = &pending
validOrder.Id = req.Id
validOrder.CertificateSerial = nil
validOrder.Error = nil
return validOrder, nil
}
// Order ID 6 belongs to reg ID 6
if *req.Id == 6 {
six := int64(6)
validOrder.Id = req.Id
validOrder.RegistrationID = &six
}
// Order ID 7 is ready, but expired
if *req.Id == 7 {
ready := string(core.StatusReady)
validOrder.Status = &ready
exp = sa.clk.Now().AddDate(-30, 0, 0).Unix()
validOrder.Expires = &exp
}
if *req.Id == 8 {
ready := string(core.StatusReady)
validOrder.Status = &ready
}
return validOrder, nil
} | go | func (sa *StorageAuthority) GetOrder(_ context.Context, req *sapb.OrderRequest) (*corepb.Order, error) {
if *req.Id == 2 {
return nil, berrors.NotFoundError("bad")
} else if *req.Id == 3 {
return nil, errors.New("very bad")
}
status := string(core.StatusValid)
one := int64(1)
serial := "serial"
exp := sa.clk.Now().AddDate(30, 0, 0).Unix()
validOrder := &corepb.Order{
Id: req.Id,
RegistrationID: &one,
Expires: &exp,
Names: []string{"example.com"},
Status: &status,
Authorizations: []string{"hello"},
CertificateSerial: &serial,
Error: nil,
}
// Order ID doesn't have a certificate serial yet
if *req.Id == 4 {
pending := string(core.StatusPending)
validOrder.Status = &pending
validOrder.Id = req.Id
validOrder.CertificateSerial = nil
validOrder.Error = nil
return validOrder, nil
}
// Order ID 6 belongs to reg ID 6
if *req.Id == 6 {
six := int64(6)
validOrder.Id = req.Id
validOrder.RegistrationID = &six
}
// Order ID 7 is ready, but expired
if *req.Id == 7 {
ready := string(core.StatusReady)
validOrder.Status = &ready
exp = sa.clk.Now().AddDate(-30, 0, 0).Unix()
validOrder.Expires = &exp
}
if *req.Id == 8 {
ready := string(core.StatusReady)
validOrder.Status = &ready
}
return validOrder, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetOrder",
"(",
"_",
"context",
".",
"Context",
",",
"req",
"*",
"sapb",
".",
"OrderRequest",
")",
"(",
"*",
"corepb",
".",
"Order",
",",
"error",
")",
"{",
"if",
"*",
"req",
".",
"Id",
"==",
"2",
"{",
"return",
"nil",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"bad\"",
")",
"\n",
"}",
"else",
"if",
"*",
"req",
".",
"Id",
"==",
"3",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"very bad\"",
")",
"\n",
"}",
"\n",
"status",
":=",
"string",
"(",
"core",
".",
"StatusValid",
")",
"\n",
"one",
":=",
"int64",
"(",
"1",
")",
"\n",
"serial",
":=",
"\"serial\"",
"\n",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"30",
",",
"0",
",",
"0",
")",
".",
"Unix",
"(",
")",
"\n",
"validOrder",
":=",
"&",
"corepb",
".",
"Order",
"{",
"Id",
":",
"req",
".",
"Id",
",",
"RegistrationID",
":",
"&",
"one",
",",
"Expires",
":",
"&",
"exp",
",",
"Names",
":",
"[",
"]",
"string",
"{",
"\"example.com\"",
"}",
",",
"Status",
":",
"&",
"status",
",",
"Authorizations",
":",
"[",
"]",
"string",
"{",
"\"hello\"",
"}",
",",
"CertificateSerial",
":",
"&",
"serial",
",",
"Error",
":",
"nil",
",",
"}",
"\n",
"if",
"*",
"req",
".",
"Id",
"==",
"4",
"{",
"pending",
":=",
"string",
"(",
"core",
".",
"StatusPending",
")",
"\n",
"validOrder",
".",
"Status",
"=",
"&",
"pending",
"\n",
"validOrder",
".",
"Id",
"=",
"req",
".",
"Id",
"\n",
"validOrder",
".",
"CertificateSerial",
"=",
"nil",
"\n",
"validOrder",
".",
"Error",
"=",
"nil",
"\n",
"return",
"validOrder",
",",
"nil",
"\n",
"}",
"\n",
"if",
"*",
"req",
".",
"Id",
"==",
"6",
"{",
"six",
":=",
"int64",
"(",
"6",
")",
"\n",
"validOrder",
".",
"Id",
"=",
"req",
".",
"Id",
"\n",
"validOrder",
".",
"RegistrationID",
"=",
"&",
"six",
"\n",
"}",
"\n",
"if",
"*",
"req",
".",
"Id",
"==",
"7",
"{",
"ready",
":=",
"string",
"(",
"core",
".",
"StatusReady",
")",
"\n",
"validOrder",
".",
"Status",
"=",
"&",
"ready",
"\n",
"exp",
"=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"-",
"30",
",",
"0",
",",
"0",
")",
".",
"Unix",
"(",
")",
"\n",
"validOrder",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"}",
"\n",
"if",
"*",
"req",
".",
"Id",
"==",
"8",
"{",
"ready",
":=",
"string",
"(",
"core",
".",
"StatusReady",
")",
"\n",
"validOrder",
".",
"Status",
"=",
"&",
"ready",
"\n",
"}",
"\n",
"return",
"validOrder",
",",
"nil",
"\n",
"}"
] | // GetOrder is a mock | [
"GetOrder",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L476-L529 | train |
letsencrypt/boulder | mocks/mocks.go | GetAuthorizations | func (sa *StorageAuthority) GetAuthorizations(ctx context.Context, req *sapb.GetAuthorizationsRequest) (*sapb.Authorizations, error) {
return &sapb.Authorizations{}, nil
} | go | func (sa *StorageAuthority) GetAuthorizations(ctx context.Context, req *sapb.GetAuthorizationsRequest) (*sapb.Authorizations, error) {
return &sapb.Authorizations{}, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetAuthorizations",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"sapb",
".",
"GetAuthorizationsRequest",
")",
"(",
"*",
"sapb",
".",
"Authorizations",
",",
"error",
")",
"{",
"return",
"&",
"sapb",
".",
"Authorizations",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // GetAuthorizations is a mock | [
"GetAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L540-L542 | train |
letsencrypt/boulder | mocks/mocks.go | CountInvalidAuthorizations | func (sa *StorageAuthority) CountInvalidAuthorizations(ctx context.Context, req *sapb.CountInvalidAuthorizationsRequest) (count *sapb.Count, err error) {
return &sapb.Count{}, nil
} | go | func (sa *StorageAuthority) CountInvalidAuthorizations(ctx context.Context, req *sapb.CountInvalidAuthorizationsRequest) (count *sapb.Count, err error) {
return &sapb.Count{}, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"CountInvalidAuthorizations",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"sapb",
".",
"CountInvalidAuthorizationsRequest",
")",
"(",
"count",
"*",
"sapb",
".",
"Count",
",",
"err",
"error",
")",
"{",
"return",
"&",
"sapb",
".",
"Count",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // CountInvalidAuthorizations is a mock | [
"CountInvalidAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L545-L547 | train |
letsencrypt/boulder | mocks/mocks.go | AddPendingAuthorizations | func (sa *StorageAuthority) AddPendingAuthorizations(ctx context.Context, req *sapb.AddPendingAuthorizationsRequest) (*sapb.AuthorizationIDs, error) {
return &sapb.AuthorizationIDs{}, nil
} | go | func (sa *StorageAuthority) AddPendingAuthorizations(ctx context.Context, req *sapb.AddPendingAuthorizationsRequest) (*sapb.AuthorizationIDs, error) {
return &sapb.AuthorizationIDs{}, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"AddPendingAuthorizations",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"sapb",
".",
"AddPendingAuthorizationsRequest",
")",
"(",
"*",
"sapb",
".",
"AuthorizationIDs",
",",
"error",
")",
"{",
"return",
"&",
"sapb",
".",
"AuthorizationIDs",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // AddPendingAuthorizations is a mock | [
"AddPendingAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L550-L552 | train |
letsencrypt/boulder | mocks/mocks.go | NewAuthorizations2 | func (sa *StorageAuthority) NewAuthorizations2(ctx context.Context, req *sapb.AddPendingAuthorizationsRequest) (*sapb.Authorization2IDs, error) {
return &sapb.Authorization2IDs{}, nil
} | go | func (sa *StorageAuthority) NewAuthorizations2(ctx context.Context, req *sapb.AddPendingAuthorizationsRequest) (*sapb.Authorization2IDs, error) {
return &sapb.Authorization2IDs{}, nil
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"NewAuthorizations2",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"sapb",
".",
"AddPendingAuthorizationsRequest",
")",
"(",
"*",
"sapb",
".",
"Authorization2IDs",
",",
"error",
")",
"{",
"return",
"&",
"sapb",
".",
"Authorization2IDs",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // NewAuthorizations is a mock | [
"NewAuthorizations",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L555-L557 | train |
letsencrypt/boulder | mocks/mocks.go | GetAuthorization2 | func (sa *StorageAuthority) GetAuthorization2(ctx context.Context, id *sapb.AuthorizationID2) (*corepb.Authorization, error) {
authz := core.Authorization{
Status: core.StatusValid,
RegistrationID: 1,
Identifier: core.AcmeIdentifier{Type: "dns", Value: "not-an-example.com"},
V2: true,
Challenges: []core.Challenge{
{
ID: 23,
Token: "token",
Type: "dns",
},
},
}
switch *id.Id {
case authzIdValid:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdValid)
return bgrpc.AuthzToPB(authz)
case authzIdPending:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdPending)
authz.Status = core.StatusPending
return bgrpc.AuthzToPB(authz)
case authzIdExpired:
exp := sa.clk.Now().AddDate(0, -1, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdExpired)
return bgrpc.AuthzToPB(authz)
case authzIdErrorResult:
return nil, fmt.Errorf("Unspecified database error")
case authzIdDiffAccount:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.RegistrationID = 2
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdDiffAccount)
return bgrpc.AuthzToPB(authz)
}
return nil, berrors.NotFoundError("no authorization found with id %q", id)
} | go | func (sa *StorageAuthority) GetAuthorization2(ctx context.Context, id *sapb.AuthorizationID2) (*corepb.Authorization, error) {
authz := core.Authorization{
Status: core.StatusValid,
RegistrationID: 1,
Identifier: core.AcmeIdentifier{Type: "dns", Value: "not-an-example.com"},
V2: true,
Challenges: []core.Challenge{
{
ID: 23,
Token: "token",
Type: "dns",
},
},
}
switch *id.Id {
case authzIdValid:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdValid)
return bgrpc.AuthzToPB(authz)
case authzIdPending:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdPending)
authz.Status = core.StatusPending
return bgrpc.AuthzToPB(authz)
case authzIdExpired:
exp := sa.clk.Now().AddDate(0, -1, 0)
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdExpired)
return bgrpc.AuthzToPB(authz)
case authzIdErrorResult:
return nil, fmt.Errorf("Unspecified database error")
case authzIdDiffAccount:
exp := sa.clk.Now().AddDate(100, 0, 0)
authz.RegistrationID = 2
authz.Expires = &exp
authz.ID = fmt.Sprintf("%d", authzIdDiffAccount)
return bgrpc.AuthzToPB(authz)
}
return nil, berrors.NotFoundError("no authorization found with id %q", id)
} | [
"func",
"(",
"sa",
"*",
"StorageAuthority",
")",
"GetAuthorization2",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"*",
"sapb",
".",
"AuthorizationID2",
")",
"(",
"*",
"corepb",
".",
"Authorization",
",",
"error",
")",
"{",
"authz",
":=",
"core",
".",
"Authorization",
"{",
"Status",
":",
"core",
".",
"StatusValid",
",",
"RegistrationID",
":",
"1",
",",
"Identifier",
":",
"core",
".",
"AcmeIdentifier",
"{",
"Type",
":",
"\"dns\"",
",",
"Value",
":",
"\"not-an-example.com\"",
"}",
",",
"V2",
":",
"true",
",",
"Challenges",
":",
"[",
"]",
"core",
".",
"Challenge",
"{",
"{",
"ID",
":",
"23",
",",
"Token",
":",
"\"token\"",
",",
"Type",
":",
"\"dns\"",
",",
"}",
",",
"}",
",",
"}",
"\n",
"switch",
"*",
"id",
".",
"Id",
"{",
"case",
"authzIdValid",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"authzIdValid",
")",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"case",
"authzIdPending",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"authzIdPending",
")",
"\n",
"authz",
".",
"Status",
"=",
"core",
".",
"StatusPending",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"case",
"authzIdExpired",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"0",
",",
"-",
"1",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"authzIdExpired",
")",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"case",
"authzIdErrorResult",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Unspecified database error\"",
")",
"\n",
"case",
"authzIdDiffAccount",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"RegistrationID",
"=",
"2",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"authzIdDiffAccount",
")",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"no authorization found with id %q\"",
",",
"id",
")",
"\n",
"}"
] | // GetAuthorization2 is a mock | [
"GetAuthorization2",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L604-L647 | train |
letsencrypt/boulder | mocks/mocks.go | SubmitToSingleCTWithResult | func (*Publisher) SubmitToSingleCTWithResult(_ context.Context, _ *pubpb.Request) (*pubpb.Result, error) {
return nil, nil
} | go | func (*Publisher) SubmitToSingleCTWithResult(_ context.Context, _ *pubpb.Request) (*pubpb.Result, error) {
return nil, nil
} | [
"func",
"(",
"*",
"Publisher",
")",
"SubmitToSingleCTWithResult",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"*",
"pubpb",
".",
"Request",
")",
"(",
"*",
"pubpb",
".",
"Result",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // SubmitToSingleCTWithResult is a mock | [
"SubmitToSingleCTWithResult",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L660-L662 | train |
letsencrypt/boulder | mocks/mocks.go | SendMail | func (m *Mailer) SendMail(to []string, subject, msg string) error {
for _, rcpt := range to {
m.Messages = append(m.Messages, MailerMessage{
To: rcpt,
Subject: subject,
Body: msg,
})
}
return nil
} | go | func (m *Mailer) SendMail(to []string, subject, msg string) error {
for _, rcpt := range to {
m.Messages = append(m.Messages, MailerMessage{
To: rcpt,
Subject: subject,
Body: msg,
})
}
return nil
} | [
"func",
"(",
"m",
"*",
"Mailer",
")",
"SendMail",
"(",
"to",
"[",
"]",
"string",
",",
"subject",
",",
"msg",
"string",
")",
"error",
"{",
"for",
"_",
",",
"rcpt",
":=",
"range",
"to",
"{",
"m",
".",
"Messages",
"=",
"append",
"(",
"m",
".",
"Messages",
",",
"MailerMessage",
"{",
"To",
":",
"rcpt",
",",
"Subject",
":",
"subject",
",",
"Body",
":",
"msg",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SendMail is a mock | [
"SendMail",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/mocks.go#L682-L691 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.