repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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\n",
"if",
"txt",
".",
"dirty",
"{",
"txt",
".",
"trans",
".",
"SetLen",
"(",
"txt",
".",
"tris",
".",
"Len",
"(",
")",
")",
"\n",
"txt",
".",
"trans",
".",
"Update",
"(",
"&",
"txt",
".",
"tris",
")",
"\n\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\n",
"txt",
".",
"transD",
".",
"Dirty",
"(",
")",
"\n",
"txt",
".",
"dirty",
"=",
"false",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"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\n",
"verticalFlip",
"(",
"rgba",
")",
"\n\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\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\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\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\n",
"verticalFlip",
"(",
"rgba",
")",
"\n\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\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\\n",
"\"",
",",
"value",
",",
"buf",
")",
"\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",
")",
"{",
"// load schema",
"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\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\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\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\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\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\n",
"// Credit: https://github.com/asaskevich/govalidator",
"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\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"asString",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"||",
"u",
".",
"Scheme",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\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\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\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"asString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"strings",
".",
"Contains",
"(",
"asString",
",",
"`\\`",
")",
"{",
"return",
"false",
"\n",
"}",
"\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\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\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\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\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\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\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",
"{",
"// as a fallback, the value is displayed go style",
"valueString",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"value",
")",
"\n\n",
"// marshal the go value value to json",
"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\n",
"return",
"formatErrorDescription",
"(",
"Locale",
".",
"ErrorFormat",
"(",
")",
",",
"ErrorDetails",
"{",
"\"",
"\"",
":",
"v",
".",
"context",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"description",
",",
"\"",
"\"",
":",
"valueString",
",",
"\"",
"\"",
":",
"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\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\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"doc",
",",
"err",
":=",
"loader",
".",
"LoadJSON",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"sl",
".",
"Validate",
"{",
"if",
"err",
":=",
"sl",
".",
"validateMetaschema",
"(",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"d",
":=",
"Schema",
"{",
"}",
"\n",
"d",
".",
"pool",
"=",
"sl",
".",
"pool",
"\n",
"d",
".",
"pool",
".",
"jsonLoaderFactory",
"=",
"rootSchema",
".",
"LoaderFactory",
"(",
")",
"\n",
"d",
".",
"documentReference",
"=",
"ref",
"\n",
"d",
".",
"referencePool",
"=",
"newSchemaReferencePool",
"(",
")",
"\n\n",
"var",
"doc",
"interface",
"{",
"}",
"\n",
"if",
"ref",
".",
"String",
"(",
")",
"!=",
"\"",
"\"",
"{",
"// Get document from schema pool",
"spd",
",",
"err",
":=",
"d",
".",
"pool",
".",
"GetDocument",
"(",
"d",
".",
"documentReference",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"doc",
"=",
"spd",
".",
"Document",
"\n",
"}",
"else",
"{",
"// Load JSON directly",
"doc",
",",
"err",
"=",
"rootSchema",
".",
"LoadJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// 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",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"sl",
".",
"Validate",
"{",
"if",
"err",
":=",
"sl",
".",
"validateMetaschema",
"(",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"err",
"=",
"d",
".",
"parse",
"(",
"doc",
",",
"draft",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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:[email protected]"}
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:[email protected]"}
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",
"{",
"// Tag meaning \"Missing\"",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"id",
"==",
"101",
"{",
"// Tag meaning \"Malformed\"",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"id",
"==",
"102",
"{",
"// Tag meaning \"Not Found\"",
"return",
"core",
".",
"Registration",
"{",
"}",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\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\n",
"contacts",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"goodReg",
":=",
"core",
".",
"Registration",
"{",
"ID",
":",
"id",
",",
"Key",
":",
"&",
"parsedKey",
",",
"Agreement",
":",
"agreementURL",
",",
"Contact",
":",
"&",
"contacts",
",",
"Status",
":",
"core",
".",
"StatusValid",
",",
"}",
"\n\n",
"// Return a populated registration with contacts for ID == 1 or ID == 5",
"if",
"id",
"==",
"1",
"||",
"id",
"==",
"5",
"{",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"test2KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test2KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test2KeyPublicJSON",
")",
")",
"\n",
"if",
"id",
"==",
"2",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test2KeyPublic",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"test3KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test3KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test3KeyPublicJSON",
")",
")",
"\n",
"// deactivated registration",
"if",
"id",
"==",
"3",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test3KeyPublic",
"\n",
"goodReg",
".",
"Status",
"=",
"core",
".",
"StatusDeactivated",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"test4KeyPublic",
"jose",
".",
"JSONWebKey",
"\n",
"_",
"=",
"test4KeyPublic",
".",
"UnmarshalJSON",
"(",
"[",
"]",
"byte",
"(",
"test4KeyPublicJSON",
")",
")",
"\n",
"if",
"id",
"==",
"4",
"{",
"goodReg",
".",
"Key",
"=",
"&",
"test4KeyPublic",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n\n",
"// ID 6 == an account without the agreement set",
"if",
"id",
"==",
"6",
"{",
"goodReg",
".",
"Agreement",
"=",
"\"",
"\"",
"\n",
"return",
"goodReg",
",",
"nil",
"\n",
"}",
"\n\n",
"goodReg",
".",
"InitialIP",
"=",
"net",
".",
"ParseIP",
"(",
"\"",
"\"",
")",
"\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",
":",
"\"",
"\"",
",",
"Status",
":",
"core",
".",
"StatusValid",
",",
"RegistrationID",
":",
"1",
",",
"Identifier",
":",
"core",
".",
"AcmeIdentifier",
"{",
"Type",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
"}",
",",
"Challenges",
":",
"[",
"]",
"core",
".",
"Challenge",
"{",
"{",
"ID",
":",
"23",
",",
"Token",
":",
"\"",
"\"",
",",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n",
"// Strip a leading `/` to make working with fake URLs in signed JWS tests easier.",
"id",
"=",
"strings",
".",
"TrimPrefix",
"(",
"id",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"id",
"==",
"\"",
"\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"",
"\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"",
"\"",
"{",
"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",
"==",
"\"",
"\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"0",
",",
"-",
"1",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"",
"\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"core",
".",
"Authorization",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"id",
"==",
"\"",
"\"",
"{",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"RegistrationID",
"=",
"2",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"Challenges",
"[",
"0",
"]",
".",
"URI",
"=",
"\"",
"\"",
"\n",
"return",
"authz",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"core",
".",
"Authorization",
"{",
"}",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"",
"\"",
",",
"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",
")",
"{",
"// Serial ee == 238.crt",
"if",
"serial",
"==",
"\"",
"\"",
"{",
"certPemBytes",
",",
"_",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"",
"\"",
")",
"\n",
"certBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"certPemBytes",
")",
"\n",
"return",
"core",
".",
"Certificate",
"{",
"RegistrationID",
":",
"1",
",",
"DER",
":",
"certBlock",
".",
"Bytes",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"serial",
"==",
"\"",
"\"",
"{",
"certPemBytes",
",",
"_",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"",
"\"",
")",
"\n",
"certBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"certPemBytes",
")",
"\n",
"return",
"core",
".",
"Certificate",
"{",
"RegistrationID",
":",
"1",
",",
"DER",
":",
"certBlock",
".",
"Bytes",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"core",
".",
"Certificate",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\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",
")",
"{",
"// Serial ee == 238.crt",
"if",
"serial",
"==",
"\"",
"\"",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"Status",
":",
"core",
".",
"OCSPStatusGood",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"serial",
"==",
"\"",
"\"",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"Status",
":",
"core",
".",
"OCSPStatusRevoked",
",",
"}",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"core",
".",
"CertificateStatus",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\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",
"==",
"\"",
"\"",
"{",
"exp",
":=",
"now",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"auths",
"[",
"name",
"]",
"=",
"&",
"core",
".",
"Authorization",
"{",
"Status",
":",
"core",
".",
"StatusValid",
",",
"RegistrationID",
":",
"1",
",",
"Expires",
":",
"&",
"exp",
",",
"Identifier",
":",
"core",
".",
"AcmeIdentifier",
"{",
"Type",
":",
"\"",
"\"",
",",
"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",
"{",
"\"",
"\"",
":",
"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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"*",
"req",
".",
"Id",
"==",
"3",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"status",
":=",
"string",
"(",
"core",
".",
"StatusValid",
")",
"\n",
"one",
":=",
"int64",
"(",
"1",
")",
"\n",
"serial",
":=",
"\"",
"\"",
"\n",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"30",
",",
"0",
",",
"0",
")",
".",
"Unix",
"(",
")",
"\n",
"validOrder",
":=",
"&",
"corepb",
".",
"Order",
"{",
"Id",
":",
"req",
".",
"Id",
",",
"RegistrationID",
":",
"&",
"one",
",",
"Expires",
":",
"&",
"exp",
",",
"Names",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Status",
":",
"&",
"status",
",",
"Authorizations",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"CertificateSerial",
":",
"&",
"serial",
",",
"Error",
":",
"nil",
",",
"}",
"\n\n",
"// Order ID doesn't have a certificate serial yet",
"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\n",
"// Order ID 6 belongs to reg ID 6",
"if",
"*",
"req",
".",
"Id",
"==",
"6",
"{",
"six",
":=",
"int64",
"(",
"6",
")",
"\n",
"validOrder",
".",
"Id",
"=",
"req",
".",
"Id",
"\n",
"validOrder",
".",
"RegistrationID",
"=",
"&",
"six",
"\n",
"}",
"\n\n",
"// Order ID 7 is ready, but expired",
"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\n",
"if",
"*",
"req",
".",
"Id",
"==",
"8",
"{",
"ready",
":=",
"string",
"(",
"core",
".",
"StatusReady",
")",
"\n",
"validOrder",
".",
"Status",
"=",
"&",
"ready",
"\n",
"}",
"\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",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
"}",
",",
"V2",
":",
"true",
",",
"Challenges",
":",
"[",
"]",
"core",
".",
"Challenge",
"{",
"{",
"ID",
":",
"23",
",",
"Token",
":",
"\"",
"\"",
",",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"switch",
"*",
"id",
".",
"Id",
"{",
"case",
"authzIdValid",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"authzIdExpired",
")",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"case",
"authzIdErrorResult",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"authzIdDiffAccount",
":",
"exp",
":=",
"sa",
".",
"clk",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"100",
",",
"0",
",",
"0",
")",
"\n",
"authz",
".",
"RegistrationID",
"=",
"2",
"\n",
"authz",
".",
"Expires",
"=",
"&",
"exp",
"\n",
"authz",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"authzIdDiffAccount",
")",
"\n",
"return",
"bgrpc",
".",
"AuthzToPB",
"(",
"authz",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"berrors",
".",
"NotFoundError",
"(",
"\"",
"\"",
",",
"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 |
letsencrypt/boulder | probs/probs.go | ProblemDetailsToStatusCode | func ProblemDetailsToStatusCode(prob *ProblemDetails) int {
if prob.HTTPStatus != 0 {
return prob.HTTPStatus
}
switch prob.Type {
case
ConnectionProblem,
MalformedProblem,
BadSignatureAlgorithmProblem,
BadPublicKeyProblem,
TLSProblem,
UnknownHostProblem,
BadNonceProblem,
InvalidEmailProblem,
RejectedIdentifierProblem,
AccountDoesNotExistProblem:
return http.StatusBadRequest
case ServerInternalProblem:
return http.StatusInternalServerError
case
UnauthorizedProblem,
CAAProblem:
return http.StatusForbidden
case RateLimitedProblem:
return statusTooManyRequests
default:
return http.StatusInternalServerError
}
} | go | func ProblemDetailsToStatusCode(prob *ProblemDetails) int {
if prob.HTTPStatus != 0 {
return prob.HTTPStatus
}
switch prob.Type {
case
ConnectionProblem,
MalformedProblem,
BadSignatureAlgorithmProblem,
BadPublicKeyProblem,
TLSProblem,
UnknownHostProblem,
BadNonceProblem,
InvalidEmailProblem,
RejectedIdentifierProblem,
AccountDoesNotExistProblem:
return http.StatusBadRequest
case ServerInternalProblem:
return http.StatusInternalServerError
case
UnauthorizedProblem,
CAAProblem:
return http.StatusForbidden
case RateLimitedProblem:
return statusTooManyRequests
default:
return http.StatusInternalServerError
}
} | [
"func",
"ProblemDetailsToStatusCode",
"(",
"prob",
"*",
"ProblemDetails",
")",
"int",
"{",
"if",
"prob",
".",
"HTTPStatus",
"!=",
"0",
"{",
"return",
"prob",
".",
"HTTPStatus",
"\n",
"}",
"\n",
"switch",
"prob",
".",
"Type",
"{",
"case",
"ConnectionProblem",
",",
"MalformedProblem",
",",
"BadSignatureAlgorithmProblem",
",",
"BadPublicKeyProblem",
",",
"TLSProblem",
",",
"UnknownHostProblem",
",",
"BadNonceProblem",
",",
"InvalidEmailProblem",
",",
"RejectedIdentifierProblem",
",",
"AccountDoesNotExistProblem",
":",
"return",
"http",
".",
"StatusBadRequest",
"\n",
"case",
"ServerInternalProblem",
":",
"return",
"http",
".",
"StatusInternalServerError",
"\n",
"case",
"UnauthorizedProblem",
",",
"CAAProblem",
":",
"return",
"http",
".",
"StatusForbidden",
"\n",
"case",
"RateLimitedProblem",
":",
"return",
"statusTooManyRequests",
"\n",
"default",
":",
"return",
"http",
".",
"StatusInternalServerError",
"\n",
"}",
"\n",
"}"
] | // ProblemDetailsToStatusCode inspects the given ProblemDetails to figure out
// what HTTP status code it should represent. It should only be used by the WFE
// but is included in this package because of its reliance on ProblemTypes. | [
"ProblemDetailsToStatusCode",
"inspects",
"the",
"given",
"ProblemDetails",
"to",
"figure",
"out",
"what",
"HTTP",
"status",
"code",
"it",
"should",
"represent",
".",
"It",
"should",
"only",
"be",
"used",
"by",
"the",
"WFE",
"but",
"is",
"included",
"in",
"this",
"package",
"because",
"of",
"its",
"reliance",
"on",
"ProblemTypes",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L56-L84 | train |
letsencrypt/boulder | probs/probs.go | BadNonce | func BadNonce(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadNonceProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func BadNonce(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadNonceProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"BadNonce",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"BadNonceProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // BadNonce returns a ProblemDetails with a BadNonceProblem and a 400 Bad
// Request status code. | [
"BadNonce",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"BadNonceProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L88-L94 | train |
letsencrypt/boulder | probs/probs.go | RejectedIdentifier | func RejectedIdentifier(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: RejectedIdentifierProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func RejectedIdentifier(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: RejectedIdentifierProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"RejectedIdentifier",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"RejectedIdentifierProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // RejectedIdentifier returns a ProblemDetails with a RejectedIdentifierProblem and a 400 Bad
// Request status code. | [
"RejectedIdentifier",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"RejectedIdentifierProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L98-L104 | train |
letsencrypt/boulder | probs/probs.go | Conflict | func Conflict(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusConflict,
}
} | go | func Conflict(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusConflict,
}
} | [
"func",
"Conflict",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"MalformedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusConflict",
",",
"}",
"\n",
"}"
] | // Conflict returns a ProblemDetails with a MalformedProblem and a 409 Conflict
// status code. | [
"Conflict",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"MalformedProblem",
"and",
"a",
"409",
"Conflict",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L108-L114 | train |
letsencrypt/boulder | probs/probs.go | AlreadyRevoked | func AlreadyRevoked(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: AlreadyRevokedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func AlreadyRevoked(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: AlreadyRevokedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"AlreadyRevoked",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"AlreadyRevokedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // AlreadyRevoked returns a ProblemDetails with a AlreadyRevokedProblem and a 400 Bad
// Request status code. | [
"AlreadyRevoked",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"AlreadyRevokedProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L118-L124 | train |
letsencrypt/boulder | probs/probs.go | Malformed | func Malformed(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func Malformed(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"Malformed",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"MalformedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // Malformed returns a ProblemDetails with a MalformedProblem and a 400 Bad
// Request status code. | [
"Malformed",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"MalformedProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L128-L134 | train |
letsencrypt/boulder | probs/probs.go | BadSignatureAlgorithm | func BadSignatureAlgorithm(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadSignatureAlgorithmProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func BadSignatureAlgorithm(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadSignatureAlgorithmProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"BadSignatureAlgorithm",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"BadSignatureAlgorithmProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // BadSignatureAlgorithm returns a ProblemDetails with a BadSignatureAlgorithmProblem
// and a 400 Bad Request status code. | [
"BadSignatureAlgorithm",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"BadSignatureAlgorithmProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L138-L144 | train |
letsencrypt/boulder | probs/probs.go | BadPublicKey | func BadPublicKey(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadPublicKeyProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func BadPublicKey(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: BadPublicKeyProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"BadPublicKey",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"BadPublicKeyProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // BadPublicKey returns a ProblemDetails with a BadPublicKeyProblem and a 400 Bad
// Request status code. | [
"BadPublicKey",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"BadPublicKeyProblem",
"and",
"a",
"400",
"Bad",
"Request",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L148-L154 | train |
letsencrypt/boulder | probs/probs.go | NotFound | func NotFound(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusNotFound,
}
} | go | func NotFound(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusNotFound,
}
} | [
"func",
"NotFound",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"MalformedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusNotFound",
",",
"}",
"\n",
"}"
] | // NotFound returns a ProblemDetails with a MalformedProblem and a 404 Not Found
// status code. | [
"NotFound",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"MalformedProblem",
"and",
"a",
"404",
"Not",
"Found",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L158-L164 | train |
letsencrypt/boulder | probs/probs.go | ServerInternal | func ServerInternal(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: ServerInternalProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusInternalServerError,
}
} | go | func ServerInternal(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: ServerInternalProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusInternalServerError,
}
} | [
"func",
"ServerInternal",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"ServerInternalProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusInternalServerError",
",",
"}",
"\n",
"}"
] | // ServerInternal returns a ProblemDetails with a ServerInternalProblem and a
// 500 Internal Server Failure status code. | [
"ServerInternal",
"returns",
"a",
"ProblemDetails",
"with",
"a",
"ServerInternalProblem",
"and",
"a",
"500",
"Internal",
"Server",
"Failure",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L168-L174 | train |
letsencrypt/boulder | probs/probs.go | Unauthorized | func Unauthorized(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: UnauthorizedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | go | func Unauthorized(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: UnauthorizedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | [
"func",
"Unauthorized",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"UnauthorizedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusForbidden",
",",
"}",
"\n",
"}"
] | // Unauthorized returns a ProblemDetails with an UnauthorizedProblem and a 403
// Forbidden status code. | [
"Unauthorized",
"returns",
"a",
"ProblemDetails",
"with",
"an",
"UnauthorizedProblem",
"and",
"a",
"403",
"Forbidden",
"status",
"code",
"."
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L178-L184 | train |
letsencrypt/boulder | probs/probs.go | InvalidContentType | func InvalidContentType(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusUnsupportedMediaType,
}
} | go | func InvalidContentType(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: MalformedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusUnsupportedMediaType,
}
} | [
"func",
"InvalidContentType",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"MalformedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusUnsupportedMediaType",
",",
"}",
"\n",
"}"
] | // InvalidContentType returns a ProblemDetails suitable for a missing
// ContentType header, or an incorrect ContentType header | [
"InvalidContentType",
"returns",
"a",
"ProblemDetails",
"suitable",
"for",
"a",
"missing",
"ContentType",
"header",
"or",
"an",
"incorrect",
"ContentType",
"header"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L208-L214 | train |
letsencrypt/boulder | probs/probs.go | InvalidEmail | func InvalidEmail(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: InvalidEmailProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func InvalidEmail(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: InvalidEmailProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"InvalidEmail",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"InvalidEmailProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // InvalidEmail returns a ProblemDetails representing an invalid email address
// error | [
"InvalidEmail",
"returns",
"a",
"ProblemDetails",
"representing",
"an",
"invalid",
"email",
"address",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L218-L224 | train |
letsencrypt/boulder | probs/probs.go | ConnectionFailure | func ConnectionFailure(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: ConnectionProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func ConnectionFailure(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: ConnectionProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"ConnectionFailure",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"ConnectionProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // ConnectionFailure returns a ProblemDetails representing a ConnectionProblem
// error | [
"ConnectionFailure",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"ConnectionProblem",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L228-L234 | train |
letsencrypt/boulder | probs/probs.go | UnknownHost | func UnknownHost(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: UnknownHostProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func UnknownHost(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: UnknownHostProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"UnknownHost",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"UnknownHostProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // UnknownHost returns a ProblemDetails representing an UnknownHostProblem error | [
"UnknownHost",
"returns",
"a",
"ProblemDetails",
"representing",
"an",
"UnknownHostProblem",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L237-L243 | train |
letsencrypt/boulder | probs/probs.go | RateLimited | func RateLimited(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: RateLimitedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: statusTooManyRequests,
}
} | go | func RateLimited(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: RateLimitedProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: statusTooManyRequests,
}
} | [
"func",
"RateLimited",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"RateLimitedProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"statusTooManyRequests",
",",
"}",
"\n",
"}"
] | // RateLimited returns a ProblemDetails representing a RateLimitedProblem error | [
"RateLimited",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"RateLimitedProblem",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L246-L252 | train |
letsencrypt/boulder | probs/probs.go | TLSError | func TLSError(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: TLSProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func TLSError(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: TLSProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"TLSError",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"TLSProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // TLSError returns a ProblemDetails representing a TLSProblem error | [
"TLSError",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"TLSProblem",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L255-L261 | train |
letsencrypt/boulder | probs/probs.go | AccountDoesNotExist | func AccountDoesNotExist(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: AccountDoesNotExistProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func AccountDoesNotExist(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: AccountDoesNotExistProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"AccountDoesNotExist",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"AccountDoesNotExistProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // AccountDoesNotExist returns a ProblemDetails representing an
// AccountDoesNotExistProblem error | [
"AccountDoesNotExist",
"returns",
"a",
"ProblemDetails",
"representing",
"an",
"AccountDoesNotExistProblem",
"error"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L265-L271 | train |
letsencrypt/boulder | probs/probs.go | CAA | func CAA(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: CAAProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | go | func CAA(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: CAAProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | [
"func",
"CAA",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"CAAProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusForbidden",
",",
"}",
"\n",
"}"
] | // CAA returns a ProblemDetails representing a CAAProblem | [
"CAA",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"CAAProblem"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L274-L280 | train |
letsencrypt/boulder | probs/probs.go | DNS | func DNS(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: DNSProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | go | func DNS(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: DNSProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusBadRequest,
}
} | [
"func",
"DNS",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"DNSProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusBadRequest",
",",
"}",
"\n",
"}"
] | // DNS returns a ProblemDetails representing a DNSProblem | [
"DNS",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"DNSProblem"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L283-L289 | train |
letsencrypt/boulder | probs/probs.go | OrderNotReady | func OrderNotReady(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: OrderNotReadyProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | go | func OrderNotReady(detail string, a ...interface{}) *ProblemDetails {
return &ProblemDetails{
Type: OrderNotReadyProblem,
Detail: fmt.Sprintf(detail, a...),
HTTPStatus: http.StatusForbidden,
}
} | [
"func",
"OrderNotReady",
"(",
"detail",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ProblemDetails",
"{",
"return",
"&",
"ProblemDetails",
"{",
"Type",
":",
"OrderNotReadyProblem",
",",
"Detail",
":",
"fmt",
".",
"Sprintf",
"(",
"detail",
",",
"a",
"...",
")",
",",
"HTTPStatus",
":",
"http",
".",
"StatusForbidden",
",",
"}",
"\n",
"}"
] | // OrderNotReady returns a ProblemDetails representing a OrderNotReadyProblem | [
"OrderNotReady",
"returns",
"a",
"ProblemDetails",
"representing",
"a",
"OrderNotReadyProblem"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/probs/probs.go#L292-L298 | train |
letsencrypt/boulder | mocks/ca.go | IssueCertificate | func (ca *MockCA) IssueCertificate(ctx context.Context, _ *caPB.IssueCertificateRequest) (core.Certificate, error) {
if ca.PEM == nil {
return core.Certificate{}, fmt.Errorf("MockCA's PEM field must be set before calling IssueCertificate")
}
block, _ := pem.Decode(ca.PEM)
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return core.Certificate{}, err
}
return core.Certificate{
DER: cert.Raw,
}, nil
} | go | func (ca *MockCA) IssueCertificate(ctx context.Context, _ *caPB.IssueCertificateRequest) (core.Certificate, error) {
if ca.PEM == nil {
return core.Certificate{}, fmt.Errorf("MockCA's PEM field must be set before calling IssueCertificate")
}
block, _ := pem.Decode(ca.PEM)
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return core.Certificate{}, err
}
return core.Certificate{
DER: cert.Raw,
}, nil
} | [
"func",
"(",
"ca",
"*",
"MockCA",
")",
"IssueCertificate",
"(",
"ctx",
"context",
".",
"Context",
",",
"_",
"*",
"caPB",
".",
"IssueCertificateRequest",
")",
"(",
"core",
".",
"Certificate",
",",
"error",
")",
"{",
"if",
"ca",
".",
"PEM",
"==",
"nil",
"{",
"return",
"core",
".",
"Certificate",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"ca",
".",
"PEM",
")",
"\n",
"cert",
",",
"err",
":=",
"x509",
".",
"ParseCertificate",
"(",
"block",
".",
"Bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"core",
".",
"Certificate",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"core",
".",
"Certificate",
"{",
"DER",
":",
"cert",
".",
"Raw",
",",
"}",
",",
"nil",
"\n",
"}"
] | // IssueCertificate is a mock | [
"IssueCertificate",
"is",
"a",
"mock"
] | a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf | https://github.com/letsencrypt/boulder/blob/a3d35f51ff716e0d4916ac2c8ce5b6df16a95baf/mocks/ca.go#L22-L34 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.