repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
disintegration/imaging
tools.go
PasteCenter
func PasteCenter(background, img image.Image) *image.NRGBA { bgBounds := background.Bounds() bgW := bgBounds.Dx() bgH := bgBounds.Dy() bgMinX := bgBounds.Min.X bgMinY := bgBounds.Min.Y centerX := bgMinX + bgW/2 centerY := bgMinY + bgH/2 x0 := centerX - img.Bounds().Dx()/2 y0 := centerY - img.Bounds().Dy()/2 ...
go
func PasteCenter(background, img image.Image) *image.NRGBA { bgBounds := background.Bounds() bgW := bgBounds.Dx() bgH := bgBounds.Dy() bgMinX := bgBounds.Min.X bgMinY := bgBounds.Min.Y centerX := bgMinX + bgW/2 centerY := bgMinY + bgH/2 x0 := centerX - img.Bounds().Dx()/2 y0 := centerY - img.Bounds().Dy()/2 ...
[ "func", "PasteCenter", "(", "background", ",", "img", "image", ".", "Image", ")", "*", "image", ".", "NRGBA", "{", "bgBounds", ":=", "background", ".", "Bounds", "(", ")", "\n", "bgW", ":=", "bgBounds", ".", "Dx", "(", ")", "\n", "bgH", ":=", "bgBoun...
// PasteCenter pastes the img image to the center of the background image and returns the combined image.
[ "PasteCenter", "pastes", "the", "img", "image", "to", "the", "center", "of", "the", "background", "image", "and", "returns", "the", "combined", "image", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L152-L166
train
disintegration/imaging
tools.go
OverlayCenter
func OverlayCenter(background, img image.Image, opacity float64) *image.NRGBA { bgBounds := background.Bounds() bgW := bgBounds.Dx() bgH := bgBounds.Dy() bgMinX := bgBounds.Min.X bgMinY := bgBounds.Min.Y centerX := bgMinX + bgW/2 centerY := bgMinY + bgH/2 x0 := centerX - img.Bounds().Dx()/2 y0 := centerY - i...
go
func OverlayCenter(background, img image.Image, opacity float64) *image.NRGBA { bgBounds := background.Bounds() bgW := bgBounds.Dx() bgH := bgBounds.Dy() bgMinX := bgBounds.Min.X bgMinY := bgBounds.Min.Y centerX := bgMinX + bgW/2 centerY := bgMinY + bgH/2 x0 := centerX - img.Bounds().Dx()/2 y0 := centerY - i...
[ "func", "OverlayCenter", "(", "background", ",", "img", "image", ".", "Image", ",", "opacity", "float64", ")", "*", "image", ".", "NRGBA", "{", "bgBounds", ":=", "background", ".", "Bounds", "(", ")", "\n", "bgW", ":=", "bgBounds", ".", "Dx", "(", ")",...
// OverlayCenter overlays the img image to the center of the background image and // returns the combined image. Opacity parameter is the opacity of the img // image layer, used to compose the images, it must be from 0.0 to 1.0.
[ "OverlayCenter", "overlays", "the", "img", "image", "to", "the", "center", "of", "the", "background", "image", "and", "returns", "the", "combined", "image", ".", "Opacity", "parameter", "is", "the", "opacity", "of", "the", "img", "image", "layer", "used", "t...
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L235-L249
train
disintegration/imaging
transform.go
Rotate
func Rotate(img image.Image, angle float64, bgColor color.Color) *image.NRGBA { angle = angle - math.Floor(angle/360)*360 switch angle { case 0: return Clone(img) case 90: return Rotate90(img) case 180: return Rotate180(img) case 270: return Rotate270(img) } src := toNRGBA(img) srcW := src.Bounds().M...
go
func Rotate(img image.Image, angle float64, bgColor color.Color) *image.NRGBA { angle = angle - math.Floor(angle/360)*360 switch angle { case 0: return Clone(img) case 90: return Rotate90(img) case 180: return Rotate180(img) case 270: return Rotate270(img) } src := toNRGBA(img) srcW := src.Bounds().M...
[ "func", "Rotate", "(", "img", "image", ".", "Image", ",", "angle", "float64", ",", "bgColor", "color", ".", "Color", ")", "*", "image", ".", "NRGBA", "{", "angle", "=", "angle", "-", "math", ".", "Floor", "(", "angle", "/", "360", ")", "*", "360", ...
// Rotate rotates an image by the given angle counter-clockwise . // The angle parameter is the rotation angle in degrees. // The bgColor parameter specifies the color of the uncovered zone after the rotation.
[ "Rotate", "rotates", "an", "image", "by", "the", "given", "angle", "counter", "-", "clockwise", ".", "The", "angle", "parameter", "is", "the", "rotation", "angle", "in", "degrees", ".", "The", "bgColor", "parameter", "specifies", "the", "color", "of", "the",...
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/transform.go#L135-L178
train
disintegration/imaging
utils.go
parallel
func parallel(start, stop int, fn func(<-chan int)) { count := stop - start if count < 1 { return } procs := runtime.GOMAXPROCS(0) if procs > count { procs = count } c := make(chan int, count) for i := start; i < stop; i++ { c <- i } close(c) var wg sync.WaitGroup for i := 0; i < procs; i++ { wg....
go
func parallel(start, stop int, fn func(<-chan int)) { count := stop - start if count < 1 { return } procs := runtime.GOMAXPROCS(0) if procs > count { procs = count } c := make(chan int, count) for i := start; i < stop; i++ { c <- i } close(c) var wg sync.WaitGroup for i := 0; i < procs; i++ { wg....
[ "func", "parallel", "(", "start", ",", "stop", "int", ",", "fn", "func", "(", "<-", "chan", "int", ")", ")", "{", "count", ":=", "stop", "-", "start", "\n", "if", "count", "<", "1", "{", "return", "\n", "}", "\n\n", "procs", ":=", "runtime", ".",...
// parallel processes the data in separate goroutines.
[ "parallel", "processes", "the", "data", "in", "separate", "goroutines", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/utils.go#L11-L37
train
disintegration/imaging
utils.go
clamp
func clamp(x float64) uint8 { v := int64(x + 0.5) if v > 255 { return 255 } if v > 0 { return uint8(v) } return 0 }
go
func clamp(x float64) uint8 { v := int64(x + 0.5) if v > 255 { return 255 } if v > 0 { return uint8(v) } return 0 }
[ "func", "clamp", "(", "x", "float64", ")", "uint8", "{", "v", ":=", "int64", "(", "x", "+", "0.5", ")", "\n", "if", "v", ">", "255", "{", "return", "255", "\n", "}", "\n", "if", "v", ">", "0", "{", "return", "uint8", "(", "v", ")", "\n", "}...
// clamp rounds and clamps float64 value to fit into uint8.
[ "clamp", "rounds", "and", "clamps", "float64", "value", "to", "fit", "into", "uint8", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/utils.go#L48-L57
train
disintegration/imaging
utils.go
rgbToHSL
func rgbToHSL(r, g, b uint8) (float64, float64, float64) { rr := float64(r) / 255 gg := float64(g) / 255 bb := float64(b) / 255 max := math.Max(rr, math.Max(gg, bb)) min := math.Min(rr, math.Min(gg, bb)) l := (max + min) / 2 if max == min { return 0, 0, l } var h, s float64 d := max - min if l > 0.5 { ...
go
func rgbToHSL(r, g, b uint8) (float64, float64, float64) { rr := float64(r) / 255 gg := float64(g) / 255 bb := float64(b) / 255 max := math.Max(rr, math.Max(gg, bb)) min := math.Min(rr, math.Min(gg, bb)) l := (max + min) / 2 if max == min { return 0, 0, l } var h, s float64 d := max - min if l > 0.5 { ...
[ "func", "rgbToHSL", "(", "r", ",", "g", ",", "b", "uint8", ")", "(", "float64", ",", "float64", ",", "float64", ")", "{", "rr", ":=", "float64", "(", "r", ")", "/", "255", "\n", "gg", ":=", "float64", "(", "g", ")", "/", "255", "\n", "bb", ":...
// rgbToHSL converts a color from RGB to HSL.
[ "rgbToHSL", "converts", "a", "color", "from", "RGB", "to", "HSL", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/utils.go#L89-L125
train
disintegration/imaging
utils.go
hslToRGB
func hslToRGB(h, s, l float64) (uint8, uint8, uint8) { var r, g, b float64 if s == 0 { v := clamp(l * 255) return v, v, v } var q float64 if l < 0.5 { q = l * (1 + s) } else { q = l + s - l*s } p := 2*l - q r = hueToRGB(p, q, h+1/3.0) g = hueToRGB(p, q, h) b = hueToRGB(p, q, h-1/3.0) return clamp...
go
func hslToRGB(h, s, l float64) (uint8, uint8, uint8) { var r, g, b float64 if s == 0 { v := clamp(l * 255) return v, v, v } var q float64 if l < 0.5 { q = l * (1 + s) } else { q = l + s - l*s } p := 2*l - q r = hueToRGB(p, q, h+1/3.0) g = hueToRGB(p, q, h) b = hueToRGB(p, q, h-1/3.0) return clamp...
[ "func", "hslToRGB", "(", "h", ",", "s", ",", "l", "float64", ")", "(", "uint8", ",", "uint8", ",", "uint8", ")", "{", "var", "r", ",", "g", ",", "b", "float64", "\n", "if", "s", "==", "0", "{", "v", ":=", "clamp", "(", "l", "*", "255", ")",...
// hslToRGB converts a color from HSL to RGB.
[ "hslToRGB", "converts", "a", "color", "from", "HSL", "to", "RGB", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/utils.go#L128-L148
train
disintegration/imaging
resize.go
resizeNearest
func resizeNearest(img image.Image, width, height int) *image.NRGBA { dst := image.NewNRGBA(image.Rect(0, 0, width, height)) dx := float64(img.Bounds().Dx()) / float64(width) dy := float64(img.Bounds().Dy()) / float64(height) if dx > 1 && dy > 1 { src := newScanner(img) parallel(0, height, func(ys <-chan int) ...
go
func resizeNearest(img image.Image, width, height int) *image.NRGBA { dst := image.NewNRGBA(image.Rect(0, 0, width, height)) dx := float64(img.Bounds().Dx()) / float64(width) dy := float64(img.Bounds().Dy()) / float64(height) if dx > 1 && dy > 1 { src := newScanner(img) parallel(0, height, func(ys <-chan int) ...
[ "func", "resizeNearest", "(", "img", "image", ".", "Image", ",", "width", ",", "height", "int", ")", "*", "image", ".", "NRGBA", "{", "dst", ":=", "image", ".", "NewNRGBA", "(", "image", ".", "Rect", "(", "0", ",", "0", ",", "width", ",", "height",...
// resizeNearest is a fast nearest-neighbor resize, no filtering.
[ "resizeNearest", "is", "a", "fast", "nearest", "-", "neighbor", "resize", "no", "filtering", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/resize.go#L177-L213
train
disintegration/imaging
resize.go
cropAndResize
func cropAndResize(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA { dstW, dstH := width, height srcBounds := img.Bounds() srcW := srcBounds.Dx() srcH := srcBounds.Dy() srcAspectRatio := float64(srcW) / float64(srcH) dstAspectRatio := float64(dstW) / float64(dstH) var tmp...
go
func cropAndResize(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA { dstW, dstH := width, height srcBounds := img.Bounds() srcW := srcBounds.Dx() srcH := srcBounds.Dy() srcAspectRatio := float64(srcW) / float64(srcH) dstAspectRatio := float64(dstW) / float64(dstH) var tmp...
[ "func", "cropAndResize", "(", "img", "image", ".", "Image", ",", "width", ",", "height", "int", ",", "anchor", "Anchor", ",", "filter", "ResampleFilter", ")", "*", "image", ".", "NRGBA", "{", "dstW", ",", "dstH", ":=", "width", ",", "height", "\n\n", "...
// cropAndResize crops the image to the smallest possible size that has the required aspect ratio using // the given anchor point, then scales it to the specified dimensions and returns the transformed image. // // This is generally faster than resizing first, but may result in inaccuracies when used on small source im...
[ "cropAndResize", "crops", "the", "image", "to", "the", "smallest", "possible", "size", "that", "has", "the", "required", "aspect", "ratio", "using", "the", "given", "anchor", "point", "then", "scales", "it", "to", "the", "specified", "dimensions", "and", "retu...
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/resize.go#L292-L311
train
disintegration/imaging
resize.go
resizeAndCrop
func resizeAndCrop(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA { dstW, dstH := width, height srcBounds := img.Bounds() srcW := srcBounds.Dx() srcH := srcBounds.Dy() srcAspectRatio := float64(srcW) / float64(srcH) dstAspectRatio := float64(dstW) / float64(dstH) var tmp...
go
func resizeAndCrop(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA { dstW, dstH := width, height srcBounds := img.Bounds() srcW := srcBounds.Dx() srcH := srcBounds.Dy() srcAspectRatio := float64(srcW) / float64(srcH) dstAspectRatio := float64(dstW) / float64(dstH) var tmp...
[ "func", "resizeAndCrop", "(", "img", "image", ".", "Image", ",", "width", ",", "height", "int", ",", "anchor", "Anchor", ",", "filter", "ResampleFilter", ")", "*", "image", ".", "NRGBA", "{", "dstW", ",", "dstH", ":=", "width", ",", "height", "\n\n", "...
// resizeAndCrop resizes the image to the smallest possible size that will cover the specified dimensions, // crops the resized image to the specified dimensions using the given anchor point and returns // the transformed image.
[ "resizeAndCrop", "resizes", "the", "image", "to", "the", "smallest", "possible", "size", "that", "will", "cover", "the", "specified", "dimensions", "crops", "the", "resized", "image", "to", "the", "specified", "dimensions", "using", "the", "given", "anchor", "po...
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/resize.go#L316-L333
train
disintegration/imaging
adjust.go
Grayscale
func Grayscale(img image.Image) *image.NRGBA { src := newScanner(img) dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h)) parallel(0, src.h, func(ys <-chan int) { for y := range ys { i := y * dst.Stride src.scan(0, y, src.w, y+1, dst.Pix[i:i+src.w*4]) for x := 0; x < src.w; x++ { d := dst.Pix[i : i+...
go
func Grayscale(img image.Image) *image.NRGBA { src := newScanner(img) dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h)) parallel(0, src.h, func(ys <-chan int) { for y := range ys { i := y * dst.Stride src.scan(0, y, src.w, y+1, dst.Pix[i:i+src.w*4]) for x := 0; x < src.w; x++ { d := dst.Pix[i : i+...
[ "func", "Grayscale", "(", "img", "image", ".", "Image", ")", "*", "image", ".", "NRGBA", "{", "src", ":=", "newScanner", "(", "img", ")", "\n", "dst", ":=", "image", ".", "NewNRGBA", "(", "image", ".", "Rect", "(", "0", ",", "0", ",", "src", ".",...
// Grayscale produces a grayscale version of the image.
[ "Grayscale", "produces", "a", "grayscale", "version", "of", "the", "image", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/adjust.go#L10-L32
train
disintegration/imaging
io.go
Decode
func Decode(r io.Reader, opts ...DecodeOption) (image.Image, error) { cfg := defaultDecodeConfig for _, option := range opts { option(&cfg) } if !cfg.autoOrientation { img, _, err := image.Decode(r) return img, err } var orient orientation pr, pw := io.Pipe() r = io.TeeReader(r, pw) done := make(chan s...
go
func Decode(r io.Reader, opts ...DecodeOption) (image.Image, error) { cfg := defaultDecodeConfig for _, option := range opts { option(&cfg) } if !cfg.autoOrientation { img, _, err := image.Decode(r) return img, err } var orient orientation pr, pw := io.Pipe() r = io.TeeReader(r, pw) done := make(chan s...
[ "func", "Decode", "(", "r", "io", ".", "Reader", ",", "opts", "...", "DecodeOption", ")", "(", "image", ".", "Image", ",", "error", ")", "{", "cfg", ":=", "defaultDecodeConfig", "\n", "for", "_", ",", "option", ":=", "range", "opts", "{", "option", "...
// Decode reads an image from r.
[ "Decode", "reads", "an", "image", "from", "r", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/io.go#L54-L83
train
disintegration/imaging
io.go
GIFQuantizer
func GIFQuantizer(quantizer draw.Quantizer) EncodeOption { return func(c *encodeConfig) { c.gifQuantizer = quantizer } }
go
func GIFQuantizer(quantizer draw.Quantizer) EncodeOption { return func(c *encodeConfig) { c.gifQuantizer = quantizer } }
[ "func", "GIFQuantizer", "(", "quantizer", "draw", ".", "Quantizer", ")", "EncodeOption", "{", "return", "func", "(", "c", "*", "encodeConfig", ")", "{", "c", ".", "gifQuantizer", "=", "quantizer", "\n", "}", "\n", "}" ]
// GIFQuantizer returns an EncodeOption that sets the quantizer that is used to produce // a palette of the GIF-encoded image.
[ "GIFQuantizer", "returns", "an", "EncodeOption", "that", "sets", "the", "quantizer", "that", "is", "used", "to", "produce", "a", "palette", "of", "the", "GIF", "-", "encoded", "image", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/io.go#L194-L198
train
disintegration/imaging
io.go
GIFDrawer
func GIFDrawer(drawer draw.Drawer) EncodeOption { return func(c *encodeConfig) { c.gifDrawer = drawer } }
go
func GIFDrawer(drawer draw.Drawer) EncodeOption { return func(c *encodeConfig) { c.gifDrawer = drawer } }
[ "func", "GIFDrawer", "(", "drawer", "draw", ".", "Drawer", ")", "EncodeOption", "{", "return", "func", "(", "c", "*", "encodeConfig", ")", "{", "c", ".", "gifDrawer", "=", "drawer", "\n", "}", "\n", "}" ]
// GIFDrawer returns an EncodeOption that sets the drawer that is used to convert // the source image to the desired palette of the GIF-encoded image.
[ "GIFDrawer", "returns", "an", "EncodeOption", "that", "sets", "the", "drawer", "that", "is", "used", "to", "convert", "the", "source", "image", "to", "the", "desired", "palette", "of", "the", "GIF", "-", "encoded", "image", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/io.go#L202-L206
train
disintegration/imaging
io.go
PNGCompressionLevel
func PNGCompressionLevel(level png.CompressionLevel) EncodeOption { return func(c *encodeConfig) { c.pngCompressionLevel = level } }
go
func PNGCompressionLevel(level png.CompressionLevel) EncodeOption { return func(c *encodeConfig) { c.pngCompressionLevel = level } }
[ "func", "PNGCompressionLevel", "(", "level", "png", ".", "CompressionLevel", ")", "EncodeOption", "{", "return", "func", "(", "c", "*", "encodeConfig", ")", "{", "c", ".", "pngCompressionLevel", "=", "level", "\n", "}", "\n", "}" ]
// PNGCompressionLevel returns an EncodeOption that sets the compression level // of the PNG-encoded image. Default is png.DefaultCompression.
[ "PNGCompressionLevel", "returns", "an", "EncodeOption", "that", "sets", "the", "compression", "level", "of", "the", "PNG", "-", "encoded", "image", ".", "Default", "is", "png", ".", "DefaultCompression", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/io.go#L210-L214
train
disintegration/imaging
io.go
fixOrientation
func fixOrientation(img image.Image, o orientation) image.Image { switch o { case orientationNormal: case orientationFlipH: img = FlipH(img) case orientationFlipV: img = FlipV(img) case orientationRotate90: img = Rotate90(img) case orientationRotate180: img = Rotate180(img) case orientationRotate270: i...
go
func fixOrientation(img image.Image, o orientation) image.Image { switch o { case orientationNormal: case orientationFlipH: img = FlipH(img) case orientationFlipV: img = FlipV(img) case orientationRotate90: img = Rotate90(img) case orientationRotate180: img = Rotate180(img) case orientationRotate270: i...
[ "func", "fixOrientation", "(", "img", "image", ".", "Image", ",", "o", "orientation", ")", "image", ".", "Image", "{", "switch", "o", "{", "case", "orientationNormal", ":", "case", "orientationFlipH", ":", "img", "=", "FlipH", "(", "img", ")", "\n", "cas...
// fixOrientation applies a transform to img corresponding to the given orientation flag.
[ "fixOrientation", "applies", "a", "transform", "to", "img", "corresponding", "to", "the", "given", "orientation", "flag", "." ]
061e8a750a4db9667cdf9e2af7f4029ba506cb3b
https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/io.go#L425-L444
train
rqlite/rqlite
tcp/transport.go
NewTLSTransport
func NewTLSTransport(certFile, keyPath string, skipVerify bool) *Transport { return &Transport{ certFile: certFile, certKey: keyPath, remoteEncrypted: true, skipVerify: skipVerify, } }
go
func NewTLSTransport(certFile, keyPath string, skipVerify bool) *Transport { return &Transport{ certFile: certFile, certKey: keyPath, remoteEncrypted: true, skipVerify: skipVerify, } }
[ "func", "NewTLSTransport", "(", "certFile", ",", "keyPath", "string", ",", "skipVerify", "bool", ")", "*", "Transport", "{", "return", "&", "Transport", "{", "certFile", ":", "certFile", ",", "certKey", ":", "keyPath", ",", "remoteEncrypted", ":", "true", ",...
// NewTLSTransport returns an initialized TLS-ecrypted Transport.
[ "NewTLSTransport", "returns", "an", "initialized", "TLS", "-", "ecrypted", "Transport", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/tcp/transport.go#L26-L33
train
rqlite/rqlite
tcp/transport.go
Open
func (t *Transport) Open(addr string) error { ln, err := net.Listen("tcp", addr) if err != nil { return err } if t.certFile != "" { config, err := createTLSConfig(t.certFile, t.certKey) if err != nil { return err } ln = tls.NewListener(ln, config) } t.ln = ln return nil }
go
func (t *Transport) Open(addr string) error { ln, err := net.Listen("tcp", addr) if err != nil { return err } if t.certFile != "" { config, err := createTLSConfig(t.certFile, t.certKey) if err != nil { return err } ln = tls.NewListener(ln, config) } t.ln = ln return nil }
[ "func", "(", "t", "*", "Transport", ")", "Open", "(", "addr", "string", ")", "error", "{", "ln", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", ...
// Open opens the transport, binding to the supplied address.
[ "Open", "opens", "the", "transport", "binding", "to", "the", "supplied", "address", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/tcp/transport.go#L36-L51
train
rqlite/rqlite
tcp/transport.go
Dial
func (t *Transport) Dial(addr string, timeout time.Duration) (net.Conn, error) { dialer := &net.Dialer{Timeout: timeout} var err error var conn net.Conn if t.remoteEncrypted { conf := &tls.Config{ InsecureSkipVerify: t.skipVerify, } fmt.Println("doing a TLS dial") conn, err = tls.DialWithDialer(dialer, ...
go
func (t *Transport) Dial(addr string, timeout time.Duration) (net.Conn, error) { dialer := &net.Dialer{Timeout: timeout} var err error var conn net.Conn if t.remoteEncrypted { conf := &tls.Config{ InsecureSkipVerify: t.skipVerify, } fmt.Println("doing a TLS dial") conn, err = tls.DialWithDialer(dialer, ...
[ "func", "(", "t", "*", "Transport", ")", "Dial", "(", "addr", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "dialer", ":=", "&", "net", ".", "Dialer", "{", "Timeout", ":", "timeout", "}", ...
// Dial opens a network connection.
[ "Dial", "opens", "a", "network", "connection", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/tcp/transport.go#L54-L70
train
rqlite/rqlite
cmd/rqbench/http.go
Prepare
func (h *HTTPTester) Prepare(stmt string, bSz int, tx bool) error { s := make([]string, bSz) for i := 0; i < len(s); i++ { s[i] = stmt } b, err := json.Marshal(s) if err != nil { return err } h.br = bytes.NewReader(b) if tx { h.url = h.url + "?transaction" } return nil }
go
func (h *HTTPTester) Prepare(stmt string, bSz int, tx bool) error { s := make([]string, bSz) for i := 0; i < len(s); i++ { s[i] = stmt } b, err := json.Marshal(s) if err != nil { return err } h.br = bytes.NewReader(b) if tx { h.url = h.url + "?transaction" } return nil }
[ "func", "(", "h", "*", "HTTPTester", ")", "Prepare", "(", "stmt", "string", ",", "bSz", "int", ",", "tx", "bool", ")", "error", "{", "s", ":=", "make", "(", "[", "]", "string", ",", "bSz", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len...
// Prepare prepares the tester for execution.
[ "Prepare", "prepares", "the", "tester", "for", "execution", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqbench/http.go#L28-L45
train
rqlite/rqlite
cmd/rqbench/http.go
Once
func (h *HTTPTester) Once() (time.Duration, error) { h.br.Seek(0, io.SeekStart) start := time.Now() resp, err := h.client.Post(h.url, "application/json", h.br) if err != nil { return 0, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return 0, fmt.Errorf("received %s", resp.Status) } ...
go
func (h *HTTPTester) Once() (time.Duration, error) { h.br.Seek(0, io.SeekStart) start := time.Now() resp, err := h.client.Post(h.url, "application/json", h.br) if err != nil { return 0, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return 0, fmt.Errorf("received %s", resp.Status) } ...
[ "func", "(", "h", "*", "HTTPTester", ")", "Once", "(", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "h", ".", "br", ".", "Seek", "(", "0", ",", "io", ".", "SeekStart", ")", "\n\n", "start", ":=", "time", ".", "Now", "(", ")", "\...
// Once executes a single test request.
[ "Once", "executes", "a", "single", "test", "request", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqbench/http.go#L48-L64
train
rqlite/rqlite
store/peers.go
NumPeers
func NumPeers(raftDir string) (int, error) { // Read the file buf, err := ioutil.ReadFile(filepath.Join(raftDir, jsonPeerPath)) if err != nil && !os.IsNotExist(err) { return 0, err } // Check for no peers if len(buf) == 0 { return 0, nil } // Decode the peers var peerSet []string dec := json.NewDecoder(...
go
func NumPeers(raftDir string) (int, error) { // Read the file buf, err := ioutil.ReadFile(filepath.Join(raftDir, jsonPeerPath)) if err != nil && !os.IsNotExist(err) { return 0, err } // Check for no peers if len(buf) == 0 { return 0, nil } // Decode the peers var peerSet []string dec := json.NewDecoder(...
[ "func", "NumPeers", "(", "raftDir", "string", ")", "(", "int", ",", "error", ")", "{", "// Read the file", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ".", "Join", "(", "raftDir", ",", "jsonPeerPath", ")", ")", "\n", "if", "err...
// NumPeers returns the number of peers indicated by the config files // within raftDir. // // This code makes assumptions about how the Raft module works.
[ "NumPeers", "returns", "the", "number", "of", "peers", "indicated", "by", "the", "config", "files", "within", "raftDir", ".", "This", "code", "makes", "assumptions", "about", "how", "the", "Raft", "module", "works", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/peers.go#L19-L39
train
rqlite/rqlite
store/peers.go
JoinAllowed
func JoinAllowed(raftDir string) (bool, error) { n, err := NumPeers(raftDir) if err != nil { return false, err } return n <= 1, nil }
go
func JoinAllowed(raftDir string) (bool, error) { n, err := NumPeers(raftDir) if err != nil { return false, err } return n <= 1, nil }
[ "func", "JoinAllowed", "(", "raftDir", "string", ")", "(", "bool", ",", "error", ")", "{", "n", ",", "err", ":=", "NumPeers", "(", "raftDir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "n", ...
// JoinAllowed returns whether the config files within raftDir indicate // that the node can join a cluster.
[ "JoinAllowed", "returns", "whether", "the", "config", "files", "within", "raftDir", "indicate", "that", "the", "node", "can", "join", "a", "cluster", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/peers.go#L43-L49
train
rqlite/rqlite
store/store.go
New
func New(ln Listener, c *StoreConfig) *Store { logger := c.Logger if logger == nil { logger = log.New(os.Stderr, "[store] ", log.LstdFlags) } return &Store{ ln: ln, raftDir: c.Dir, raftID: c.ID, dbConf: c.DBConf, dbPath: filepath.Join(c.Dir, sqliteFile), ran...
go
func New(ln Listener, c *StoreConfig) *Store { logger := c.Logger if logger == nil { logger = log.New(os.Stderr, "[store] ", log.LstdFlags) } return &Store{ ln: ln, raftDir: c.Dir, raftID: c.ID, dbConf: c.DBConf, dbPath: filepath.Join(c.Dir, sqliteFile), ran...
[ "func", "New", "(", "ln", "Listener", ",", "c", "*", "StoreConfig", ")", "*", "Store", "{", "logger", ":=", "c", ".", "Logger", "\n", "if", "logger", "==", "nil", "{", "logger", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ...
// New returns a new Store.
[ "New", "returns", "a", "new", "Store", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L220-L240
train
rqlite/rqlite
store/store.go
Open
func (s *Store) Open(enableSingle bool) error { s.closedMu.Lock() defer s.closedMu.Unlock() if s.closed { return ErrStoreInvalidState } s.logger.Printf("opening store with node ID %s", s.raftID) s.logger.Printf("ensuring directory at %s exists", s.raftDir) if err := os.MkdirAll(s.raftDir, 0755); err != nil {...
go
func (s *Store) Open(enableSingle bool) error { s.closedMu.Lock() defer s.closedMu.Unlock() if s.closed { return ErrStoreInvalidState } s.logger.Printf("opening store with node ID %s", s.raftID) s.logger.Printf("ensuring directory at %s exists", s.raftDir) if err := os.MkdirAll(s.raftDir, 0755); err != nil {...
[ "func", "(", "s", "*", "Store", ")", "Open", "(", "enableSingle", "bool", ")", "error", "{", "s", ".", "closedMu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "closedMu", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "closed", "{", "return",...
// Open opens the store. If enableSingle is set, and there are no existing peers, // then this node becomes the first node, and therefore leader, of the cluster.
[ "Open", "opens", "the", "store", ".", "If", "enableSingle", "is", "set", "and", "there", "are", "no", "existing", "peers", "then", "this", "node", "becomes", "the", "first", "node", "and", "therefore", "leader", "of", "the", "cluster", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L244-L327
train
rqlite/rqlite
store/store.go
Connect
func (s *Store) Connect(opt *ConnectionOptions) (*Connection, error) { // Randomly-selected connection ID must be part of command so // that all nodes use the same value as connection ID. connID := func() uint64 { s.connsMu.Lock() defer s.connsMu.Unlock() for { // Make sure we get an unused ID. id := s.r...
go
func (s *Store) Connect(opt *ConnectionOptions) (*Connection, error) { // Randomly-selected connection ID must be part of command so // that all nodes use the same value as connection ID. connID := func() uint64 { s.connsMu.Lock() defer s.connsMu.Unlock() for { // Make sure we get an unused ID. id := s.r...
[ "func", "(", "s", "*", "Store", ")", "Connect", "(", "opt", "*", "ConnectionOptions", ")", "(", "*", "Connection", ",", "error", ")", "{", "// Randomly-selected connection ID must be part of command so", "// that all nodes use the same value as connection ID.", "connID", ...
// Connect returns a new connection to the database. Changes made to the database // through this connection are applied via the Raft consensus system. The Store // must have been opened first. Must be called on the leader or an error will // we returned. // // Any connection returned by this call are READ_COMMITTED is...
[ "Connect", "returns", "a", "new", "connection", "to", "the", "database", ".", "Changes", "made", "to", "the", "database", "through", "this", "connection", "are", "applied", "via", "the", "Raft", "consensus", "system", ".", "The", "Store", "must", "have", "be...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L336-L381
train
rqlite/rqlite
store/store.go
Execute
func (s *Store) Execute(ex *ExecuteRequest) (*ExecuteResponse, error) { return s.execute(nil, ex) }
go
func (s *Store) Execute(ex *ExecuteRequest) (*ExecuteResponse, error) { return s.execute(nil, ex) }
[ "func", "(", "s", "*", "Store", ")", "Execute", "(", "ex", "*", "ExecuteRequest", ")", "(", "*", "ExecuteResponse", ",", "error", ")", "{", "return", "s", ".", "execute", "(", "nil", ",", "ex", ")", "\n", "}" ]
// Execute executes queries that return no rows, but do modify the database. // Changes made to the database through this call are applied via the Raft // consensus system. The Store must have been opened first. Must be called // on the leader or an error will we returned. The changes are made using // the database con...
[ "Execute", "executes", "queries", "that", "return", "no", "rows", "but", "do", "modify", "the", "database", ".", "Changes", "made", "to", "the", "database", "through", "this", "call", "are", "applied", "via", "the", "Raft", "consensus", "system", ".", "The",...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L388-L390
train
rqlite/rqlite
store/store.go
ExecuteOrAbort
func (s *Store) ExecuteOrAbort(ex *ExecuteRequest) (resp *ExecuteResponse, retErr error) { return s.executeOrAbort(nil, ex) }
go
func (s *Store) ExecuteOrAbort(ex *ExecuteRequest) (resp *ExecuteResponse, retErr error) { return s.executeOrAbort(nil, ex) }
[ "func", "(", "s", "*", "Store", ")", "ExecuteOrAbort", "(", "ex", "*", "ExecuteRequest", ")", "(", "resp", "*", "ExecuteResponse", ",", "retErr", "error", ")", "{", "return", "s", ".", "executeOrAbort", "(", "nil", ",", "ex", ")", "\n", "}" ]
// ExecuteOrAbort executes the requests, but aborts any active transaction // on the underlying database in the case of any error. Any changes are made // using the database connection built-in to the Store.
[ "ExecuteOrAbort", "executes", "the", "requests", "but", "aborts", "any", "active", "transaction", "on", "the", "underlying", "database", "in", "the", "case", "of", "any", "error", ".", "Any", "changes", "are", "made", "using", "the", "database", "connection", ...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L395-L397
train
rqlite/rqlite
store/store.go
Query
func (s *Store) Query(qr *QueryRequest) (*QueryResponse, error) { return s.query(nil, qr) }
go
func (s *Store) Query(qr *QueryRequest) (*QueryResponse, error) { return s.query(nil, qr) }
[ "func", "(", "s", "*", "Store", ")", "Query", "(", "qr", "*", "QueryRequest", ")", "(", "*", "QueryResponse", ",", "error", ")", "{", "return", "s", ".", "query", "(", "nil", ",", "qr", ")", "\n", "}" ]
// Query executes queries that return rows, and do not modify the database. // The queries are made using the database connection built-in to the Store. // Depending on the read consistency requested, it may or may not need to be // called on the leader.
[ "Query", "executes", "queries", "that", "return", "rows", "and", "do", "not", "modify", "the", "database", ".", "The", "queries", "are", "made", "using", "the", "database", "connection", "built", "-", "in", "to", "the", "Store", ".", "Depending", "on", "th...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L403-L405
train
rqlite/rqlite
store/store.go
Close
func (s *Store) Close(wait bool) error { s.closedMu.Lock() defer s.closedMu.Unlock() if s.closed { return nil } defer func() { s.closed = true }() close(s.done) s.wg.Wait() // XXX CLOSE OTHER CONNECTIONS if err := s.dbConn.Close(); err != nil { return err } s.dbConn = nil s.db = nil if s.raft != ...
go
func (s *Store) Close(wait bool) error { s.closedMu.Lock() defer s.closedMu.Unlock() if s.closed { return nil } defer func() { s.closed = true }() close(s.done) s.wg.Wait() // XXX CLOSE OTHER CONNECTIONS if err := s.dbConn.Close(); err != nil { return err } s.dbConn = nil s.db = nil if s.raft != ...
[ "func", "(", "s", "*", "Store", ")", "Close", "(", "wait", "bool", ")", "error", "{", "s", ".", "closedMu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "closedMu", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "closed", "{", "return", "nil...
// Close closes the store. If wait is true, waits for a graceful shutdown. // Once closed, a Store may not be re-opened.
[ "Close", "closes", "the", "store", ".", "If", "wait", "is", "true", "waits", "for", "a", "graceful", "shutdown", ".", "Once", "closed", "a", "Store", "may", "not", "be", "re", "-", "opened", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L409-L448
train
rqlite/rqlite
store/store.go
WaitForApplied
func (s *Store) WaitForApplied(timeout time.Duration) error { if timeout == 0 { return nil } s.logger.Printf("waiting for up to %s for application of initial logs", timeout) if err := s.WaitForAppliedIndex(s.raft.LastIndex(), timeout); err != nil { return ErrOpenTimeout } return nil }
go
func (s *Store) WaitForApplied(timeout time.Duration) error { if timeout == 0 { return nil } s.logger.Printf("waiting for up to %s for application of initial logs", timeout) if err := s.WaitForAppliedIndex(s.raft.LastIndex(), timeout); err != nil { return ErrOpenTimeout } return nil }
[ "func", "(", "s", "*", "Store", ")", "WaitForApplied", "(", "timeout", "time", ".", "Duration", ")", "error", "{", "if", "timeout", "==", "0", "{", "return", "nil", "\n", "}", "\n", "s", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "timeout"...
// WaitForApplied waits for all Raft log entries to to be applied to the // underlying database.
[ "WaitForApplied", "waits", "for", "all", "Raft", "log", "entries", "to", "to", "be", "applied", "to", "the", "underlying", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L452-L461
train
rqlite/rqlite
store/store.go
State
func (s *Store) State() ClusterState { state := s.raft.State() switch state { case raft.Leader: return Leader case raft.Candidate: return Candidate case raft.Follower: return Follower case raft.Shutdown: return Shutdown default: return Unknown } }
go
func (s *Store) State() ClusterState { state := s.raft.State() switch state { case raft.Leader: return Leader case raft.Candidate: return Candidate case raft.Follower: return Follower case raft.Shutdown: return Shutdown default: return Unknown } }
[ "func", "(", "s", "*", "Store", ")", "State", "(", ")", "ClusterState", "{", "state", ":=", "s", ".", "raft", ".", "State", "(", ")", "\n", "switch", "state", "{", "case", "raft", ".", "Leader", ":", "return", "Leader", "\n", "case", "raft", ".", ...
// State returns the current node's Raft state
[ "State", "returns", "the", "current", "node", "s", "Raft", "state" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L469-L483
train
rqlite/rqlite
store/store.go
Connection
func (s *Store) Connection(id uint64) (*Connection, bool) { s.connsMu.RLock() defer s.connsMu.RUnlock() c, ok := s.conns[id] return c, ok }
go
func (s *Store) Connection(id uint64) (*Connection, bool) { s.connsMu.RLock() defer s.connsMu.RUnlock() c, ok := s.conns[id] return c, ok }
[ "func", "(", "s", "*", "Store", ")", "Connection", "(", "id", "uint64", ")", "(", "*", "Connection", ",", "bool", ")", "{", "s", ".", "connsMu", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "connsMu", ".", "RUnlock", "(", ")", "\n", "c", ",...
// Connection returns the connection for the given ID.
[ "Connection", "returns", "the", "connection", "for", "the", "given", "ID", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L501-L506
train
rqlite/rqlite
store/store.go
LeaderID
func (s *Store) LeaderID() (string, error) { addr := s.LeaderAddr() configFuture := s.raft.GetConfiguration() if err := configFuture.Error(); err != nil { s.logger.Printf("failed to get raft configuration: %v", err) return "", err } for _, srv := range configFuture.Configuration().Servers { if srv.Address =...
go
func (s *Store) LeaderID() (string, error) { addr := s.LeaderAddr() configFuture := s.raft.GetConfiguration() if err := configFuture.Error(); err != nil { s.logger.Printf("failed to get raft configuration: %v", err) return "", err } for _, srv := range configFuture.Configuration().Servers { if srv.Address =...
[ "func", "(", "s", "*", "Store", ")", "LeaderID", "(", ")", "(", "string", ",", "error", ")", "{", "addr", ":=", "s", ".", "LeaderAddr", "(", ")", "\n", "configFuture", ":=", "s", ".", "raft", ".", "GetConfiguration", "(", ")", "\n", "if", "err", ...
// LeaderID returns the node ID of the Raft leader. Returns a // blank string if there is no leader, or an error.
[ "LeaderID", "returns", "the", "node", "ID", "of", "the", "Raft", "leader", ".", "Returns", "a", "blank", "string", "if", "there", "is", "no", "leader", "or", "an", "error", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L516-L530
train
rqlite/rqlite
store/store.go
Nodes
func (s *Store) Nodes() ([]*Server, error) { f := s.raft.GetConfiguration() if f.Error() != nil { return nil, f.Error() } rs := f.Configuration().Servers servers := make([]*Server, len(rs)) for i := range rs { servers[i] = &Server{ ID: string(rs[i].ID), Addr: string(rs[i].Address), } } sort.Sort...
go
func (s *Store) Nodes() ([]*Server, error) { f := s.raft.GetConfiguration() if f.Error() != nil { return nil, f.Error() } rs := f.Configuration().Servers servers := make([]*Server, len(rs)) for i := range rs { servers[i] = &Server{ ID: string(rs[i].ID), Addr: string(rs[i].Address), } } sort.Sort...
[ "func", "(", "s", "*", "Store", ")", "Nodes", "(", ")", "(", "[", "]", "*", "Server", ",", "error", ")", "{", "f", ":=", "s", ".", "raft", ".", "GetConfiguration", "(", ")", "\n", "if", "f", ".", "Error", "(", ")", "!=", "nil", "{", "return",...
// Nodes returns the slice of nodes in the cluster, sorted by ID ascending.
[ "Nodes", "returns", "the", "slice", "of", "nodes", "in", "the", "cluster", "sorted", "by", "ID", "ascending", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L533-L550
train
rqlite/rqlite
store/store.go
WaitForLeader
func (s *Store) WaitForLeader(timeout time.Duration) (string, error) { tck := time.NewTicker(leaderWaitDelay) defer tck.Stop() tmr := time.NewTimer(timeout) defer tmr.Stop() for { select { case <-tck.C: l := s.LeaderAddr() if l != "" { return l, nil } case <-tmr.C: return "", fmt.Errorf("tim...
go
func (s *Store) WaitForLeader(timeout time.Duration) (string, error) { tck := time.NewTicker(leaderWaitDelay) defer tck.Stop() tmr := time.NewTimer(timeout) defer tmr.Stop() for { select { case <-tck.C: l := s.LeaderAddr() if l != "" { return l, nil } case <-tmr.C: return "", fmt.Errorf("tim...
[ "func", "(", "s", "*", "Store", ")", "WaitForLeader", "(", "timeout", "time", ".", "Duration", ")", "(", "string", ",", "error", ")", "{", "tck", ":=", "time", ".", "NewTicker", "(", "leaderWaitDelay", ")", "\n", "defer", "tck", ".", "Stop", "(", ")"...
// WaitForLeader blocks until a leader is detected, or the timeout expires.
[ "WaitForLeader", "blocks", "until", "a", "leader", "is", "detected", "or", "the", "timeout", "expires", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L553-L570
train
rqlite/rqlite
store/store.go
WaitForAppliedIndex
func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error { tck := time.NewTicker(appliedWaitDelay) defer tck.Stop() tmr := time.NewTimer(timeout) defer tmr.Stop() for { select { case <-tck.C: if s.raft.AppliedIndex() >= idx { return nil } case <-tmr.C: return fmt.Errorf("tim...
go
func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error { tck := time.NewTicker(appliedWaitDelay) defer tck.Stop() tmr := time.NewTimer(timeout) defer tmr.Stop() for { select { case <-tck.C: if s.raft.AppliedIndex() >= idx { return nil } case <-tmr.C: return fmt.Errorf("tim...
[ "func", "(", "s", "*", "Store", ")", "WaitForAppliedIndex", "(", "idx", "uint64", ",", "timeout", "time", ".", "Duration", ")", "error", "{", "tck", ":=", "time", ".", "NewTicker", "(", "appliedWaitDelay", ")", "\n", "defer", "tck", ".", "Stop", "(", "...
// WaitForAppliedIndex blocks until a given log index has been applied, // or the timeout expires.
[ "WaitForAppliedIndex", "blocks", "until", "a", "given", "log", "index", "has", "been", "applied", "or", "the", "timeout", "expires", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L574-L590
train
rqlite/rqlite
store/store.go
Stats
func (s *Store) Stats() (map[string]interface{}, error) { fkEnabled, err := s.dbConn.FKConstraints() if err != nil { return nil, err } dbStatus := map[string]interface{}{ "dsn": s.dbConf.DSN, "fk_constraints": enabledFromBool(fkEnabled), "version": sdb.DBVersion, } if !s.dbConf.Memory {...
go
func (s *Store) Stats() (map[string]interface{}, error) { fkEnabled, err := s.dbConn.FKConstraints() if err != nil { return nil, err } dbStatus := map[string]interface{}{ "dsn": s.dbConf.DSN, "fk_constraints": enabledFromBool(fkEnabled), "version": sdb.DBVersion, } if !s.dbConf.Memory {...
[ "func", "(", "s", "*", "Store", ")", "Stats", "(", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "fkEnabled", ",", "err", ":=", "s", ".", "dbConn", ".", "FKConstraints", "(", ")", "\n", "if", "err", "!=", "...
// Stats returns stats for the store.
[ "Stats", "returns", "stats", "for", "the", "store", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L593-L669
train
rqlite/rqlite
store/store.go
Backup
func (s *Store) Backup(leader bool, fmt BackupFormat, dst io.Writer) error { s.restoreMu.RLock() defer s.restoreMu.RUnlock() if leader && s.raft.State() != raft.Leader { return ErrNotLeader } var err error if fmt == BackupBinary { err = s.database(leader, dst) if err != nil { return err } } else if ...
go
func (s *Store) Backup(leader bool, fmt BackupFormat, dst io.Writer) error { s.restoreMu.RLock() defer s.restoreMu.RUnlock() if leader && s.raft.State() != raft.Leader { return ErrNotLeader } var err error if fmt == BackupBinary { err = s.database(leader, dst) if err != nil { return err } } else if ...
[ "func", "(", "s", "*", "Store", ")", "Backup", "(", "leader", "bool", ",", "fmt", "BackupFormat", ",", "dst", "io", ".", "Writer", ")", "error", "{", "s", ".", "restoreMu", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "restoreMu", ".", "RUnlock...
// Backup writes a snapshot of the underlying database to dst // // If leader is true, this operation is performed with a read consistency // level equivalent to "weak". Otherwise no guarantees are made about the // read consistency level.
[ "Backup", "writes", "a", "snapshot", "of", "the", "underlying", "database", "to", "dst", "If", "leader", "is", "true", "this", "operation", "is", "performed", "with", "a", "read", "consistency", "level", "equivalent", "to", "weak", ".", "Otherwise", "no", "g...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L676-L699
train
rqlite/rqlite
store/store.go
Join
func (s *Store) Join(id, addr string, metadata map[string]string) error { s.logger.Printf("received request to join node at %s", addr) if s.raft.State() != raft.Leader { return ErrNotLeader } configFuture := s.raft.GetConfiguration() if err := configFuture.Error(); err != nil { s.logger.Printf("failed to get ...
go
func (s *Store) Join(id, addr string, metadata map[string]string) error { s.logger.Printf("received request to join node at %s", addr) if s.raft.State() != raft.Leader { return ErrNotLeader } configFuture := s.raft.GetConfiguration() if err := configFuture.Error(); err != nil { s.logger.Printf("failed to get ...
[ "func", "(", "s", "*", "Store", ")", "Join", "(", "id", ",", "addr", "string", ",", "metadata", "map", "[", "string", "]", "string", ")", "error", "{", "s", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "s", ".", ...
// Join joins a node, identified by id and located at addr, to this store. // The node must be ready to respond to Raft communications at that address.
[ "Join", "joins", "a", "node", "identified", "by", "id", "and", "located", "at", "addr", "to", "this", "store", ".", "The", "node", "must", "be", "ready", "to", "respond", "to", "Raft", "communications", "at", "that", "address", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L703-L747
train
rqlite/rqlite
store/store.go
Remove
func (s *Store) Remove(id string) error { s.logger.Printf("received request to remove node %s", id) if err := s.remove(id); err != nil { s.logger.Printf("failed to remove node %s: %s", id, err.Error()) return err } s.logger.Printf("node %s removed successfully", id) return nil }
go
func (s *Store) Remove(id string) error { s.logger.Printf("received request to remove node %s", id) if err := s.remove(id); err != nil { s.logger.Printf("failed to remove node %s: %s", id, err.Error()) return err } s.logger.Printf("node %s removed successfully", id) return nil }
[ "func", "(", "s", "*", "Store", ")", "Remove", "(", "id", "string", ")", "error", "{", "s", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "id", ")", "\n", "if", "err", ":=", "s", ".", "remove", "(", "id", ")", ";", "err", "!=", "nil", ...
// Remove removes a node from the store, specified by ID.
[ "Remove", "removes", "a", "node", "from", "the", "store", "specified", "by", "ID", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L750-L759
train
rqlite/rqlite
store/store.go
Metadata
func (s *Store) Metadata(id, key string) string { s.metaMu.RLock() defer s.metaMu.RUnlock() if _, ok := s.meta[id]; !ok { return "" } v, ok := s.meta[id][key] if ok { return v } return "" }
go
func (s *Store) Metadata(id, key string) string { s.metaMu.RLock() defer s.metaMu.RUnlock() if _, ok := s.meta[id]; !ok { return "" } v, ok := s.meta[id][key] if ok { return v } return "" }
[ "func", "(", "s", "*", "Store", ")", "Metadata", "(", "id", ",", "key", "string", ")", "string", "{", "s", ".", "metaMu", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "metaMu", ".", "RUnlock", "(", ")", "\n\n", "if", "_", ",", "ok", ":=", ...
// Metadata returns the value for a given key, for a given node ID.
[ "Metadata", "returns", "the", "value", "for", "a", "given", "key", "for", "a", "given", "node", "ID", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L762-L774
train
rqlite/rqlite
store/store.go
SetMetadata
func (s *Store) SetMetadata(md map[string]string) error { return s.setMetadata(s.raftID, md) }
go
func (s *Store) SetMetadata(md map[string]string) error { return s.setMetadata(s.raftID, md) }
[ "func", "(", "s", "*", "Store", ")", "SetMetadata", "(", "md", "map", "[", "string", "]", "string", ")", "error", "{", "return", "s", ".", "setMetadata", "(", "s", ".", "raftID", ",", "md", ")", "\n", "}" ]
// SetMetadata adds the metadata md to any existing metadata for // this node.
[ "SetMetadata", "adds", "the", "metadata", "md", "to", "any", "existing", "metadata", "for", "this", "node", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L778-L780
train
rqlite/rqlite
store/store.go
setMetadata
func (s *Store) setMetadata(id string, md map[string]string) error { // Check local data first. if func() bool { s.metaMu.RLock() defer s.metaMu.RUnlock() if _, ok := s.meta[id]; ok { for k, v := range md { if s.meta[id][k] != v { return false } } return true } return false }() { //...
go
func (s *Store) setMetadata(id string, md map[string]string) error { // Check local data first. if func() bool { s.metaMu.RLock() defer s.metaMu.RUnlock() if _, ok := s.meta[id]; ok { for k, v := range md { if s.meta[id][k] != v { return false } } return true } return false }() { //...
[ "func", "(", "s", "*", "Store", ")", "setMetadata", "(", "id", "string", ",", "md", "map", "[", "string", "]", "string", ")", "error", "{", "// Check local data first.", "if", "func", "(", ")", "bool", "{", "s", ".", "metaMu", ".", "RLock", "(", ")",...
// setMetadata adds the metadata md to any existing metadata for // the given node ID.
[ "setMetadata", "adds", "the", "metadata", "md", "to", "any", "existing", "metadata", "for", "the", "given", "node", "ID", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L784-L821
train
rqlite/rqlite
store/store.go
disconnect
func (s *Store) disconnect(c *Connection) error { d := &connectionSub{ ConnID: c.ID, } cmd, err := newCommand(disconnect, d) if err != nil { return err } b, err := json.Marshal(cmd) if err != nil { return err } f := s.raft.Apply(b, s.ApplyTimeout) if e := f.(raft.Future); e.Error() != nil { if e.Erro...
go
func (s *Store) disconnect(c *Connection) error { d := &connectionSub{ ConnID: c.ID, } cmd, err := newCommand(disconnect, d) if err != nil { return err } b, err := json.Marshal(cmd) if err != nil { return err } f := s.raft.Apply(b, s.ApplyTimeout) if e := f.(raft.Future); e.Error() != nil { if e.Erro...
[ "func", "(", "s", "*", "Store", ")", "disconnect", "(", "c", "*", "Connection", ")", "error", "{", "d", ":=", "&", "connectionSub", "{", "ConnID", ":", "c", ".", "ID", ",", "}", "\n", "cmd", ",", "err", ":=", "newCommand", "(", "disconnect", ",", ...
// disconnect removes a connection to the database, a connection // which was previously established via Raft consensus.
[ "disconnect", "removes", "a", "connection", "to", "the", "database", "a", "connection", "which", "was", "previously", "established", "via", "Raft", "consensus", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L825-L847
train
rqlite/rqlite
store/store.go
execute
func (s *Store) execute(c *Connection, ex *ExecuteRequest) (*ExecuteResponse, error) { if c == nil { s.connsMu.RLock() c = s.conns[defaultConnID] s.connsMu.RUnlock() } c.SetLastUsedNow() start := time.Now() d := &databaseSub{ ConnID: c.ID, Atomic: ex.Atomic, Queries: ex.Queries, Timings: ex.Timin...
go
func (s *Store) execute(c *Connection, ex *ExecuteRequest) (*ExecuteResponse, error) { if c == nil { s.connsMu.RLock() c = s.conns[defaultConnID] s.connsMu.RUnlock() } c.SetLastUsedNow() start := time.Now() d := &databaseSub{ ConnID: c.ID, Atomic: ex.Atomic, Queries: ex.Queries, Timings: ex.Timin...
[ "func", "(", "s", "*", "Store", ")", "execute", "(", "c", "*", "Connection", ",", "ex", "*", "ExecuteRequest", ")", "(", "*", "ExecuteResponse", ",", "error", ")", "{", "if", "c", "==", "nil", "{", "s", ".", "connsMu", ".", "RLock", "(", ")", "\n...
// Execute executes queries that return no rows, but do modify the database. If connection // is nil then the utility connection is used.
[ "Execute", "executes", "queries", "that", "return", "no", "rows", "but", "do", "modify", "the", "database", ".", "If", "connection", "is", "nil", "then", "the", "utility", "connection", "is", "used", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L851-L896
train
rqlite/rqlite
store/store.go
query
func (s *Store) query(c *Connection, qr *QueryRequest) (*QueryResponse, error) { if c == nil { s.connsMu.RLock() c = s.conns[defaultConnID] s.connsMu.RUnlock() } c.SetLastUsedNow() s.restoreMu.RLock() defer s.restoreMu.RUnlock() start := time.Now() if qr.Lvl == Strong { d := &databaseSub{ ConnID: c...
go
func (s *Store) query(c *Connection, qr *QueryRequest) (*QueryResponse, error) { if c == nil { s.connsMu.RLock() c = s.conns[defaultConnID] s.connsMu.RUnlock() } c.SetLastUsedNow() s.restoreMu.RLock() defer s.restoreMu.RUnlock() start := time.Now() if qr.Lvl == Strong { d := &databaseSub{ ConnID: c...
[ "func", "(", "s", "*", "Store", ")", "query", "(", "c", "*", "Connection", ",", "qr", "*", "QueryRequest", ")", "(", "*", "QueryResponse", ",", "error", ")", "{", "if", "c", "==", "nil", "{", "s", ".", "connsMu", ".", "RLock", "(", ")", "\n", "...
// Query executes queries that return rows, and do not modify the database. If // connection is nil, then the utility connection is used.
[ "Query", "executes", "queries", "that", "return", "rows", "and", "do", "not", "modify", "the", "database", ".", "If", "connection", "is", "nil", "then", "the", "utility", "connection", "is", "used", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L927-L986
train
rqlite/rqlite
store/store.go
createDatabase
func (s *Store) createDatabase() error { var db *sdb.DB var err error if !s.dbConf.Memory { // as it will be rebuilt from (possibly) a snapshot and committed log entries. if err := os.Remove(s.dbPath); err != nil && !os.IsNotExist(err) { return err } db, err = sdb.New(s.dbPath, s.dbConf.DSN, false) if e...
go
func (s *Store) createDatabase() error { var db *sdb.DB var err error if !s.dbConf.Memory { // as it will be rebuilt from (possibly) a snapshot and committed log entries. if err := os.Remove(s.dbPath); err != nil && !os.IsNotExist(err) { return err } db, err = sdb.New(s.dbPath, s.dbConf.DSN, false) if e...
[ "func", "(", "s", "*", "Store", ")", "createDatabase", "(", ")", "error", "{", "var", "db", "*", "sdb", ".", "DB", "\n", "var", "err", "error", "\n", "if", "!", "s", ".", "dbConf", ".", "Memory", "{", "// as it will be rebuilt from (possibly) a snapshot an...
// createDatabase creates the the in-memory or file-based database.
[ "createDatabase", "creates", "the", "the", "in", "-", "memory", "or", "file", "-", "based", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L989-L1011
train
rqlite/rqlite
store/store.go
remove
func (s *Store) remove(id string) error { if s.raft.State() != raft.Leader { return ErrNotLeader } f := s.raft.RemoveServer(raft.ServerID(id), 0, 0) if f.Error() != nil { if f.Error() == raft.ErrNotLeader { return ErrNotLeader } return f.Error() } c, err := newCommand(metadataDelete, id) if err != n...
go
func (s *Store) remove(id string) error { if s.raft.State() != raft.Leader { return ErrNotLeader } f := s.raft.RemoveServer(raft.ServerID(id), 0, 0) if f.Error() != nil { if f.Error() == raft.ErrNotLeader { return ErrNotLeader } return f.Error() } c, err := newCommand(metadataDelete, id) if err != n...
[ "func", "(", "s", "*", "Store", ")", "remove", "(", "id", "string", ")", "error", "{", "if", "s", ".", "raft", ".", "State", "(", ")", "!=", "raft", ".", "Leader", "{", "return", "ErrNotLeader", "\n", "}", "\n\n", "f", ":=", "s", ".", "raft", "...
// remove removes the node, with the given ID, from the cluster.
[ "remove", "removes", "the", "node", "with", "the", "given", "ID", "from", "the", "cluster", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1014-L1044
train
rqlite/rqlite
store/store.go
raftConfig
func (s *Store) raftConfig() *raft.Config { config := raft.DefaultConfig() if s.SnapshotThreshold != 0 { config.SnapshotThreshold = s.SnapshotThreshold } if s.SnapshotInterval != 0 { config.SnapshotInterval = s.SnapshotInterval } if s.HeartbeatTimeout != 0 { config.HeartbeatTimeout = s.HeartbeatTimeout } ...
go
func (s *Store) raftConfig() *raft.Config { config := raft.DefaultConfig() if s.SnapshotThreshold != 0 { config.SnapshotThreshold = s.SnapshotThreshold } if s.SnapshotInterval != 0 { config.SnapshotInterval = s.SnapshotInterval } if s.HeartbeatTimeout != 0 { config.HeartbeatTimeout = s.HeartbeatTimeout } ...
[ "func", "(", "s", "*", "Store", ")", "raftConfig", "(", ")", "*", "raft", ".", "Config", "{", "config", ":=", "raft", ".", "DefaultConfig", "(", ")", "\n", "if", "s", ".", "SnapshotThreshold", "!=", "0", "{", "config", ".", "SnapshotThreshold", "=", ...
// raftConfig returns a new Raft config for the store.
[ "raftConfig", "returns", "a", "new", "Raft", "config", "for", "the", "store", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1047-L1059
train
rqlite/rqlite
store/store.go
checkConnections
func (s *Store) checkConnections() { s.wg.Add(1) ticker := time.NewTicker(s.connPollPeriod) go func() { defer s.wg.Done() defer ticker.Stop() for { select { case <-s.done: return case <-ticker.C: // This is not a 100% correct check, but is right almost all // the time, and saves the node f...
go
func (s *Store) checkConnections() { s.wg.Add(1) ticker := time.NewTicker(s.connPollPeriod) go func() { defer s.wg.Done() defer ticker.Stop() for { select { case <-s.done: return case <-ticker.C: // This is not a 100% correct check, but is right almost all // the time, and saves the node f...
[ "func", "(", "s", "*", "Store", ")", "checkConnections", "(", ")", "{", "s", ".", "wg", ".", "Add", "(", "1", ")", "\n", "ticker", ":=", "time", ".", "NewTicker", "(", "s", ".", "connPollPeriod", ")", "\n", "go", "func", "(", ")", "{", "defer", ...
// checkConnections periodically checks which connections should // close due to timeouts.
[ "checkConnections", "periodically", "checks", "which", "connections", "should", "close", "due", "to", "timeouts", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1063-L1110
train
rqlite/rqlite
store/store.go
database
func (s *Store) database(leader bool, dst io.Writer) error { if leader && s.raft.State() != raft.Leader { return ErrNotLeader } f, err := ioutil.TempFile("", "rqlilte-snap-") if err != nil { return err } if err := f.Close(); err != nil { return err } os.Remove(f.Name()) db, err := sdb.New(f.Name(), "", ...
go
func (s *Store) database(leader bool, dst io.Writer) error { if leader && s.raft.State() != raft.Leader { return ErrNotLeader } f, err := ioutil.TempFile("", "rqlilte-snap-") if err != nil { return err } if err := f.Close(); err != nil { return err } os.Remove(f.Name()) db, err := sdb.New(f.Name(), "", ...
[ "func", "(", "s", "*", "Store", ")", "database", "(", "leader", "bool", ",", "dst", "io", ".", "Writer", ")", "error", "{", "if", "leader", "&&", "s", ".", "raft", ".", "State", "(", ")", "!=", "raft", ".", "Leader", "{", "return", "ErrNotLeader", ...
// Database copies contents of the underlying SQLite file to dst
[ "Database", "copies", "contents", "of", "the", "underlying", "SQLite", "file", "to", "dst" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1222-L1259
train
rqlite/rqlite
store/store.go
Snapshot
func (s *Store) Snapshot() (raft.FSMSnapshot, error) { s.restoreMu.RLock() defer s.restoreMu.RUnlock() // Snapshots are not permitted while any connection has a transaction // in progress, because it's not possible (not without a lot of extra // code anyway) to capture the state of a connection during a transacti...
go
func (s *Store) Snapshot() (raft.FSMSnapshot, error) { s.restoreMu.RLock() defer s.restoreMu.RUnlock() // Snapshots are not permitted while any connection has a transaction // in progress, because it's not possible (not without a lot of extra // code anyway) to capture the state of a connection during a transacti...
[ "func", "(", "s", "*", "Store", ")", "Snapshot", "(", ")", "(", "raft", ".", "FSMSnapshot", ",", "error", ")", "{", "s", ".", "restoreMu", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "restoreMu", ".", "RUnlock", "(", ")", "\n\n", "// Snapshots...
// Snapshot returns a snapshot of the store. The caller must ensure that // no Raft transaction is taking place during this call. Hashicorp Raft // guarantees that this function will not be called concurrently with Apply.
[ "Snapshot", "returns", "a", "snapshot", "of", "the", "store", ".", "The", "caller", "must", "ensure", "that", "no", "Raft", "transaction", "is", "taking", "place", "during", "this", "call", ".", "Hashicorp", "Raft", "guarantees", "that", "this", "function", ...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1264-L1315
train
rqlite/rqlite
store/store.go
RegisterObserver
func (s *Store) RegisterObserver(o *raft.Observer) { s.raft.RegisterObserver(o) }
go
func (s *Store) RegisterObserver(o *raft.Observer) { s.raft.RegisterObserver(o) }
[ "func", "(", "s", "*", "Store", ")", "RegisterObserver", "(", "o", "*", "raft", ".", "Observer", ")", "{", "s", ".", "raft", ".", "RegisterObserver", "(", "o", ")", "\n", "}" ]
// RegisterObserver registers an observer of Raft events
[ "RegisterObserver", "registers", "an", "observer", "of", "Raft", "events" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1410-L1412
train
rqlite/rqlite
store/store.go
DeregisterObserver
func (s *Store) DeregisterObserver(o *raft.Observer) { s.raft.DeregisterObserver(o) }
go
func (s *Store) DeregisterObserver(o *raft.Observer) { s.raft.DeregisterObserver(o) }
[ "func", "(", "s", "*", "Store", ")", "DeregisterObserver", "(", "o", "*", "raft", ".", "Observer", ")", "{", "s", ".", "raft", ".", "DeregisterObserver", "(", "o", ")", "\n", "}" ]
// DeregisterObserver deregisters an observer of Raft events
[ "DeregisterObserver", "deregisters", "an", "observer", "of", "Raft", "events" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1415-L1417
train
rqlite/rqlite
store/store.go
pathExists
func pathExists(p string) bool { if _, err := os.Lstat(p); err != nil && os.IsNotExist(err) { return false } return true }
go
func pathExists(p string) bool { if _, err := os.Lstat(p); err != nil && os.IsNotExist(err) { return false } return true }
[ "func", "pathExists", "(", "p", "string", ")", "bool", "{", "if", "_", ",", "err", ":=", "os", ".", "Lstat", "(", "p", ")", ";", "err", "!=", "nil", "&&", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "false", "\n", "}", "\n", "retur...
// pathExists returns true if the given path exists.
[ "pathExists", "returns", "true", "if", "the", "given", "path", "exists", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1473-L1478
train
rqlite/rqlite
store/store.go
tempfile
func tempfile() (*os.File, error) { f, err := ioutil.TempFile("", "rqlilte-snap-") if err != nil { return nil, err } return f, nil }
go
func tempfile() (*os.File, error) { f, err := ioutil.TempFile("", "rqlilte-snap-") if err != nil { return nil, err } return f, nil }
[ "func", "tempfile", "(", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "f", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n"...
// tempfile returns a temporary file for use
[ "tempfile", "returns", "a", "temporary", "file", "for", "use" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/store/store.go#L1481-L1487
train
rqlite/rqlite
http/service.go
New
func New(addr string, store Store, credentials CredentialStore) *Service { return &Service{ addr: addr, store: store, start: time.Now(), statuses: make(map[string]Statuser), credentialStore: credentials, logger: log.New(os.Stderr, "[http] ", log.LstdFlags), }...
go
func New(addr string, store Store, credentials CredentialStore) *Service { return &Service{ addr: addr, store: store, start: time.Now(), statuses: make(map[string]Statuser), credentialStore: credentials, logger: log.New(os.Stderr, "[http] ", log.LstdFlags), }...
[ "func", "New", "(", "addr", "string", ",", "store", "Store", ",", "credentials", "CredentialStore", ")", "*", "Service", "{", "return", "&", "Service", "{", "addr", ":", "addr", ",", "store", ":", "store", ",", "start", ":", "time", ".", "Now", "(", ...
// New returns an uninitialized HTTP service. If credentials is nil, then // the service performs no authentication and authorization checks.
[ "New", "returns", "an", "uninitialized", "HTTP", "service", ".", "If", "credentials", "is", "nil", "then", "the", "service", "performs", "no", "authentication", "and", "authorization", "checks", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L190-L199
train
rqlite/rqlite
http/service.go
ServeHTTP
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.rootHandler.Handler(s).ServeHTTP(w, r) }
go
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.rootHandler.Handler(s).ServeHTTP(w, r) }
[ "func", "(", "s", "*", "Service", ")", "ServeHTTP", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "s", ".", "rootHandler", ".", "Handler", "(", "s", ")", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n",...
// ServeHTTP allows Service to serve HTTP requests.
[ "ServeHTTP", "allows", "Service", "to", "serve", "HTTP", "requests", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L245-L247
train
rqlite/rqlite
http/service.go
RegisterStatus
func (s *Service) RegisterStatus(key string, stat Statuser) error { s.statusMu.Lock() defer s.statusMu.Unlock() if _, ok := s.statuses[key]; ok { return fmt.Errorf("status already registered with key %s", key) } s.statuses[key] = stat return nil }
go
func (s *Service) RegisterStatus(key string, stat Statuser) error { s.statusMu.Lock() defer s.statusMu.Unlock() if _, ok := s.statuses[key]; ok { return fmt.Errorf("status already registered with key %s", key) } s.statuses[key] = stat return nil }
[ "func", "(", "s", "*", "Service", ")", "RegisterStatus", "(", "key", "string", ",", "stat", "Statuser", ")", "error", "{", "s", ".", "statusMu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "statusMu", ".", "Unlock", "(", ")", "\n\n", "if", "_",...
// RegisterStatus allows other modules to register status for serving over HTTP.
[ "RegisterStatus", "allows", "other", "modules", "to", "register", "status", "for", "serving", "over", "HTTP", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L250-L260
train
rqlite/rqlite
http/service.go
createConnection
func (s *Service) createConnection(w http.ResponseWriter, r *http.Request) { opts := store.ConnectionOptions{ IdleTimeout: s.ConnIdleTimeout, TxTimeout: s.ConnTxTimeout, } d, b, err := txTimeout(r) if err != nil { w.WriteHeader(http.StatusBadRequest) return } if b { opts.TxTimeout = d } d, b, err ...
go
func (s *Service) createConnection(w http.ResponseWriter, r *http.Request) { opts := store.ConnectionOptions{ IdleTimeout: s.ConnIdleTimeout, TxTimeout: s.ConnTxTimeout, } d, b, err := txTimeout(r) if err != nil { w.WriteHeader(http.StatusBadRequest) return } if b { opts.TxTimeout = d } d, b, err ...
[ "func", "(", "s", "*", "Service", ")", "createConnection", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "opts", ":=", "store", ".", "ConnectionOptions", "{", "IdleTimeout", ":", "s", ".", "ConnIdleTimeout", ",...
// createConnection creates a connection and returns its ID.
[ "createConnection", "creates", "a", "connection", "and", "returns", "its", "ID", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L263-L294
train
rqlite/rqlite
http/service.go
deleteConnection
func (s *Service) deleteConnection(id uint64) error { conn, ok := s.store.Connection(id) if !ok { return nil } return conn.Close() }
go
func (s *Service) deleteConnection(id uint64) error { conn, ok := s.store.Connection(id) if !ok { return nil } return conn.Close() }
[ "func", "(", "s", "*", "Service", ")", "deleteConnection", "(", "id", "uint64", ")", "error", "{", "conn", ",", "ok", ":=", "s", ".", "store", ".", "Connection", "(", "id", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "retur...
// deleteConnection closes a connection and makes it unavailable for // future use.
[ "deleteConnection", "closes", "a", "connection", "and", "makes", "it", "unavailable", "for", "future", "use", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L298-L304
train
rqlite/rqlite
http/service.go
handleJoin
func (s *Service) handleJoin(w http.ResponseWriter, r *http.Request) { b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { w.WriteHeader(http.StatusBadRequest) return } md := map[string]interface{}{} if err := json.Unmarshal(b, &md); err != nil { w.WriteHeader(http.StatusBadRequest) retu...
go
func (s *Service) handleJoin(w http.ResponseWriter, r *http.Request) { b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { w.WriteHeader(http.StatusBadRequest) return } md := map[string]interface{}{} if err := json.Unmarshal(b, &md); err != nil { w.WriteHeader(http.StatusBadRequest) retu...
[ "func", "(", "s", "*", "Service", ")", "handleJoin", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "defer", "r", ".", ...
// handleJoin handles cluster-join requests from other nodes.
[ "handleJoin", "handles", "cluster", "-", "join", "requests", "from", "other", "nodes", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L307-L356
train
rqlite/rqlite
http/service.go
handleRemove
func (s *Service) handleRemove(w http.ResponseWriter, r *http.Request) { b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { w.WriteHeader(http.StatusBadRequest) return } m := map[string]string{} if err := json.Unmarshal(b, &m); err != nil { w.WriteHeader(http.StatusBadRequest) return }...
go
func (s *Service) handleRemove(w http.ResponseWriter, r *http.Request) { b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { w.WriteHeader(http.StatusBadRequest) return } m := map[string]string{} if err := json.Unmarshal(b, &m); err != nil { w.WriteHeader(http.StatusBadRequest) return }...
[ "func", "(", "s", "*", "Service", ")", "handleRemove", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "defer", "r", ".",...
// handleRemove handles cluster-remove requests.
[ "handleRemove", "handles", "cluster", "-", "remove", "requests", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L359-L399
train
rqlite/rqlite
http/service.go
handleBackup
func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request) { noLeader, err := noLeader(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } bf, err := backupFormat(w, r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } err...
go
func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request) { noLeader, err := noLeader(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } bf, err := backupFormat(w, r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } err...
[ "func", "(", "s", "*", "Service", ")", "handleBackup", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "noLeader", ",", "err", ":=", "noLeader", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "http", ...
// handleBackup returns the consistent database snapshot.
[ "handleBackup", "returns", "the", "consistent", "database", "snapshot", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L402-L422
train
rqlite/rqlite
http/service.go
handleLoad
func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request) { timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) ret...
go
func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request) { timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } b, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) ret...
[ "func", "(", "s", "*", "Service", ")", "handleLoad", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "timings", ",", "err", ":=", "timings", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "http", "."...
// handleLoad loads the state contained in a .dump output.
[ "handleLoad", "loads", "the", "state", "contained", "in", "a", ".", "dump", "output", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L425-L463
train
rqlite/rqlite
http/service.go
handleStatus
func (s *Service) handleStatus(w http.ResponseWriter, r *http.Request) { results, err := s.store.Stats() if err != nil { w.WriteHeader(http.StatusInternalServerError) return } rt := map[string]interface{}{ "GOARCH": runtime.GOARCH, "GOOS": runtime.GOOS, "GOMAXPROCS": runtime.GOMAXPROCS...
go
func (s *Service) handleStatus(w http.ResponseWriter, r *http.Request) { results, err := s.store.Stats() if err != nil { w.WriteHeader(http.StatusInternalServerError) return } rt := map[string]interface{}{ "GOARCH": runtime.GOARCH, "GOOS": runtime.GOOS, "GOMAXPROCS": runtime.GOMAXPROCS...
[ "func", "(", "s", "*", "Service", ")", "handleStatus", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "results", ",", "err", ":=", "s", ".", "store", ".", "Stats", "(", ")", "\n", "if", "err", "!=", "nil...
// handleStatus returns status on the system.
[ "handleStatus", "returns", "status", "on", "the", "system", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L466-L538
train
rqlite/rqlite
http/service.go
handleExecute
func (s *Service) handleExecute(connID uint64, w http.ResponseWriter, r *http.Request) { isAtomic, err := isAtomic(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) re...
go
func (s *Service) handleExecute(connID uint64, w http.ResponseWriter, r *http.Request) { isAtomic, err := isAtomic(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) re...
[ "func", "(", "s", "*", "Service", ")", "handleExecute", "(", "connID", "uint64", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "isAtomic", ",", "err", ":=", "isAtomic", "(", "r", ")", "\n", "if", "err", "...
// handleExecute handles queries that modify the database.
[ "handleExecute", "handles", "queries", "that", "modify", "the", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L541-L603
train
rqlite/rqlite
http/service.go
handleQuery
func (s *Service) handleQuery(connID uint64, w http.ResponseWriter, r *http.Request) { isAtomic, err := isAtomic(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) retu...
go
func (s *Service) handleQuery(connID uint64, w http.ResponseWriter, r *http.Request) { isAtomic, err := isAtomic(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } timings, err := timings(r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) retu...
[ "func", "(", "s", "*", "Service", ")", "handleQuery", "(", "connID", "uint64", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "isAtomic", ",", "err", ":=", "isAtomic", "(", "r", ")", "\n", "if", "err", "!=...
// handleQuery handles queries that do not modify the database.
[ "handleQuery", "handles", "queries", "that", "do", "not", "modify", "the", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L606-L668
train
rqlite/rqlite
http/service.go
FormRedirect
func (s *Service) FormRedirect(r *http.Request, host string) string { rq := r.URL.RawQuery if rq != "" { rq = fmt.Sprintf("?%s", rq) } return fmt.Sprintf("%s://%s%s%s", s.protocol(), host, r.URL.Path, rq) }
go
func (s *Service) FormRedirect(r *http.Request, host string) string { rq := r.URL.RawQuery if rq != "" { rq = fmt.Sprintf("?%s", rq) } return fmt.Sprintf("%s://%s%s%s", s.protocol(), host, r.URL.Path, rq) }
[ "func", "(", "s", "*", "Service", ")", "FormRedirect", "(", "r", "*", "http", ".", "Request", ",", "host", "string", ")", "string", "{", "rq", ":=", "r", ".", "URL", ".", "RawQuery", "\n", "if", "rq", "!=", "\"", "\"", "{", "rq", "=", "fmt", "....
// FormRedirect returns the value for the "Location" header for a 301 response.
[ "FormRedirect", "returns", "the", "value", "for", "the", "Location", "header", "for", "a", "301", "response", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L676-L682
train
rqlite/rqlite
http/service.go
FormConnectionURL
func (s *Service) FormConnectionURL(r *http.Request, id uint64) string { return fmt.Sprintf("%s://%s/db/connections/%d", s.protocol(), r.Host, id) }
go
func (s *Service) FormConnectionURL(r *http.Request, id uint64) string { return fmt.Sprintf("%s://%s/db/connections/%d", s.protocol(), r.Host, id) }
[ "func", "(", "s", "*", "Service", ")", "FormConnectionURL", "(", "r", "*", "http", ".", "Request", ",", "id", "uint64", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "protocol", "(", ")", ",", "r", ".", "Hos...
// FormConnectionURL returns the URL of the new connection.
[ "FormConnectionURL", "returns", "the", "URL", "of", "the", "new", "connection", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L685-L687
train
rqlite/rqlite
http/service.go
CheckRequestPerm
func (s *Service) CheckRequestPerm(r *http.Request, perm string) bool { if s.credentialStore == nil { return true } username, _, ok := r.BasicAuth() if !ok { return false } return s.credentialStore.HasAnyPerm(username, perm, PermAll) }
go
func (s *Service) CheckRequestPerm(r *http.Request, perm string) bool { if s.credentialStore == nil { return true } username, _, ok := r.BasicAuth() if !ok { return false } return s.credentialStore.HasAnyPerm(username, perm, PermAll) }
[ "func", "(", "s", "*", "Service", ")", "CheckRequestPerm", "(", "r", "*", "http", ".", "Request", ",", "perm", "string", ")", "bool", "{", "if", "s", ".", "credentialStore", "==", "nil", "{", "return", "true", "\n", "}", "\n\n", "username", ",", "_",...
// CheckRequestPerm returns true if authentication is enabled and the user contained // in the BasicAuth request has either PermAll, or the given perm.
[ "CheckRequestPerm", "returns", "true", "if", "authentication", "is", "enabled", "and", "the", "user", "contained", "in", "the", "BasicAuth", "request", "has", "either", "PermAll", "or", "the", "given", "perm", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L691-L701
train
rqlite/rqlite
http/service.go
addBuildVersion
func (s *Service) addBuildVersion(w http.ResponseWriter) { // Add version header to every response, if available. version := "unknown" if v, ok := s.BuildInfo["version"].(string); ok { version = v } w.Header().Add(VersionHTTPHeader, version) }
go
func (s *Service) addBuildVersion(w http.ResponseWriter) { // Add version header to every response, if available. version := "unknown" if v, ok := s.BuildInfo["version"].(string); ok { version = v } w.Header().Add(VersionHTTPHeader, version) }
[ "func", "(", "s", "*", "Service", ")", "addBuildVersion", "(", "w", "http", ".", "ResponseWriter", ")", "{", "// Add version header to every response, if available.", "version", ":=", "\"", "\"", "\n", "if", "v", ",", "ok", ":=", "s", ".", "BuildInfo", "[", ...
// addBuildVersion adds the build version to the HTTP response.
[ "addBuildVersion", "adds", "the", "build", "version", "to", "the", "HTTP", "response", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L712-L719
train
rqlite/rqlite
http/service.go
queryParam
func queryParam(req *http.Request, param string) (bool, error) { err := req.ParseForm() if err != nil { return false, err } if _, ok := req.Form[param]; ok { return true, nil } return false, nil }
go
func queryParam(req *http.Request, param string) (bool, error) { err := req.ParseForm() if err != nil { return false, err } if _, ok := req.Form[param]; ok { return true, nil } return false, nil }
[ "func", "queryParam", "(", "req", "*", "http", ".", "Request", ",", "param", "string", ")", "(", "bool", ",", "error", ")", "{", "err", ":=", "req", ".", "ParseForm", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "...
// queryParam returns whether the given query param is set to true.
[ "queryParam", "returns", "whether", "the", "given", "query", "param", "is", "set", "to", "true", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L788-L797
train
rqlite/rqlite
http/service.go
durationParam
func durationParam(req *http.Request, param string) (time.Duration, bool, error) { q := req.URL.Query() t := strings.TrimSpace(q.Get(param)) if t == "" { return 0, false, nil } dur, err := time.ParseDuration(t) if err != nil { return 0, false, err } return dur, true, nil }
go
func durationParam(req *http.Request, param string) (time.Duration, bool, error) { q := req.URL.Query() t := strings.TrimSpace(q.Get(param)) if t == "" { return 0, false, nil } dur, err := time.ParseDuration(t) if err != nil { return 0, false, err } return dur, true, nil }
[ "func", "durationParam", "(", "req", "*", "http", ".", "Request", ",", "param", "string", ")", "(", "time", ".", "Duration", ",", "bool", ",", "error", ")", "{", "q", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "t", ":=", "strings", "....
// durationParam returns the duration of the given query param, if set.
[ "durationParam", "returns", "the", "duration", "of", "the", "given", "query", "param", "if", "set", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L800-L811
train
rqlite/rqlite
http/service.go
stmtParam
func stmtParam(req *http.Request) (string, error) { q := req.URL.Query() return strings.TrimSpace(q.Get("q")), nil }
go
func stmtParam(req *http.Request) (string, error) { q := req.URL.Query() return strings.TrimSpace(q.Get("q")), nil }
[ "func", "stmtParam", "(", "req", "*", "http", ".", "Request", ")", "(", "string", ",", "error", ")", "{", "q", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "return", "strings", ".", "TrimSpace", "(", "q", ".", "Get", "(", "\"", "\"", ...
// stmtParam returns the value for URL param 'q', if present.
[ "stmtParam", "returns", "the", "value", "for", "URL", "param", "q", "if", "present", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L814-L817
train
rqlite/rqlite
http/service.go
isAtomic
func isAtomic(req *http.Request) (bool, error) { // "transaction" is checked for backwards compatibility with // client libraries. for _, q := range []string{"atomic", "transaction"} { if a, err := queryParam(req, q); err != nil || a { return a, err } } return false, nil }
go
func isAtomic(req *http.Request) (bool, error) { // "transaction" is checked for backwards compatibility with // client libraries. for _, q := range []string{"atomic", "transaction"} { if a, err := queryParam(req, q); err != nil || a { return a, err } } return false, nil }
[ "func", "isAtomic", "(", "req", "*", "http", ".", "Request", ")", "(", "bool", ",", "error", ")", "{", "// \"transaction\" is checked for backwards compatibility with", "// client libraries.", "for", "_", ",", "q", ":=", "range", "[", "]", "string", "{", "\"", ...
// isAtomic returns whether the HTTP request is an atomic request.
[ "isAtomic", "returns", "whether", "the", "HTTP", "request", "is", "an", "atomic", "request", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L831-L840
train
rqlite/rqlite
http/service.go
txTimeout
func txTimeout(req *http.Request) (time.Duration, bool, error) { return durationParam(req, "tx_timeout") }
go
func txTimeout(req *http.Request) (time.Duration, bool, error) { return durationParam(req, "tx_timeout") }
[ "func", "txTimeout", "(", "req", "*", "http", ".", "Request", ")", "(", "time", ".", "Duration", ",", "bool", ",", "error", ")", "{", "return", "durationParam", "(", "req", ",", "\"", "\"", ")", "\n", "}" ]
// txTimeout returns the duration of any transaction timeout set.
[ "txTimeout", "returns", "the", "duration", "of", "any", "transaction", "timeout", "set", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L853-L855
train
rqlite/rqlite
http/service.go
level
func level(req *http.Request) (store.ConsistencyLevel, error) { q := req.URL.Query() lvl := strings.TrimSpace(q.Get("level")) switch strings.ToLower(lvl) { case "none": return store.None, nil case "weak": return store.Weak, nil case "strong": return store.Strong, nil default: return store.Weak, nil } }
go
func level(req *http.Request) (store.ConsistencyLevel, error) { q := req.URL.Query() lvl := strings.TrimSpace(q.Get("level")) switch strings.ToLower(lvl) { case "none": return store.None, nil case "weak": return store.Weak, nil case "strong": return store.Strong, nil default: return store.Weak, nil } }
[ "func", "level", "(", "req", "*", "http", ".", "Request", ")", "(", "store", ".", "ConsistencyLevel", ",", "error", ")", "{", "q", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "lvl", ":=", "strings", ".", "TrimSpace", "(", "q", ".", "Ge...
// level returns the requested consistency level for a query
[ "level", "returns", "the", "requested", "consistency", "level", "for", "a", "query" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L863-L877
train
rqlite/rqlite
http/service.go
backupFormat
func backupFormat(w http.ResponseWriter, r *http.Request) (store.BackupFormat, error) { fmt, err := fmtParam(r) if err != nil { return store.BackupBinary, err } if fmt == "sql" { w.Header().Set("Content-Type", "application/sql") return store.BackupSQL, nil } w.Header().Set("Content-Type", "application/octet...
go
func backupFormat(w http.ResponseWriter, r *http.Request) (store.BackupFormat, error) { fmt, err := fmtParam(r) if err != nil { return store.BackupBinary, err } if fmt == "sql" { w.Header().Set("Content-Type", "application/sql") return store.BackupSQL, nil } w.Header().Set("Content-Type", "application/octet...
[ "func", "backupFormat", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "(", "store", ".", "BackupFormat", ",", "error", ")", "{", "fmt", ",", "err", ":=", "fmtParam", "(", "r", ")", "\n", "if", "err", "!=", "ni...
// backuFormat returns the request backup format, setting the response header // accordingly.
[ "backuFormat", "returns", "the", "request", "backup", "format", "setting", "the", "response", "header", "accordingly", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/http/service.go#L881-L892
train
rqlite/rqlite
db/db.go
New
func New(path, dsnQuery string, memory bool) (*DB, error) { q, err := url.ParseQuery(dsnQuery) if err != nil { return nil, err } if memory { q.Set("mode", "memory") q.Set("cache", "shared") } if !strings.HasPrefix(path, "file:") { path = fmt.Sprintf("file:%s", path) } var fqdsn string if len(q) > 0 {...
go
func New(path, dsnQuery string, memory bool) (*DB, error) { q, err := url.ParseQuery(dsnQuery) if err != nil { return nil, err } if memory { q.Set("mode", "memory") q.Set("cache", "shared") } if !strings.HasPrefix(path, "file:") { path = fmt.Sprintf("file:%s", path) } var fqdsn string if len(q) > 0 {...
[ "func", "New", "(", "path", ",", "dsnQuery", "string", ",", "memory", "bool", ")", "(", "*", "DB", ",", "error", ")", "{", "q", ",", "err", ":=", "url", ".", "ParseQuery", "(", "dsnQuery", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil"...
// New returns an instance of the database at path. If the database // has already been created and opened, this database will share // the data of that database when connected.
[ "New", "returns", "an", "instance", "of", "the", "database", "at", "path", ".", "If", "the", "database", "has", "already", "been", "created", "and", "opened", "this", "database", "will", "share", "the", "data", "of", "that", "database", "when", "connected", ...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L75-L102
train
rqlite/rqlite
db/db.go
Connect
func (d *DB) Connect() (*Conn, error) { drv := sqlite3.SQLiteDriver{} c, err := drv.Open(d.fqdsn) if err != nil { return nil, err } return &Conn{ sqlite: c.(*sqlite3.SQLiteConn), }, nil }
go
func (d *DB) Connect() (*Conn, error) { drv := sqlite3.SQLiteDriver{} c, err := drv.Open(d.fqdsn) if err != nil { return nil, err } return &Conn{ sqlite: c.(*sqlite3.SQLiteConn), }, nil }
[ "func", "(", "d", "*", "DB", ")", "Connect", "(", ")", "(", "*", "Conn", ",", "error", ")", "{", "drv", ":=", "sqlite3", ".", "SQLiteDriver", "{", "}", "\n", "c", ",", "err", ":=", "drv", ".", "Open", "(", "d", ".", "fqdsn", ")", "\n", "if", ...
// Connect returns a connection to the database.
[ "Connect", "returns", "a", "connection", "to", "the", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L105-L115
train
rqlite/rqlite
db/db.go
Execute
func (c *Conn) Execute(queries []string, tx, xTime bool) ([]*Result, error) { stats.Add(numExecutions, int64(len(queries))) if tx { stats.Add(numETx, 1) } type Execer interface { Exec(query string, args []driver.Value) (driver.Result, error) } var allResults []*Result err := func() error { var execer Exe...
go
func (c *Conn) Execute(queries []string, tx, xTime bool) ([]*Result, error) { stats.Add(numExecutions, int64(len(queries))) if tx { stats.Add(numETx, 1) } type Execer interface { Exec(query string, args []driver.Value) (driver.Result, error) } var allResults []*Result err := func() error { var execer Exe...
[ "func", "(", "c", "*", "Conn", ")", "Execute", "(", "queries", "[", "]", "string", ",", "tx", ",", "xTime", "bool", ")", "(", "[", "]", "*", "Result", ",", "error", ")", "{", "stats", ".", "Add", "(", "numExecutions", ",", "int64", "(", "len", ...
// Execute executes queries that modify the database.
[ "Execute", "executes", "queries", "that", "modify", "the", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L139-L239
train
rqlite/rqlite
db/db.go
Query
func (c *Conn) Query(queries []string, tx, xTime bool) ([]*Rows, error) { stats.Add(numQueries, int64(len(queries))) if tx { stats.Add(numQTx, 1) } type Queryer interface { Query(query string, args []driver.Value) (driver.Rows, error) } var allRows []*Rows err := func() (err error) { var queryer Queryer ...
go
func (c *Conn) Query(queries []string, tx, xTime bool) ([]*Rows, error) { stats.Add(numQueries, int64(len(queries))) if tx { stats.Add(numQTx, 1) } type Queryer interface { Query(query string, args []driver.Value) (driver.Rows, error) } var allRows []*Rows err := func() (err error) { var queryer Queryer ...
[ "func", "(", "c", "*", "Conn", ")", "Query", "(", "queries", "[", "]", "string", ",", "tx", ",", "xTime", "bool", ")", "(", "[", "]", "*", "Rows", ",", "error", ")", "{", "stats", ".", "Add", "(", "numQueries", ",", "int64", "(", "len", "(", ...
// Query executes queries that return rows, but don't modify the database.
[ "Query", "executes", "queries", "that", "return", "rows", "but", "don", "t", "modify", "the", "database", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L242-L320
train
rqlite/rqlite
db/db.go
EnableFKConstraints
func (c *Conn) EnableFKConstraints(e bool) error { q := fkChecksEnabled if !e { q = fkChecksDisabled } _, err := c.sqlite.Exec(q, nil) return err }
go
func (c *Conn) EnableFKConstraints(e bool) error { q := fkChecksEnabled if !e { q = fkChecksDisabled } _, err := c.sqlite.Exec(q, nil) return err }
[ "func", "(", "c", "*", "Conn", ")", "EnableFKConstraints", "(", "e", "bool", ")", "error", "{", "q", ":=", "fkChecksEnabled", "\n", "if", "!", "e", "{", "q", "=", "fkChecksDisabled", "\n", "}", "\n", "_", ",", "err", ":=", "c", ".", "sqlite", ".", ...
// EnableFKConstraints allows control of foreign key constraint checks.
[ "EnableFKConstraints", "allows", "control", "of", "foreign", "key", "constraint", "checks", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L323-L330
train
rqlite/rqlite
db/db.go
FKConstraints
func (c *Conn) FKConstraints() (bool, error) { r, err := c.sqlite.Query(fkChecks, nil) if err != nil { return false, err } dest := make([]driver.Value, len(r.Columns())) types := r.(*sqlite3.SQLiteRows).DeclTypes() if err := r.Next(dest); err != nil { return false, err } values := normalizeRowValues(dest,...
go
func (c *Conn) FKConstraints() (bool, error) { r, err := c.sqlite.Query(fkChecks, nil) if err != nil { return false, err } dest := make([]driver.Value, len(r.Columns())) types := r.(*sqlite3.SQLiteRows).DeclTypes() if err := r.Next(dest); err != nil { return false, err } values := normalizeRowValues(dest,...
[ "func", "(", "c", "*", "Conn", ")", "FKConstraints", "(", ")", "(", "bool", ",", "error", ")", "{", "r", ",", "err", ":=", "c", ".", "sqlite", ".", "Query", "(", "fkChecks", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false...
// FKConstraints returns whether FK constraints are set or not.
[ "FKConstraints", "returns", "whether", "FK", "constraints", "are", "set", "or", "not", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L333-L350
train
rqlite/rqlite
db/db.go
Load
func (c *Conn) Load(src *Conn) error { return copyDatabase(c.sqlite, src.sqlite) }
go
func (c *Conn) Load(src *Conn) error { return copyDatabase(c.sqlite, src.sqlite) }
[ "func", "(", "c", "*", "Conn", ")", "Load", "(", "src", "*", "Conn", ")", "error", "{", "return", "copyDatabase", "(", "c", ".", "sqlite", ",", "src", ".", "sqlite", ")", "\n", "}" ]
// Load loads the connected database from the database connected to src. // It overwrites the data contained in this database. It is the caller's // responsibility to ensure that no other connections to this database // are accessed while this operation is in progress.
[ "Load", "loads", "the", "connected", "database", "from", "the", "database", "connected", "to", "src", ".", "It", "overwrites", "the", "data", "contained", "in", "this", "database", ".", "It", "is", "the", "caller", "s", "responsibility", "to", "ensure", "tha...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L356-L358
train
rqlite/rqlite
db/db.go
Backup
func (c *Conn) Backup(dst *Conn) error { return copyDatabase(dst.sqlite, c.sqlite) }
go
func (c *Conn) Backup(dst *Conn) error { return copyDatabase(dst.sqlite, c.sqlite) }
[ "func", "(", "c", "*", "Conn", ")", "Backup", "(", "dst", "*", "Conn", ")", "error", "{", "return", "copyDatabase", "(", "dst", ".", "sqlite", ",", "c", ".", "sqlite", ")", "\n", "}" ]
// Backup writes a snapshot of the database over the given database // connection, erasing all the contents of the destination database. // The consistency of the snapshot is READ_COMMITTED relative to any // other connections currently open to this database. The caller must // ensure that all connections to the destin...
[ "Backup", "writes", "a", "snapshot", "of", "the", "database", "over", "the", "given", "database", "connection", "erasing", "all", "the", "contents", "of", "the", "destination", "database", ".", "The", "consistency", "of", "the", "snapshot", "is", "READ_COMMITTED...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L366-L368
train
rqlite/rqlite
db/db.go
Dump
func (c *Conn) Dump(w io.Writer) error { if _, err := w.Write([]byte("PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\n")); err != nil { return err } // Get the schema. query := `SELECT "name", "type", "sql" FROM "sqlite_master" WHERE "sql" NOT NULL AND "type" == 'table' ORDER BY "name"` rows, err :=...
go
func (c *Conn) Dump(w io.Writer) error { if _, err := w.Write([]byte("PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\n")); err != nil { return err } // Get the schema. query := `SELECT "name", "type", "sql" FROM "sqlite_master" WHERE "sql" NOT NULL AND "type" == 'table' ORDER BY "name"` rows, err :=...
[ "func", "(", "c", "*", "Conn", ")", "Dump", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\n", "\\n", "\"", ")", ")", ";", "err", "!=", "nil", "{", "r...
// Dump writes a snapshot of the database in SQL text format. The consistency // of the snapshot is READ_COMMITTED relative to any other connections // currently open to this database.
[ "Dump", "writes", "a", "snapshot", "of", "the", "database", "in", "SQL", "text", "format", ".", "The", "consistency", "of", "the", "snapshot", "is", "READ_COMMITTED", "relative", "to", "any", "other", "connections", "currently", "open", "to", "this", "database...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/db/db.go#L373-L450
train
rqlite/rqlite
cmd/rqlite/main.go
cliJSON
func cliJSON(ctx *cli.Context, cmd, line, url string, argv *argT) error { // Recursive JSON printer. var pprint func(indent int, m map[string]interface{}) pprint = func(indent int, m map[string]interface{}) { indentation := " " for k, v := range m { if v == nil { continue } switch v.(type) { cas...
go
func cliJSON(ctx *cli.Context, cmd, line, url string, argv *argT) error { // Recursive JSON printer. var pprint func(indent int, m map[string]interface{}) pprint = func(indent int, m map[string]interface{}) { indentation := " " for k, v := range m { if v == nil { continue } switch v.(type) { cas...
[ "func", "cliJSON", "(", "ctx", "*", "cli", ".", "Context", ",", "cmd", ",", "line", ",", "url", "string", ",", "argv", "*", "argT", ")", "error", "{", "// Recursive JSON printer.", "var", "pprint", "func", "(", "indent", "int", ",", "m", "map", "[", ...
// cliJSON fetches JSON from a URL, and displays it at the CLI.
[ "cliJSON", "fetches", "JSON", "from", "a", "URL", "and", "displays", "it", "at", "the", "CLI", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqlite/main.go#L233-L289
train
rqlite/rqlite
disco/client.go
New
func New(url string) *Client { return &Client{ url: url, logger: log.New(os.Stderr, "[discovery] ", log.LstdFlags), } }
go
func New(url string) *Client { return &Client{ url: url, logger: log.New(os.Stderr, "[discovery] ", log.LstdFlags), } }
[ "func", "New", "(", "url", "string", ")", "*", "Client", "{", "return", "&", "Client", "{", "url", ":", "url", ",", "logger", ":", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "log", ".", "LstdFlags", ")", ",", "}", "\n", ...
// New returns an initialized Discovery Service client.
[ "New", "returns", "an", "initialized", "Discovery", "Service", "client", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/disco/client.go#L29-L34
train
rqlite/rqlite
disco/client.go
Register
func (c *Client) Register(id, addr string) (*Response, error) { m := map[string]string{ "addr": addr, } url := c.registrationURL(c.url, id) client := &http.Client{} client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } for { b, err := json.Marshal(m)...
go
func (c *Client) Register(id, addr string) (*Response, error) { m := map[string]string{ "addr": addr, } url := c.registrationURL(c.url, id) client := &http.Client{} client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } for { b, err := json.Marshal(m)...
[ "func", "(", "c", "*", "Client", ")", "Register", "(", "id", ",", "addr", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "m", ":=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "addr", ",", "}", "\n\n", "url", ":=", ...
// Register attempts to register with the Discovery Service, using the given // address.
[ "Register", "attempts", "to", "register", "with", "the", "Discovery", "Service", "using", "the", "given", "address", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/disco/client.go#L43-L88
train
rqlite/rqlite
cmd/rqlited/main.go
startProfile
func startProfile(cpuprofile, memprofile string) { if cpuprofile != "" { f, err := os.Create(cpuprofile) if err != nil { log.Fatalf("failed to create CPU profile file at %s: %s", cpuprofile, err.Error()) } log.Printf("writing CPU profile to: %s\n", cpuprofile) prof.cpu = f pprof.StartCPUProfile(prof.cpu...
go
func startProfile(cpuprofile, memprofile string) { if cpuprofile != "" { f, err := os.Create(cpuprofile) if err != nil { log.Fatalf("failed to create CPU profile file at %s: %s", cpuprofile, err.Error()) } log.Printf("writing CPU profile to: %s\n", cpuprofile) prof.cpu = f pprof.StartCPUProfile(prof.cpu...
[ "func", "startProfile", "(", "cpuprofile", ",", "memprofile", "string", ")", "{", "if", "cpuprofile", "!=", "\"", "\"", "{", "f", ",", "err", ":=", "os", ".", "Create", "(", "cpuprofile", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf"...
// startProfile initializes the CPU and memory profile, if specified.
[ "startProfile", "initializes", "the", "CPU", "and", "memory", "profile", "if", "specified", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqlited/main.go#L374-L394
train
rqlite/rqlite
cmd/rqlited/main.go
stopProfile
func stopProfile() { if prof.cpu != nil { pprof.StopCPUProfile() prof.cpu.Close() log.Println("CPU profiling stopped") } if prof.mem != nil { pprof.Lookup("heap").WriteTo(prof.mem, 0) prof.mem.Close() log.Println("memory profiling stopped") } }
go
func stopProfile() { if prof.cpu != nil { pprof.StopCPUProfile() prof.cpu.Close() log.Println("CPU profiling stopped") } if prof.mem != nil { pprof.Lookup("heap").WriteTo(prof.mem, 0) prof.mem.Close() log.Println("memory profiling stopped") } }
[ "func", "stopProfile", "(", ")", "{", "if", "prof", ".", "cpu", "!=", "nil", "{", "pprof", ".", "StopCPUProfile", "(", ")", "\n", "prof", ".", "cpu", ".", "Close", "(", ")", "\n", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "}", "\n", "i...
// stopProfile closes the CPU and memory profiles if they are running.
[ "stopProfile", "closes", "the", "CPU", "and", "memory", "profiles", "if", "they", "are", "running", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqlited/main.go#L397-L408
train
rqlite/rqlite
cluster/join.go
Join
func Join(joinAddr []string, id, addr string, meta map[string]string, skip bool) (string, error) { var err error var j string logger := log.New(os.Stderr, "[cluster-join] ", log.LstdFlags) for i := 0; i < numAttempts; i++ { for _, a := range joinAddr { j, err = join(a, id, addr, meta, skip) if err == nil {...
go
func Join(joinAddr []string, id, addr string, meta map[string]string, skip bool) (string, error) { var err error var j string logger := log.New(os.Stderr, "[cluster-join] ", log.LstdFlags) for i := 0; i < numAttempts; i++ { for _, a := range joinAddr { j, err = join(a, id, addr, meta, skip) if err == nil {...
[ "func", "Join", "(", "joinAddr", "[", "]", "string", ",", "id", ",", "addr", "string", ",", "meta", "map", "[", "string", "]", "string", ",", "skip", "bool", ")", "(", "string", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "j", "st...
// Join attempts to join the cluster at one of the addresses given in joinAddr. // It walks through joinAddr in order, and sets the node ID and Raft address of // the joining node as id addr respectively. It returns the endpoint // successfully used to join the cluster.
[ "Join", "attempts", "to", "join", "the", "cluster", "at", "one", "of", "the", "addresses", "given", "in", "joinAddr", ".", "It", "walks", "through", "joinAddr", "in", "order", "and", "sets", "the", "node", "ID", "and", "Raft", "address", "of", "the", "jo...
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cluster/join.go#L25-L43
train
rqlite/rqlite
cmd/rqlite/query.go
Get
func (r *Rows) Get(i, j int) string { if i == 0 { if j >= len(r.Columns) { return "" } return r.Columns[j] } if r.Values == nil { return "NULL" } if i-1 >= len(r.Values) { return "NULL" } if j >= len(r.Values[i-1]) { return "NULL" } return fmt.Sprintf("%v", r.Values[i-1][j]) }
go
func (r *Rows) Get(i, j int) string { if i == 0 { if j >= len(r.Columns) { return "" } return r.Columns[j] } if r.Values == nil { return "NULL" } if i-1 >= len(r.Values) { return "NULL" } if j >= len(r.Values[i-1]) { return "NULL" } return fmt.Sprintf("%v", r.Values[i-1][j]) }
[ "func", "(", "r", "*", "Rows", ")", "Get", "(", "i", ",", "j", "int", ")", "string", "{", "if", "i", "==", "0", "{", "if", "j", ">=", "len", "(", "r", ".", "Columns", ")", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "r", ".", "C...
// Get implements textutil.Table interface
[ "Get", "implements", "textutil", ".", "Table", "interface" ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/cmd/rqlite/query.go#L33-L52
train
rqlite/rqlite
auth/credential_store.go
NewCredentialsStore
func NewCredentialsStore() *CredentialsStore { return &CredentialsStore{ store: make(map[string]string), perms: make(map[string]map[string]bool), } }
go
func NewCredentialsStore() *CredentialsStore { return &CredentialsStore{ store: make(map[string]string), perms: make(map[string]map[string]bool), } }
[ "func", "NewCredentialsStore", "(", ")", "*", "CredentialsStore", "{", "return", "&", "CredentialsStore", "{", "store", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "perms", ":", "make", "(", "map", "[", "string", "]", "map", "[", "...
// NewCredentialsStore returns a new instance of a CredentialStore.
[ "NewCredentialsStore", "returns", "a", "new", "instance", "of", "a", "CredentialStore", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/auth/credential_store.go#L31-L36
train
rqlite/rqlite
auth/credential_store.go
Load
func (c *CredentialsStore) Load(r io.Reader) error { dec := json.NewDecoder(r) // Read open bracket _, err := dec.Token() if err != nil { return err } var cred Credential for dec.More() { err := dec.Decode(&cred) if err != nil { return err } c.store[cred.Username] = cred.Password c.perms[cred.Use...
go
func (c *CredentialsStore) Load(r io.Reader) error { dec := json.NewDecoder(r) // Read open bracket _, err := dec.Token() if err != nil { return err } var cred Credential for dec.More() { err := dec.Decode(&cred) if err != nil { return err } c.store[cred.Username] = cred.Password c.perms[cred.Use...
[ "func", "(", "c", "*", "CredentialsStore", ")", "Load", "(", "r", "io", ".", "Reader", ")", "error", "{", "dec", ":=", "json", ".", "NewDecoder", "(", "r", ")", "\n", "// Read open bracket", "_", ",", "err", ":=", "dec", ".", "Token", "(", ")", "\n...
// Load loads credential information from a reader.
[ "Load", "loads", "credential", "information", "from", "a", "reader", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/auth/credential_store.go#L39-L67
train
rqlite/rqlite
auth/credential_store.go
Check
func (c *CredentialsStore) Check(username, password string) bool { pw, ok := c.store[username] if !ok { return false } return password == pw || bcrypt.CompareHashAndPassword([]byte(pw), []byte(password)) == nil }
go
func (c *CredentialsStore) Check(username, password string) bool { pw, ok := c.store[username] if !ok { return false } return password == pw || bcrypt.CompareHashAndPassword([]byte(pw), []byte(password)) == nil }
[ "func", "(", "c", "*", "CredentialsStore", ")", "Check", "(", "username", ",", "password", "string", ")", "bool", "{", "pw", ",", "ok", ":=", "c", ".", "store", "[", "username", "]", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", ...
// Check returns true if the password is correct for the given username.
[ "Check", "returns", "true", "if", "the", "password", "is", "correct", "for", "the", "given", "username", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/auth/credential_store.go#L70-L77
train
rqlite/rqlite
auth/credential_store.go
CheckRequest
func (c *CredentialsStore) CheckRequest(b BasicAuther) bool { username, password, ok := b.BasicAuth() if !ok || !c.Check(username, password) { return false } return true }
go
func (c *CredentialsStore) CheckRequest(b BasicAuther) bool { username, password, ok := b.BasicAuth() if !ok || !c.Check(username, password) { return false } return true }
[ "func", "(", "c", "*", "CredentialsStore", ")", "CheckRequest", "(", "b", "BasicAuther", ")", "bool", "{", "username", ",", "password", ",", "ok", ":=", "b", ".", "BasicAuth", "(", ")", "\n", "if", "!", "ok", "||", "!", "c", ".", "Check", "(", "use...
// CheckRequest returns true if b contains a valid username and password.
[ "CheckRequest", "returns", "true", "if", "b", "contains", "a", "valid", "username", "and", "password", "." ]
12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3
https://github.com/rqlite/rqlite/blob/12a954c7ef29a9060870c0b5c6c4d8a9e8c35ce3/auth/credential_store.go#L80-L86
train