id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
147,700
wcharczuk/go-chart
seq/linear.go
GetValue
func (lg Linear) GetValue(index int) float64 { fi := float64(index) if lg.start < lg.end { return lg.start + (fi * lg.step) } return lg.start - (fi * lg.step) }
go
func (lg Linear) GetValue(index int) float64 { fi := float64(index) if lg.start < lg.end { return lg.start + (fi * lg.step) } return lg.start - (fi * lg.step) }
[ "func", "(", "lg", "Linear", ")", "GetValue", "(", "index", "int", ")", "float64", "{", "fi", ":=", "float64", "(", "index", ")", "\n", "if", "lg", ".", "start", "<", "lg", ".", "end", "{", "return", "lg", ".", "start", "+", "(", "fi", "*", "lg", ".", "step", ")", "\n", "}", "\n", "return", "lg", ".", "start", "-", "(", "fi", "*", "lg", ".", "step", ")", "\n", "}" ]
// GetValue returns the value at a given index.
[ "GetValue", "returns", "the", "value", "at", "a", "given", "index", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/linear.go#L49-L55
147,701
wcharczuk/go-chart
seq/linear.go
WithStart
func (lg *Linear) WithStart(start float64) *Linear { lg.start = start return lg }
go
func (lg *Linear) WithStart(start float64) *Linear { lg.start = start return lg }
[ "func", "(", "lg", "*", "Linear", ")", "WithStart", "(", "start", "float64", ")", "*", "Linear", "{", "lg", ".", "start", "=", "start", "\n", "return", "lg", "\n", "}" ]
// WithStart sets the start and returns the linear generator.
[ "WithStart", "sets", "the", "start", "and", "returns", "the", "linear", "generator", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/linear.go#L58-L61
147,702
wcharczuk/go-chart
seq/linear.go
WithEnd
func (lg *Linear) WithEnd(end float64) *Linear { lg.end = end return lg }
go
func (lg *Linear) WithEnd(end float64) *Linear { lg.end = end return lg }
[ "func", "(", "lg", "*", "Linear", ")", "WithEnd", "(", "end", "float64", ")", "*", "Linear", "{", "lg", ".", "end", "=", "end", "\n", "return", "lg", "\n", "}" ]
// WithEnd sets the end and returns the linear generator.
[ "WithEnd", "sets", "the", "end", "and", "returns", "the", "linear", "generator", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/linear.go#L64-L67
147,703
wcharczuk/go-chart
seq/linear.go
WithStep
func (lg *Linear) WithStep(step float64) *Linear { lg.step = step return lg }
go
func (lg *Linear) WithStep(step float64) *Linear { lg.step = step return lg }
[ "func", "(", "lg", "*", "Linear", ")", "WithStep", "(", "step", "float64", ")", "*", "Linear", "{", "lg", ".", "step", "=", "step", "\n", "return", "lg", "\n", "}" ]
// WithStep sets the step and returns the linear generator.
[ "WithStep", "sets", "the", "step", "and", "returns", "the", "linear", "generator", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/linear.go#L70-L73
147,704
wcharczuk/go-chart
ema_series.go
GetFirstValues
func (ema *EMASeries) GetFirstValues() (x, y float64) { if ema.InnerSeries == nil { return } if len(ema.cache) == 0 { ema.ensureCachedValues() } x, _ = ema.InnerSeries.GetValues(0) y = ema.cache[0] return }
go
func (ema *EMASeries) GetFirstValues() (x, y float64) { if ema.InnerSeries == nil { return } if len(ema.cache) == 0 { ema.ensureCachedValues() } x, _ = ema.InnerSeries.GetValues(0) y = ema.cache[0] return }
[ "func", "(", "ema", "*", "EMASeries", ")", "GetFirstValues", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "if", "ema", ".", "InnerSeries", "==", "nil", "{", "return", "\n", "}", "\n", "if", "len", "(", "ema", ".", "cache", ")", "==", "0", "{", "ema", ".", "ensureCachedValues", "(", ")", "\n", "}", "\n", "x", ",", "_", "=", "ema", ".", "InnerSeries", ".", "GetValues", "(", "0", ")", "\n", "y", "=", "ema", ".", "cache", "[", "0", "]", "\n", "return", "\n", "}" ]
// GetFirstValues computes the first moving average value.
[ "GetFirstValues", "computes", "the", "first", "moving", "average", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/ema_series.go#L77-L87
147,705
wcharczuk/go-chart
concat_series.go
Len
func (cs ConcatSeries) Len() int { total := 0 for _, s := range cs { if typed, isValuesProvider := s.(ValuesProvider); isValuesProvider { total += typed.Len() } } return total }
go
func (cs ConcatSeries) Len() int { total := 0 for _, s := range cs { if typed, isValuesProvider := s.(ValuesProvider); isValuesProvider { total += typed.Len() } } return total }
[ "func", "(", "cs", "ConcatSeries", ")", "Len", "(", ")", "int", "{", "total", ":=", "0", "\n", "for", "_", ",", "s", ":=", "range", "cs", "{", "if", "typed", ",", "isValuesProvider", ":=", "s", ".", "(", "ValuesProvider", ")", ";", "isValuesProvider", "{", "total", "+=", "typed", ".", "Len", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "total", "\n", "}" ]
// Len returns the length of the concatenated set of series.
[ "Len", "returns", "the", "length", "of", "the", "concatenated", "set", "of", "series", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/concat_series.go#L7-L16
147,706
wcharczuk/go-chart
drawing/stack_graphic_context.go
NewStackGraphicContext
func NewStackGraphicContext() *StackGraphicContext { gc := &StackGraphicContext{} gc.current = new(ContextStack) gc.current.Tr = NewIdentityMatrix() gc.current.Path = new(Path) gc.current.LineWidth = 1.0 gc.current.StrokeColor = image.Black gc.current.FillColor = image.White gc.current.Cap = RoundCap gc.current.FillRule = FillRuleEvenOdd gc.current.Join = RoundJoin gc.current.FontSizePoints = 10 return gc }
go
func NewStackGraphicContext() *StackGraphicContext { gc := &StackGraphicContext{} gc.current = new(ContextStack) gc.current.Tr = NewIdentityMatrix() gc.current.Path = new(Path) gc.current.LineWidth = 1.0 gc.current.StrokeColor = image.Black gc.current.FillColor = image.White gc.current.Cap = RoundCap gc.current.FillRule = FillRuleEvenOdd gc.current.Join = RoundJoin gc.current.FontSizePoints = 10 return gc }
[ "func", "NewStackGraphicContext", "(", ")", "*", "StackGraphicContext", "{", "gc", ":=", "&", "StackGraphicContext", "{", "}", "\n", "gc", ".", "current", "=", "new", "(", "ContextStack", ")", "\n", "gc", ".", "current", ".", "Tr", "=", "NewIdentityMatrix", "(", ")", "\n", "gc", ".", "current", ".", "Path", "=", "new", "(", "Path", ")", "\n", "gc", ".", "current", ".", "LineWidth", "=", "1.0", "\n", "gc", ".", "current", ".", "StrokeColor", "=", "image", ".", "Black", "\n", "gc", ".", "current", ".", "FillColor", "=", "image", ".", "White", "\n", "gc", ".", "current", ".", "Cap", "=", "RoundCap", "\n", "gc", ".", "current", ".", "FillRule", "=", "FillRuleEvenOdd", "\n", "gc", ".", "current", ".", "Join", "=", "RoundJoin", "\n", "gc", ".", "current", ".", "FontSizePoints", "=", "10", "\n", "return", "gc", "\n", "}" ]
// NewStackGraphicContext Create a new Graphic context from an image
[ "NewStackGraphicContext", "Create", "a", "new", "Graphic", "context", "from", "an", "image" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L37-L50
147,707
wcharczuk/go-chart
drawing/stack_graphic_context.go
ComposeMatrixTransform
func (gc *StackGraphicContext) ComposeMatrixTransform(tr Matrix) { gc.current.Tr.Compose(tr) }
go
func (gc *StackGraphicContext) ComposeMatrixTransform(tr Matrix) { gc.current.Tr.Compose(tr) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "ComposeMatrixTransform", "(", "tr", "Matrix", ")", "{", "gc", ".", "current", ".", "Tr", ".", "Compose", "(", "tr", ")", "\n", "}" ]
// ComposeMatrixTransform composes a transform into the current transform.
[ "ComposeMatrixTransform", "composes", "a", "transform", "into", "the", "current", "transform", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L63-L65
147,708
wcharczuk/go-chart
drawing/stack_graphic_context.go
Rotate
func (gc *StackGraphicContext) Rotate(angle float64) { gc.current.Tr.Rotate(angle) }
go
func (gc *StackGraphicContext) Rotate(angle float64) { gc.current.Tr.Rotate(angle) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "Rotate", "(", "angle", "float64", ")", "{", "gc", ".", "current", ".", "Tr", ".", "Rotate", "(", "angle", ")", "\n", "}" ]
// Rotate rotates the matrix transform by an angle in degrees.
[ "Rotate", "rotates", "the", "matrix", "transform", "by", "an", "angle", "in", "degrees", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L68-L70
147,709
wcharczuk/go-chart
drawing/stack_graphic_context.go
Translate
func (gc *StackGraphicContext) Translate(tx, ty float64) { gc.current.Tr.Translate(tx, ty) }
go
func (gc *StackGraphicContext) Translate(tx, ty float64) { gc.current.Tr.Translate(tx, ty) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "Translate", "(", "tx", ",", "ty", "float64", ")", "{", "gc", ".", "current", ".", "Tr", ".", "Translate", "(", "tx", ",", "ty", ")", "\n", "}" ]
// Translate translates a transform.
[ "Translate", "translates", "a", "transform", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L73-L75
147,710
wcharczuk/go-chart
drawing/stack_graphic_context.go
Scale
func (gc *StackGraphicContext) Scale(sx, sy float64) { gc.current.Tr.Scale(sx, sy) }
go
func (gc *StackGraphicContext) Scale(sx, sy float64) { gc.current.Tr.Scale(sx, sy) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "Scale", "(", "sx", ",", "sy", "float64", ")", "{", "gc", ".", "current", ".", "Tr", ".", "Scale", "(", "sx", ",", "sy", ")", "\n", "}" ]
// Scale scales a transform.
[ "Scale", "scales", "a", "transform", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L78-L80
147,711
wcharczuk/go-chart
drawing/stack_graphic_context.go
SetStrokeColor
func (gc *StackGraphicContext) SetStrokeColor(c color.Color) { gc.current.StrokeColor = c }
go
func (gc *StackGraphicContext) SetStrokeColor(c color.Color) { gc.current.StrokeColor = c }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "SetStrokeColor", "(", "c", "color", ".", "Color", ")", "{", "gc", ".", "current", ".", "StrokeColor", "=", "c", "\n", "}" ]
// SetStrokeColor sets the stroke color.
[ "SetStrokeColor", "sets", "the", "stroke", "color", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L83-L85
147,712
wcharczuk/go-chart
drawing/stack_graphic_context.go
SetFillColor
func (gc *StackGraphicContext) SetFillColor(c color.Color) { gc.current.FillColor = c }
go
func (gc *StackGraphicContext) SetFillColor(c color.Color) { gc.current.FillColor = c }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "SetFillColor", "(", "c", "color", ".", "Color", ")", "{", "gc", ".", "current", ".", "FillColor", "=", "c", "\n", "}" ]
// SetFillColor sets the fill color.
[ "SetFillColor", "sets", "the", "fill", "color", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L88-L90
147,713
wcharczuk/go-chart
drawing/stack_graphic_context.go
SetLineDash
func (gc *StackGraphicContext) SetLineDash(dash []float64, dashOffset float64) { gc.current.Dash = dash gc.current.DashOffset = dashOffset }
go
func (gc *StackGraphicContext) SetLineDash(dash []float64, dashOffset float64) { gc.current.Dash = dash gc.current.DashOffset = dashOffset }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "SetLineDash", "(", "dash", "[", "]", "float64", ",", "dashOffset", "float64", ")", "{", "gc", ".", "current", ".", "Dash", "=", "dash", "\n", "gc", ".", "current", ".", "DashOffset", "=", "dashOffset", "\n", "}" ]
// SetLineDash sets the line dash.
[ "SetLineDash", "sets", "the", "line", "dash", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L113-L116
147,714
wcharczuk/go-chart
drawing/stack_graphic_context.go
SetFont
func (gc *StackGraphicContext) SetFont(f *truetype.Font) { gc.current.Font = f }
go
func (gc *StackGraphicContext) SetFont(f *truetype.Font) { gc.current.Font = f }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "SetFont", "(", "f", "*", "truetype", ".", "Font", ")", "{", "gc", ".", "current", ".", "Font", "=", "f", "\n", "}" ]
// SetFont sets the current font.
[ "SetFont", "sets", "the", "current", "font", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L129-L131
147,715
wcharczuk/go-chart
drawing/stack_graphic_context.go
LastPoint
func (gc *StackGraphicContext) LastPoint() (x float64, y float64) { return gc.current.Path.LastPoint() }
go
func (gc *StackGraphicContext) LastPoint() (x float64, y float64) { return gc.current.Path.LastPoint() }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "LastPoint", "(", ")", "(", "x", "float64", ",", "y", "float64", ")", "{", "return", "gc", ".", "current", ".", "Path", ".", "LastPoint", "(", ")", "\n", "}" ]
// LastPoint returns the last point on the path.
[ "LastPoint", "returns", "the", "last", "point", "on", "the", "path", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L149-L151
147,716
wcharczuk/go-chart
drawing/stack_graphic_context.go
MoveTo
func (gc *StackGraphicContext) MoveTo(x, y float64) { gc.current.Path.MoveTo(x, y) }
go
func (gc *StackGraphicContext) MoveTo(x, y float64) { gc.current.Path.MoveTo(x, y) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "MoveTo", "(", "x", ",", "y", "float64", ")", "{", "gc", ".", "current", ".", "Path", ".", "MoveTo", "(", "x", ",", "y", ")", "\n", "}" ]
// MoveTo moves the cursor for a path.
[ "MoveTo", "moves", "the", "cursor", "for", "a", "path", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L154-L156
147,717
wcharczuk/go-chart
drawing/stack_graphic_context.go
LineTo
func (gc *StackGraphicContext) LineTo(x, y float64) { gc.current.Path.LineTo(x, y) }
go
func (gc *StackGraphicContext) LineTo(x, y float64) { gc.current.Path.LineTo(x, y) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "LineTo", "(", "x", ",", "y", "float64", ")", "{", "gc", ".", "current", ".", "Path", ".", "LineTo", "(", "x", ",", "y", ")", "\n", "}" ]
// LineTo draws a line.
[ "LineTo", "draws", "a", "line", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L159-L161
147,718
wcharczuk/go-chart
drawing/stack_graphic_context.go
ArcTo
func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, delta float64) { gc.current.Path.ArcTo(cx, cy, rx, ry, startAngle, delta) }
go
func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, delta float64) { gc.current.Path.ArcTo(cx, cy, rx, ry, startAngle, delta) }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "ArcTo", "(", "cx", ",", "cy", ",", "rx", ",", "ry", ",", "startAngle", ",", "delta", "float64", ")", "{", "gc", ".", "current", ".", "Path", ".", "ArcTo", "(", "cx", ",", "cy", ",", "rx", ",", "ry", ",", "startAngle", ",", "delta", ")", "\n", "}" ]
// ArcTo draws an arc.
[ "ArcTo", "draws", "an", "arc", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L174-L176
147,719
wcharczuk/go-chart
drawing/stack_graphic_context.go
Save
func (gc *StackGraphicContext) Save() { context := new(ContextStack) context.FontSizePoints = gc.current.FontSizePoints context.Font = gc.current.Font context.LineWidth = gc.current.LineWidth context.StrokeColor = gc.current.StrokeColor context.FillColor = gc.current.FillColor context.FillRule = gc.current.FillRule context.Dash = gc.current.Dash context.DashOffset = gc.current.DashOffset context.Cap = gc.current.Cap context.Join = gc.current.Join context.Path = gc.current.Path.Copy() context.Font = gc.current.Font context.Scale = gc.current.Scale copy(context.Tr[:], gc.current.Tr[:]) context.Previous = gc.current gc.current = context }
go
func (gc *StackGraphicContext) Save() { context := new(ContextStack) context.FontSizePoints = gc.current.FontSizePoints context.Font = gc.current.Font context.LineWidth = gc.current.LineWidth context.StrokeColor = gc.current.StrokeColor context.FillColor = gc.current.FillColor context.FillRule = gc.current.FillRule context.Dash = gc.current.Dash context.DashOffset = gc.current.DashOffset context.Cap = gc.current.Cap context.Join = gc.current.Join context.Path = gc.current.Path.Copy() context.Font = gc.current.Font context.Scale = gc.current.Scale copy(context.Tr[:], gc.current.Tr[:]) context.Previous = gc.current gc.current = context }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "Save", "(", ")", "{", "context", ":=", "new", "(", "ContextStack", ")", "\n", "context", ".", "FontSizePoints", "=", "gc", ".", "current", ".", "FontSizePoints", "\n", "context", ".", "Font", "=", "gc", ".", "current", ".", "Font", "\n", "context", ".", "LineWidth", "=", "gc", ".", "current", ".", "LineWidth", "\n", "context", ".", "StrokeColor", "=", "gc", ".", "current", ".", "StrokeColor", "\n", "context", ".", "FillColor", "=", "gc", ".", "current", ".", "FillColor", "\n", "context", ".", "FillRule", "=", "gc", ".", "current", ".", "FillRule", "\n", "context", ".", "Dash", "=", "gc", ".", "current", ".", "Dash", "\n", "context", ".", "DashOffset", "=", "gc", ".", "current", ".", "DashOffset", "\n", "context", ".", "Cap", "=", "gc", ".", "current", ".", "Cap", "\n", "context", ".", "Join", "=", "gc", ".", "current", ".", "Join", "\n", "context", ".", "Path", "=", "gc", ".", "current", ".", "Path", ".", "Copy", "(", ")", "\n", "context", ".", "Font", "=", "gc", ".", "current", ".", "Font", "\n", "context", ".", "Scale", "=", "gc", ".", "current", ".", "Scale", "\n", "copy", "(", "context", ".", "Tr", "[", ":", "]", ",", "gc", ".", "current", ".", "Tr", "[", ":", "]", ")", "\n", "context", ".", "Previous", "=", "gc", ".", "current", "\n", "gc", ".", "current", "=", "context", "\n", "}" ]
// Save pushes a context onto the stack.
[ "Save", "pushes", "a", "context", "onto", "the", "stack", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L184-L202
147,720
wcharczuk/go-chart
drawing/stack_graphic_context.go
Restore
func (gc *StackGraphicContext) Restore() { if gc.current.Previous != nil { oldContext := gc.current gc.current = gc.current.Previous oldContext.Previous = nil } }
go
func (gc *StackGraphicContext) Restore() { if gc.current.Previous != nil { oldContext := gc.current gc.current = gc.current.Previous oldContext.Previous = nil } }
[ "func", "(", "gc", "*", "StackGraphicContext", ")", "Restore", "(", ")", "{", "if", "gc", ".", "current", ".", "Previous", "!=", "nil", "{", "oldContext", ":=", "gc", ".", "current", "\n", "gc", ".", "current", "=", "gc", ".", "current", ".", "Previous", "\n", "oldContext", ".", "Previous", "=", "nil", "\n", "}", "\n", "}" ]
// Restore restores the previous context.
[ "Restore", "restores", "the", "previous", "context", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stack_graphic_context.go#L205-L211
147,721
wcharczuk/go-chart
linear_regression_series.go
Coefficients
func (lrs LinearRegressionSeries) Coefficients() (m, b, stdev, avg float64) { if lrs.IsZero() { lrs.computeCoefficients() } m = lrs.m b = lrs.b stdev = lrs.stddevx avg = lrs.avgx return }
go
func (lrs LinearRegressionSeries) Coefficients() (m, b, stdev, avg float64) { if lrs.IsZero() { lrs.computeCoefficients() } m = lrs.m b = lrs.b stdev = lrs.stddevx avg = lrs.avgx return }
[ "func", "(", "lrs", "LinearRegressionSeries", ")", "Coefficients", "(", ")", "(", "m", ",", "b", ",", "stdev", ",", "avg", "float64", ")", "{", "if", "lrs", ".", "IsZero", "(", ")", "{", "lrs", ".", "computeCoefficients", "(", ")", "\n", "}", "\n\n", "m", "=", "lrs", ".", "m", "\n", "b", "=", "lrs", ".", "b", "\n", "stdev", "=", "lrs", ".", "stddevx", "\n", "avg", "=", "lrs", ".", "avgx", "\n", "return", "\n", "}" ]
// Coefficients returns the linear coefficients for the series.
[ "Coefficients", "returns", "the", "linear", "coefficients", "for", "the", "series", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/linear_regression_series.go#L36-L46
147,722
wcharczuk/go-chart
linear_regression_series.go
GetLastValues
func (lrs *LinearRegressionSeries) GetLastValues() (x, y float64) { if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 { return } if lrs.IsZero() { lrs.computeCoefficients() } endIndex := lrs.GetEndIndex() x, y = lrs.InnerSeries.GetValues(endIndex) y = (lrs.m * lrs.normalize(x)) + lrs.b return }
go
func (lrs *LinearRegressionSeries) GetLastValues() (x, y float64) { if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 { return } if lrs.IsZero() { lrs.computeCoefficients() } endIndex := lrs.GetEndIndex() x, y = lrs.InnerSeries.GetValues(endIndex) y = (lrs.m * lrs.normalize(x)) + lrs.b return }
[ "func", "(", "lrs", "*", "LinearRegressionSeries", ")", "GetLastValues", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "if", "lrs", ".", "InnerSeries", "==", "nil", "||", "lrs", ".", "InnerSeries", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "lrs", ".", "IsZero", "(", ")", "{", "lrs", ".", "computeCoefficients", "(", ")", "\n", "}", "\n", "endIndex", ":=", "lrs", ".", "GetEndIndex", "(", ")", "\n", "x", ",", "y", "=", "lrs", ".", "InnerSeries", ".", "GetValues", "(", "endIndex", ")", "\n", "y", "=", "(", "lrs", ".", "m", "*", "lrs", ".", "normalize", "(", "x", ")", ")", "+", "lrs", ".", "b", "\n", "return", "\n", "}" ]
// GetLastValues computes the last linear regression value.
[ "GetLastValues", "computes", "the", "last", "linear", "regression", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/linear_regression_series.go#L120-L131
147,723
wcharczuk/go-chart
util/file_util.go
ReadByLines
func (fu fileUtil) ReadByLines(filePath string, handler func(line string) error) error { var f *os.File var err error if f, err = os.Open(filePath); err == nil { defer f.Close() var line string scanner := bufio.NewScanner(f) for scanner.Scan() { line = scanner.Text() err = handler(line) if err != nil { return err } } } return err }
go
func (fu fileUtil) ReadByLines(filePath string, handler func(line string) error) error { var f *os.File var err error if f, err = os.Open(filePath); err == nil { defer f.Close() var line string scanner := bufio.NewScanner(f) for scanner.Scan() { line = scanner.Text() err = handler(line) if err != nil { return err } } } return err }
[ "func", "(", "fu", "fileUtil", ")", "ReadByLines", "(", "filePath", "string", ",", "handler", "func", "(", "line", "string", ")", "error", ")", "error", "{", "var", "f", "*", "os", ".", "File", "\n", "var", "err", "error", "\n", "if", "f", ",", "err", "=", "os", ".", "Open", "(", "filePath", ")", ";", "err", "==", "nil", "{", "defer", "f", ".", "Close", "(", ")", "\n", "var", "line", "string", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "f", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "line", "=", "scanner", ".", "Text", "(", ")", "\n", "err", "=", "handler", "(", "line", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n\n", "}" ]
// ReadByLines reads a file and calls the handler for each line.
[ "ReadByLines", "reads", "a", "file", "and", "calls", "the", "handler", "for", "each", "line", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/file_util.go#L17-L34
147,724
wcharczuk/go-chart
util/file_util.go
ReadByChunks
func (fu fileUtil) ReadByChunks(filePath string, chunkSize int, handler func(line []byte) error) error { var f *os.File var err error if f, err = os.Open(filePath); err == nil { defer f.Close() chunk := make([]byte, chunkSize) for { readBytes, err := f.Read(chunk) if err == io.EOF { break } readData := chunk[:readBytes] err = handler(readData) if err != nil { return err } } } return err }
go
func (fu fileUtil) ReadByChunks(filePath string, chunkSize int, handler func(line []byte) error) error { var f *os.File var err error if f, err = os.Open(filePath); err == nil { defer f.Close() chunk := make([]byte, chunkSize) for { readBytes, err := f.Read(chunk) if err == io.EOF { break } readData := chunk[:readBytes] err = handler(readData) if err != nil { return err } } } return err }
[ "func", "(", "fu", "fileUtil", ")", "ReadByChunks", "(", "filePath", "string", ",", "chunkSize", "int", ",", "handler", "func", "(", "line", "[", "]", "byte", ")", "error", ")", "error", "{", "var", "f", "*", "os", ".", "File", "\n", "var", "err", "error", "\n", "if", "f", ",", "err", "=", "os", ".", "Open", "(", "filePath", ")", ";", "err", "==", "nil", "{", "defer", "f", ".", "Close", "(", ")", "\n\n", "chunk", ":=", "make", "(", "[", "]", "byte", ",", "chunkSize", ")", "\n", "for", "{", "readBytes", ",", "err", ":=", "f", ".", "Read", "(", "chunk", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "readData", ":=", "chunk", "[", ":", "readBytes", "]", "\n", "err", "=", "handler", "(", "readData", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// ReadByChunks reads a file in `chunkSize` pieces, dispatched to the handler.
[ "ReadByChunks", "reads", "a", "file", "in", "chunkSize", "pieces", "dispatched", "to", "the", "handler", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/file_util.go#L37-L57
147,725
wcharczuk/go-chart
seq/buffer.go
NewBuffer
func NewBuffer(values ...float64) *Buffer { var tail int array := make([]float64, util.Math.MaxInt(len(values), bufferDefaultCapacity)) if len(values) > 0 { copy(array, values) tail = len(values) } return &Buffer{ array: array, head: 0, tail: tail, size: len(values), } }
go
func NewBuffer(values ...float64) *Buffer { var tail int array := make([]float64, util.Math.MaxInt(len(values), bufferDefaultCapacity)) if len(values) > 0 { copy(array, values) tail = len(values) } return &Buffer{ array: array, head: 0, tail: tail, size: len(values), } }
[ "func", "NewBuffer", "(", "values", "...", "float64", ")", "*", "Buffer", "{", "var", "tail", "int", "\n", "array", ":=", "make", "(", "[", "]", "float64", ",", "util", ".", "Math", ".", "MaxInt", "(", "len", "(", "values", ")", ",", "bufferDefaultCapacity", ")", ")", "\n", "if", "len", "(", "values", ")", ">", "0", "{", "copy", "(", "array", ",", "values", ")", "\n", "tail", "=", "len", "(", "values", ")", "\n", "}", "\n", "return", "&", "Buffer", "{", "array", ":", "array", ",", "head", ":", "0", ",", "tail", ":", "tail", ",", "size", ":", "len", "(", "values", ")", ",", "}", "\n", "}" ]
// NewBuffer creates a new value buffer with an optional set of values.
[ "NewBuffer", "creates", "a", "new", "value", "buffer", "with", "an", "optional", "set", "of", "values", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L22-L35
147,726
wcharczuk/go-chart
seq/buffer.go
NewBufferWithCapacity
func NewBufferWithCapacity(capacity int) *Buffer { return &Buffer{ array: make([]float64, capacity), head: 0, tail: 0, size: 0, } }
go
func NewBufferWithCapacity(capacity int) *Buffer { return &Buffer{ array: make([]float64, capacity), head: 0, tail: 0, size: 0, } }
[ "func", "NewBufferWithCapacity", "(", "capacity", "int", ")", "*", "Buffer", "{", "return", "&", "Buffer", "{", "array", ":", "make", "(", "[", "]", "float64", ",", "capacity", ")", ",", "head", ":", "0", ",", "tail", ":", "0", ",", "size", ":", "0", ",", "}", "\n", "}" ]
// NewBufferWithCapacity creates a new ValueBuffer pre-allocated with the given capacity.
[ "NewBufferWithCapacity", "creates", "a", "new", "ValueBuffer", "pre", "-", "allocated", "with", "the", "given", "capacity", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L38-L45
147,727
wcharczuk/go-chart
seq/buffer.go
GetValue
func (b *Buffer) GetValue(index int) float64 { effectiveIndex := (b.head + index) % len(b.array) return b.array[effectiveIndex] }
go
func (b *Buffer) GetValue(index int) float64 { effectiveIndex := (b.head + index) % len(b.array) return b.array[effectiveIndex] }
[ "func", "(", "b", "*", "Buffer", ")", "GetValue", "(", "index", "int", ")", "float64", "{", "effectiveIndex", ":=", "(", "b", ".", "head", "+", "index", ")", "%", "len", "(", "b", ".", "array", ")", "\n", "return", "b", ".", "array", "[", "effectiveIndex", "]", "\n", "}" ]
// GetValue implements seq provider.
[ "GetValue", "implements", "seq", "provider", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L65-L68
147,728
wcharczuk/go-chart
seq/buffer.go
SetCapacity
func (b *Buffer) SetCapacity(capacity int) { newArray := make([]float64, capacity) if b.size > 0 { if b.head < b.tail { arrayCopy(b.array, b.head, newArray, 0, b.size) } else { arrayCopy(b.array, b.head, newArray, 0, len(b.array)-b.head) arrayCopy(b.array, 0, newArray, len(b.array)-b.head, b.tail) } } b.array = newArray b.head = 0 if b.size == capacity { b.tail = 0 } else { b.tail = b.size } }
go
func (b *Buffer) SetCapacity(capacity int) { newArray := make([]float64, capacity) if b.size > 0 { if b.head < b.tail { arrayCopy(b.array, b.head, newArray, 0, b.size) } else { arrayCopy(b.array, b.head, newArray, 0, len(b.array)-b.head) arrayCopy(b.array, 0, newArray, len(b.array)-b.head, b.tail) } } b.array = newArray b.head = 0 if b.size == capacity { b.tail = 0 } else { b.tail = b.size } }
[ "func", "(", "b", "*", "Buffer", ")", "SetCapacity", "(", "capacity", "int", ")", "{", "newArray", ":=", "make", "(", "[", "]", "float64", ",", "capacity", ")", "\n", "if", "b", ".", "size", ">", "0", "{", "if", "b", ".", "head", "<", "b", ".", "tail", "{", "arrayCopy", "(", "b", ".", "array", ",", "b", ".", "head", ",", "newArray", ",", "0", ",", "b", ".", "size", ")", "\n", "}", "else", "{", "arrayCopy", "(", "b", ".", "array", ",", "b", ".", "head", ",", "newArray", ",", "0", ",", "len", "(", "b", ".", "array", ")", "-", "b", ".", "head", ")", "\n", "arrayCopy", "(", "b", ".", "array", ",", "0", ",", "newArray", ",", "len", "(", "b", ".", "array", ")", "-", "b", ".", "head", ",", "b", ".", "tail", ")", "\n", "}", "\n", "}", "\n", "b", ".", "array", "=", "newArray", "\n", "b", ".", "head", "=", "0", "\n", "if", "b", ".", "size", "==", "capacity", "{", "b", ".", "tail", "=", "0", "\n", "}", "else", "{", "b", ".", "tail", "=", "b", ".", "size", "\n", "}", "\n", "}" ]
// SetCapacity sets the capacity of the Buffer.
[ "SetCapacity", "sets", "the", "capacity", "of", "the", "Buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L76-L93
147,729
wcharczuk/go-chart
seq/buffer.go
Clear
func (b *Buffer) Clear() { b.array = make([]float64, bufferDefaultCapacity) b.head = 0 b.tail = 0 b.size = 0 }
go
func (b *Buffer) Clear() { b.array = make([]float64, bufferDefaultCapacity) b.head = 0 b.tail = 0 b.size = 0 }
[ "func", "(", "b", "*", "Buffer", ")", "Clear", "(", ")", "{", "b", ".", "array", "=", "make", "(", "[", "]", "float64", ",", "bufferDefaultCapacity", ")", "\n", "b", ".", "head", "=", "0", "\n", "b", ".", "tail", "=", "0", "\n", "b", ".", "size", "=", "0", "\n", "}" ]
// Clear removes all objects from the Buffer.
[ "Clear", "removes", "all", "objects", "from", "the", "Buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L96-L101
147,730
wcharczuk/go-chart
seq/buffer.go
Enqueue
func (b *Buffer) Enqueue(value float64) { if b.size == len(b.array) { newCapacity := int(len(b.array) * int(bufferGrowFactor/100)) if newCapacity < (len(b.array) + bufferMinimumGrow) { newCapacity = len(b.array) + bufferMinimumGrow } b.SetCapacity(newCapacity) } b.array[b.tail] = value b.tail = (b.tail + 1) % len(b.array) b.size++ }
go
func (b *Buffer) Enqueue(value float64) { if b.size == len(b.array) { newCapacity := int(len(b.array) * int(bufferGrowFactor/100)) if newCapacity < (len(b.array) + bufferMinimumGrow) { newCapacity = len(b.array) + bufferMinimumGrow } b.SetCapacity(newCapacity) } b.array[b.tail] = value b.tail = (b.tail + 1) % len(b.array) b.size++ }
[ "func", "(", "b", "*", "Buffer", ")", "Enqueue", "(", "value", "float64", ")", "{", "if", "b", ".", "size", "==", "len", "(", "b", ".", "array", ")", "{", "newCapacity", ":=", "int", "(", "len", "(", "b", ".", "array", ")", "*", "int", "(", "bufferGrowFactor", "/", "100", ")", ")", "\n", "if", "newCapacity", "<", "(", "len", "(", "b", ".", "array", ")", "+", "bufferMinimumGrow", ")", "{", "newCapacity", "=", "len", "(", "b", ".", "array", ")", "+", "bufferMinimumGrow", "\n", "}", "\n", "b", ".", "SetCapacity", "(", "newCapacity", ")", "\n", "}", "\n\n", "b", ".", "array", "[", "b", ".", "tail", "]", "=", "value", "\n", "b", ".", "tail", "=", "(", "b", ".", "tail", "+", "1", ")", "%", "len", "(", "b", ".", "array", ")", "\n", "b", ".", "size", "++", "\n", "}" ]
// Enqueue adds an element to the "back" of the Buffer.
[ "Enqueue", "adds", "an", "element", "to", "the", "back", "of", "the", "Buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L104-L116
147,731
wcharczuk/go-chart
seq/buffer.go
Dequeue
func (b *Buffer) Dequeue() float64 { if b.size == 0 { return 0 } removed := b.array[b.head] b.head = (b.head + 1) % len(b.array) b.size-- return removed }
go
func (b *Buffer) Dequeue() float64 { if b.size == 0 { return 0 } removed := b.array[b.head] b.head = (b.head + 1) % len(b.array) b.size-- return removed }
[ "func", "(", "b", "*", "Buffer", ")", "Dequeue", "(", ")", "float64", "{", "if", "b", ".", "size", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "removed", ":=", "b", ".", "array", "[", "b", ".", "head", "]", "\n", "b", ".", "head", "=", "(", "b", ".", "head", "+", "1", ")", "%", "len", "(", "b", ".", "array", ")", "\n", "b", ".", "size", "--", "\n", "return", "removed", "\n", "}" ]
// Dequeue removes the first element from the RingBuffer.
[ "Dequeue", "removes", "the", "first", "element", "from", "the", "RingBuffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L119-L128
147,732
wcharczuk/go-chart
seq/buffer.go
Peek
func (b *Buffer) Peek() float64 { if b.size == 0 { return 0 } return b.array[b.head] }
go
func (b *Buffer) Peek() float64 { if b.size == 0 { return 0 } return b.array[b.head] }
[ "func", "(", "b", "*", "Buffer", ")", "Peek", "(", ")", "float64", "{", "if", "b", ".", "size", "==", "0", "{", "return", "0", "\n", "}", "\n", "return", "b", ".", "array", "[", "b", ".", "head", "]", "\n", "}" ]
// Peek returns but does not remove the first element.
[ "Peek", "returns", "but", "does", "not", "remove", "the", "first", "element", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L131-L136
147,733
wcharczuk/go-chart
seq/buffer.go
PeekBack
func (b *Buffer) PeekBack() float64 { if b.size == 0 { return 0 } if b.tail == 0 { return b.array[len(b.array)-1] } return b.array[b.tail-1] }
go
func (b *Buffer) PeekBack() float64 { if b.size == 0 { return 0 } if b.tail == 0 { return b.array[len(b.array)-1] } return b.array[b.tail-1] }
[ "func", "(", "b", "*", "Buffer", ")", "PeekBack", "(", ")", "float64", "{", "if", "b", ".", "size", "==", "0", "{", "return", "0", "\n", "}", "\n", "if", "b", ".", "tail", "==", "0", "{", "return", "b", ".", "array", "[", "len", "(", "b", ".", "array", ")", "-", "1", "]", "\n", "}", "\n", "return", "b", ".", "array", "[", "b", ".", "tail", "-", "1", "]", "\n", "}" ]
// PeekBack returns but does not remove the last element.
[ "PeekBack", "returns", "but", "does", "not", "remove", "the", "last", "element", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L139-L147
147,734
wcharczuk/go-chart
seq/buffer.go
TrimExcess
func (b *Buffer) TrimExcess() { threshold := float64(len(b.array)) * 0.9 if b.size < int(threshold) { b.SetCapacity(b.size) } }
go
func (b *Buffer) TrimExcess() { threshold := float64(len(b.array)) * 0.9 if b.size < int(threshold) { b.SetCapacity(b.size) } }
[ "func", "(", "b", "*", "Buffer", ")", "TrimExcess", "(", ")", "{", "threshold", ":=", "float64", "(", "len", "(", "b", ".", "array", ")", ")", "*", "0.9", "\n", "if", "b", ".", "size", "<", "int", "(", "threshold", ")", "{", "b", ".", "SetCapacity", "(", "b", ".", "size", ")", "\n", "}", "\n", "}" ]
// TrimExcess resizes the capacity of the buffer to better fit the contents.
[ "TrimExcess", "resizes", "the", "capacity", "of", "the", "buffer", "to", "better", "fit", "the", "contents", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L150-L155
147,735
wcharczuk/go-chart
seq/buffer.go
Array
func (b *Buffer) Array() Array { newArray := make([]float64, b.size) if b.size == 0 { return newArray } if b.head < b.tail { arrayCopy(b.array, b.head, newArray, 0, b.size) } else { arrayCopy(b.array, b.head, newArray, 0, len(b.array)-b.head) arrayCopy(b.array, 0, newArray, len(b.array)-b.head, b.tail) } return Array(newArray) }
go
func (b *Buffer) Array() Array { newArray := make([]float64, b.size) if b.size == 0 { return newArray } if b.head < b.tail { arrayCopy(b.array, b.head, newArray, 0, b.size) } else { arrayCopy(b.array, b.head, newArray, 0, len(b.array)-b.head) arrayCopy(b.array, 0, newArray, len(b.array)-b.head, b.tail) } return Array(newArray) }
[ "func", "(", "b", "*", "Buffer", ")", "Array", "(", ")", "Array", "{", "newArray", ":=", "make", "(", "[", "]", "float64", ",", "b", ".", "size", ")", "\n\n", "if", "b", ".", "size", "==", "0", "{", "return", "newArray", "\n", "}", "\n\n", "if", "b", ".", "head", "<", "b", ".", "tail", "{", "arrayCopy", "(", "b", ".", "array", ",", "b", ".", "head", ",", "newArray", ",", "0", ",", "b", ".", "size", ")", "\n", "}", "else", "{", "arrayCopy", "(", "b", ".", "array", ",", "b", ".", "head", ",", "newArray", ",", "0", ",", "len", "(", "b", ".", "array", ")", "-", "b", ".", "head", ")", "\n", "arrayCopy", "(", "b", ".", "array", ",", "0", ",", "newArray", ",", "len", "(", "b", ".", "array", ")", "-", "b", ".", "head", ",", "b", ".", "tail", ")", "\n", "}", "\n\n", "return", "Array", "(", "newArray", ")", "\n", "}" ]
// Array returns the ring buffer, in order, as an array.
[ "Array", "returns", "the", "ring", "buffer", "in", "order", "as", "an", "array", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L158-L173
147,736
wcharczuk/go-chart
seq/buffer.go
Each
func (b *Buffer) Each(mapfn func(int, float64)) { if b.size == 0 { return } var index int if b.head < b.tail { for cursor := b.head; cursor < b.tail; cursor++ { mapfn(index, b.array[cursor]) index++ } } else { for cursor := b.head; cursor < len(b.array); cursor++ { mapfn(index, b.array[cursor]) index++ } for cursor := 0; cursor < b.tail; cursor++ { mapfn(index, b.array[cursor]) index++ } } }
go
func (b *Buffer) Each(mapfn func(int, float64)) { if b.size == 0 { return } var index int if b.head < b.tail { for cursor := b.head; cursor < b.tail; cursor++ { mapfn(index, b.array[cursor]) index++ } } else { for cursor := b.head; cursor < len(b.array); cursor++ { mapfn(index, b.array[cursor]) index++ } for cursor := 0; cursor < b.tail; cursor++ { mapfn(index, b.array[cursor]) index++ } } }
[ "func", "(", "b", "*", "Buffer", ")", "Each", "(", "mapfn", "func", "(", "int", ",", "float64", ")", ")", "{", "if", "b", ".", "size", "==", "0", "{", "return", "\n", "}", "\n\n", "var", "index", "int", "\n", "if", "b", ".", "head", "<", "b", ".", "tail", "{", "for", "cursor", ":=", "b", ".", "head", ";", "cursor", "<", "b", ".", "tail", ";", "cursor", "++", "{", "mapfn", "(", "index", ",", "b", ".", "array", "[", "cursor", "]", ")", "\n", "index", "++", "\n", "}", "\n", "}", "else", "{", "for", "cursor", ":=", "b", ".", "head", ";", "cursor", "<", "len", "(", "b", ".", "array", ")", ";", "cursor", "++", "{", "mapfn", "(", "index", ",", "b", ".", "array", "[", "cursor", "]", ")", "\n", "index", "++", "\n", "}", "\n", "for", "cursor", ":=", "0", ";", "cursor", "<", "b", ".", "tail", ";", "cursor", "++", "{", "mapfn", "(", "index", ",", "b", ".", "array", "[", "cursor", "]", ")", "\n", "index", "++", "\n", "}", "\n", "}", "\n", "}" ]
// Each calls the consumer for each element in the buffer.
[ "Each", "calls", "the", "consumer", "for", "each", "element", "in", "the", "buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L176-L197
147,737
wcharczuk/go-chart
seq/buffer.go
String
func (b *Buffer) String() string { var values []string for _, elem := range b.Array() { values = append(values, fmt.Sprintf("%v", elem)) } return strings.Join(values, " <= ") }
go
func (b *Buffer) String() string { var values []string for _, elem := range b.Array() { values = append(values, fmt.Sprintf("%v", elem)) } return strings.Join(values, " <= ") }
[ "func", "(", "b", "*", "Buffer", ")", "String", "(", ")", "string", "{", "var", "values", "[", "]", "string", "\n", "for", "_", ",", "elem", ":=", "range", "b", ".", "Array", "(", ")", "{", "values", "=", "append", "(", "values", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "elem", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "values", ",", "\"", "\"", ")", "\n", "}" ]
// String returns a string representation for value buffers.
[ "String", "returns", "a", "string", "representation", "for", "value", "buffers", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/buffer.go#L200-L206
147,738
wcharczuk/go-chart
drawing/stroker.go
NewLineStroker
func NewLineStroker(c LineCap, j LineJoin, flattener Flattener) *LineStroker { l := new(LineStroker) l.Flattener = flattener l.HalfLineWidth = 0.5 l.Cap = c l.Join = j return l }
go
func NewLineStroker(c LineCap, j LineJoin, flattener Flattener) *LineStroker { l := new(LineStroker) l.Flattener = flattener l.HalfLineWidth = 0.5 l.Cap = c l.Join = j return l }
[ "func", "NewLineStroker", "(", "c", "LineCap", ",", "j", "LineJoin", ",", "flattener", "Flattener", ")", "*", "LineStroker", "{", "l", ":=", "new", "(", "LineStroker", ")", "\n", "l", ".", "Flattener", "=", "flattener", "\n", "l", ".", "HalfLineWidth", "=", "0.5", "\n", "l", ".", "Cap", "=", "c", "\n", "l", ".", "Join", "=", "j", "\n", "return", "l", "\n", "}" ]
// NewLineStroker creates a new line stroker.
[ "NewLineStroker", "creates", "a", "new", "line", "stroker", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stroker.go#L7-L14
147,739
wcharczuk/go-chart
drawing/stroker.go
Close
func (l *LineStroker) Close() { if len(l.vertices) > 1 { l.appendVertex(l.vertices[0], l.vertices[1], l.rewind[0], l.rewind[1]) } }
go
func (l *LineStroker) Close() { if len(l.vertices) > 1 { l.appendVertex(l.vertices[0], l.vertices[1], l.rewind[0], l.rewind[1]) } }
[ "func", "(", "l", "*", "LineStroker", ")", "Close", "(", ")", "{", "if", "len", "(", "l", ".", "vertices", ")", ">", "1", "{", "l", ".", "appendVertex", "(", "l", ".", "vertices", "[", "0", "]", ",", "l", ".", "vertices", "[", "1", "]", ",", "l", ".", "rewind", "[", "0", "]", ",", "l", ".", "rewind", "[", "1", "]", ")", "\n", "}", "\n", "}" ]
// Close implements the path builder interface.
[ "Close", "implements", "the", "path", "builder", "interface", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stroker.go#L53-L57
147,740
wcharczuk/go-chart
drawing/stroker.go
End
func (l *LineStroker) End() { if len(l.vertices) > 1 { l.Flattener.MoveTo(l.vertices[0], l.vertices[1]) for i, j := 2, 3; j < len(l.vertices); i, j = i+2, j+2 { l.Flattener.LineTo(l.vertices[i], l.vertices[j]) } } for i, j := len(l.rewind)-2, len(l.rewind)-1; j > 0; i, j = i-2, j-2 { l.Flattener.LineTo(l.rewind[i], l.rewind[j]) } if len(l.vertices) > 1 { l.Flattener.LineTo(l.vertices[0], l.vertices[1]) } l.Flattener.End() // reinit vertices l.vertices = l.vertices[0:0] l.rewind = l.rewind[0:0] l.x, l.y, l.nx, l.ny = 0, 0, 0, 0 }
go
func (l *LineStroker) End() { if len(l.vertices) > 1 { l.Flattener.MoveTo(l.vertices[0], l.vertices[1]) for i, j := 2, 3; j < len(l.vertices); i, j = i+2, j+2 { l.Flattener.LineTo(l.vertices[i], l.vertices[j]) } } for i, j := len(l.rewind)-2, len(l.rewind)-1; j > 0; i, j = i-2, j-2 { l.Flattener.LineTo(l.rewind[i], l.rewind[j]) } if len(l.vertices) > 1 { l.Flattener.LineTo(l.vertices[0], l.vertices[1]) } l.Flattener.End() // reinit vertices l.vertices = l.vertices[0:0] l.rewind = l.rewind[0:0] l.x, l.y, l.nx, l.ny = 0, 0, 0, 0 }
[ "func", "(", "l", "*", "LineStroker", ")", "End", "(", ")", "{", "if", "len", "(", "l", ".", "vertices", ")", ">", "1", "{", "l", ".", "Flattener", ".", "MoveTo", "(", "l", ".", "vertices", "[", "0", "]", ",", "l", ".", "vertices", "[", "1", "]", ")", "\n", "for", "i", ",", "j", ":=", "2", ",", "3", ";", "j", "<", "len", "(", "l", ".", "vertices", ")", ";", "i", ",", "j", "=", "i", "+", "2", ",", "j", "+", "2", "{", "l", ".", "Flattener", ".", "LineTo", "(", "l", ".", "vertices", "[", "i", "]", ",", "l", ".", "vertices", "[", "j", "]", ")", "\n", "}", "\n", "}", "\n", "for", "i", ",", "j", ":=", "len", "(", "l", ".", "rewind", ")", "-", "2", ",", "len", "(", "l", ".", "rewind", ")", "-", "1", ";", "j", ">", "0", ";", "i", ",", "j", "=", "i", "-", "2", ",", "j", "-", "2", "{", "l", ".", "Flattener", ".", "LineTo", "(", "l", ".", "rewind", "[", "i", "]", ",", "l", ".", "rewind", "[", "j", "]", ")", "\n", "}", "\n", "if", "len", "(", "l", ".", "vertices", ")", ">", "1", "{", "l", ".", "Flattener", ".", "LineTo", "(", "l", ".", "vertices", "[", "0", "]", ",", "l", ".", "vertices", "[", "1", "]", ")", "\n", "}", "\n", "l", ".", "Flattener", ".", "End", "(", ")", "\n", "// reinit vertices", "l", ".", "vertices", "=", "l", ".", "vertices", "[", "0", ":", "0", "]", "\n", "l", ".", "rewind", "=", "l", ".", "rewind", "[", "0", ":", "0", "]", "\n", "l", ".", "x", ",", "l", ".", "y", ",", "l", ".", "nx", ",", "l", ".", "ny", "=", "0", ",", "0", ",", "0", ",", "0", "\n\n", "}" ]
// End implements the path builder interface.
[ "End", "implements", "the", "path", "builder", "interface", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/stroker.go#L60-L79
147,741
wcharczuk/go-chart
viridis.go
Viridis
func Viridis(v, vmin, vmax float64) drawing.Color { normalized := (v - vmin) / (vmax - vmin) index := uint8(normalized * 255) return viridisColors[index] }
go
func Viridis(v, vmin, vmax float64) drawing.Color { normalized := (v - vmin) / (vmax - vmin) index := uint8(normalized * 255) return viridisColors[index] }
[ "func", "Viridis", "(", "v", ",", "vmin", ",", "vmax", "float64", ")", "drawing", ".", "Color", "{", "normalized", ":=", "(", "v", "-", "vmin", ")", "/", "(", "vmax", "-", "vmin", ")", "\n", "index", ":=", "uint8", "(", "normalized", "*", "255", ")", "\n", "return", "viridisColors", "[", "index", "]", "\n", "}" ]
// Viridis creates a color map provider.
[ "Viridis", "creates", "a", "color", "map", "provider", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/viridis.go#L265-L269
147,742
go-resty/resty
client.go
R
func (c *Client) R() *Request { r := &Request{ QueryParam: url.Values{}, FormData: url.Values{}, Header: http.Header{}, client: c, multipartFiles: []*File{}, multipartFields: []*MultipartField{}, pathParams: map[string]string{}, jsonEscapeHTML: true, } return r }
go
func (c *Client) R() *Request { r := &Request{ QueryParam: url.Values{}, FormData: url.Values{}, Header: http.Header{}, client: c, multipartFiles: []*File{}, multipartFields: []*MultipartField{}, pathParams: map[string]string{}, jsonEscapeHTML: true, } return r }
[ "func", "(", "c", "*", "Client", ")", "R", "(", ")", "*", "Request", "{", "r", ":=", "&", "Request", "{", "QueryParam", ":", "url", ".", "Values", "{", "}", ",", "FormData", ":", "url", ".", "Values", "{", "}", ",", "Header", ":", "http", ".", "Header", "{", "}", ",", "client", ":", "c", ",", "multipartFiles", ":", "[", "]", "*", "File", "{", "}", ",", "multipartFields", ":", "[", "]", "*", "MultipartField", "{", "}", ",", "pathParams", ":", "map", "[", "string", "]", "string", "{", "}", ",", "jsonEscapeHTML", ":", "true", ",", "}", "\n\n", "return", "r", "\n", "}" ]
// R method creates a request instance, its used for Get, Post, Put, Delete, Patch, Head and Options.
[ "R", "method", "creates", "a", "request", "instance", "its", "used", "for", "Get", "Post", "Put", "Delete", "Patch", "Head", "and", "Options", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L306-L320
147,743
go-resty/resty
client.go
OnRequestLog
func (c *Client) OnRequestLog(rl func(*RequestLog) error) *Client { if c.requestLog != nil { c.Log.Printf("Overwriting an existing on-request-log callback from=%s to=%s", functionName(c.requestLog), functionName(rl)) } c.requestLog = rl return c }
go
func (c *Client) OnRequestLog(rl func(*RequestLog) error) *Client { if c.requestLog != nil { c.Log.Printf("Overwriting an existing on-request-log callback from=%s to=%s", functionName(c.requestLog), functionName(rl)) } c.requestLog = rl return c }
[ "func", "(", "c", "*", "Client", ")", "OnRequestLog", "(", "rl", "func", "(", "*", "RequestLog", ")", "error", ")", "*", "Client", "{", "if", "c", ".", "requestLog", "!=", "nil", "{", "c", ".", "Log", ".", "Printf", "(", "\"", "\"", ",", "functionName", "(", "c", ".", "requestLog", ")", ",", "functionName", "(", "rl", ")", ")", "\n", "}", "\n", "c", ".", "requestLog", "=", "rl", "\n", "return", "c", "\n", "}" ]
// OnRequestLog method used to set request log callback into resty. Registered callback gets // called before the resty actually logs the information.
[ "OnRequestLog", "method", "used", "to", "set", "request", "log", "callback", "into", "resty", ".", "Registered", "callback", "gets", "called", "before", "the", "resty", "actually", "logs", "the", "information", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L390-L396
147,744
go-resty/resty
client.go
OnResponseLog
func (c *Client) OnResponseLog(rl func(*ResponseLog) error) *Client { if c.responseLog != nil { c.Log.Printf("Overwriting an existing on-response-log callback from=%s to=%s", functionName(c.responseLog), functionName(rl)) } c.responseLog = rl return c }
go
func (c *Client) OnResponseLog(rl func(*ResponseLog) error) *Client { if c.responseLog != nil { c.Log.Printf("Overwriting an existing on-response-log callback from=%s to=%s", functionName(c.responseLog), functionName(rl)) } c.responseLog = rl return c }
[ "func", "(", "c", "*", "Client", ")", "OnResponseLog", "(", "rl", "func", "(", "*", "ResponseLog", ")", "error", ")", "*", "Client", "{", "if", "c", ".", "responseLog", "!=", "nil", "{", "c", ".", "Log", ".", "Printf", "(", "\"", "\"", ",", "functionName", "(", "c", ".", "responseLog", ")", ",", "functionName", "(", "rl", ")", ")", "\n", "}", "\n", "c", ".", "responseLog", "=", "rl", "\n", "return", "c", "\n", "}" ]
// OnResponseLog method used to set response log callback into resty. Registered callback gets // called before the resty actually logs the information.
[ "OnResponseLog", "method", "used", "to", "set", "response", "log", "callback", "into", "resty", ".", "Registered", "callback", "gets", "called", "before", "the", "resty", "actually", "logs", "the", "information", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L400-L406
147,745
go-resty/resty
client.go
SetRetryCount
func (c *Client) SetRetryCount(count int) *Client { c.RetryCount = count return c }
go
func (c *Client) SetRetryCount(count int) *Client { c.RetryCount = count return c }
[ "func", "(", "c", "*", "Client", ")", "SetRetryCount", "(", "count", "int", ")", "*", "Client", "{", "c", ".", "RetryCount", "=", "count", "\n", "return", "c", "\n", "}" ]
// SetRetryCount method enables retry on `go-resty` client and allows you // to set no. of retry count. Resty uses a Backoff mechanism.
[ "SetRetryCount", "method", "enables", "retry", "on", "go", "-", "resty", "client", "and", "allows", "you", "to", "set", "no", ".", "of", "retry", "count", ".", "Resty", "uses", "a", "Backoff", "mechanism", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L498-L501
147,746
go-resty/resty
client.go
SetRetryWaitTime
func (c *Client) SetRetryWaitTime(waitTime time.Duration) *Client { c.RetryWaitTime = waitTime return c }
go
func (c *Client) SetRetryWaitTime(waitTime time.Duration) *Client { c.RetryWaitTime = waitTime return c }
[ "func", "(", "c", "*", "Client", ")", "SetRetryWaitTime", "(", "waitTime", "time", ".", "Duration", ")", "*", "Client", "{", "c", ".", "RetryWaitTime", "=", "waitTime", "\n", "return", "c", "\n", "}" ]
// SetRetryWaitTime method sets default wait time to sleep before retrying // request. // Default is 100 milliseconds.
[ "SetRetryWaitTime", "method", "sets", "default", "wait", "time", "to", "sleep", "before", "retrying", "request", ".", "Default", "is", "100", "milliseconds", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L506-L509
147,747
go-resty/resty
client.go
SetRetryMaxWaitTime
func (c *Client) SetRetryMaxWaitTime(maxWaitTime time.Duration) *Client { c.RetryMaxWaitTime = maxWaitTime return c }
go
func (c *Client) SetRetryMaxWaitTime(maxWaitTime time.Duration) *Client { c.RetryMaxWaitTime = maxWaitTime return c }
[ "func", "(", "c", "*", "Client", ")", "SetRetryMaxWaitTime", "(", "maxWaitTime", "time", ".", "Duration", ")", "*", "Client", "{", "c", ".", "RetryMaxWaitTime", "=", "maxWaitTime", "\n", "return", "c", "\n", "}" ]
// SetRetryMaxWaitTime method sets max wait time to sleep before retrying // request. // Default is 2 seconds.
[ "SetRetryMaxWaitTime", "method", "sets", "max", "wait", "time", "to", "sleep", "before", "retrying", "request", ".", "Default", "is", "2", "seconds", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L514-L517
147,748
go-resty/resty
client.go
AddRetryCondition
func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client { c.RetryConditions = append(c.RetryConditions, condition) return c }
go
func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client { c.RetryConditions = append(c.RetryConditions, condition) return c }
[ "func", "(", "c", "*", "Client", ")", "AddRetryCondition", "(", "condition", "RetryConditionFunc", ")", "*", "Client", "{", "c", ".", "RetryConditions", "=", "append", "(", "c", ".", "RetryConditions", ",", "condition", ")", "\n", "return", "c", "\n", "}" ]
// AddRetryCondition method adds a retry condition function to array of functions // that are checked to determine if the request is retried. The request will // retry if any of the functions return true and error is nil.
[ "AddRetryCondition", "method", "adds", "a", "retry", "condition", "function", "to", "array", "of", "functions", "that", "are", "checked", "to", "determine", "if", "the", "request", "is", "retried", ".", "The", "request", "will", "retry", "if", "any", "of", "the", "functions", "return", "true", "and", "error", "is", "nil", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L522-L525
147,749
go-resty/resty
client.go
SetCertificates
func (c *Client) SetCertificates(certs ...tls.Certificate) *Client { config, err := c.getTLSConfig() if err != nil { c.Log.Printf("ERROR %v", err) return c } config.Certificates = append(config.Certificates, certs...) return c }
go
func (c *Client) SetCertificates(certs ...tls.Certificate) *Client { config, err := c.getTLSConfig() if err != nil { c.Log.Printf("ERROR %v", err) return c } config.Certificates = append(config.Certificates, certs...) return c }
[ "func", "(", "c", "*", "Client", ")", "SetCertificates", "(", "certs", "...", "tls", ".", "Certificate", ")", "*", "Client", "{", "config", ",", "err", ":=", "c", ".", "getTLSConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "c", ".", "Log", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "c", "\n", "}", "\n", "config", ".", "Certificates", "=", "append", "(", "config", ".", "Certificates", ",", "certs", "...", ")", "\n", "return", "c", "\n", "}" ]
// SetCertificates method helps to set client certificates into resty conveniently. //
[ "SetCertificates", "method", "helps", "to", "set", "client", "certificates", "into", "resty", "conveniently", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L639-L647
147,750
go-resty/resty
client.go
SetLogPrefix
func (c *Client) SetLogPrefix(prefix string) *Client { c.logPrefix = prefix c.Log.SetPrefix(prefix) return c }
go
func (c *Client) SetLogPrefix(prefix string) *Client { c.logPrefix = prefix c.Log.SetPrefix(prefix) return c }
[ "func", "(", "c", "*", "Client", ")", "SetLogPrefix", "(", "prefix", "string", ")", "*", "Client", "{", "c", ".", "logPrefix", "=", "prefix", "\n", "c", ".", "Log", ".", "SetPrefix", "(", "prefix", ")", "\n", "return", "c", "\n", "}" ]
// SetLogPrefix method sets the Resty logger prefix value.
[ "SetLogPrefix", "method", "sets", "the", "Resty", "logger", "prefix", "value", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L739-L743
147,751
go-resty/resty
client.go
enableLogPrefix
func (c *Client) enableLogPrefix() { c.Log.SetFlags(log.LstdFlags) c.Log.SetPrefix(c.logPrefix) }
go
func (c *Client) enableLogPrefix() { c.Log.SetFlags(log.LstdFlags) c.Log.SetPrefix(c.logPrefix) }
[ "func", "(", "c", "*", "Client", ")", "enableLogPrefix", "(", ")", "{", "c", ".", "Log", ".", "SetFlags", "(", "log", ".", "LstdFlags", ")", "\n", "c", ".", "Log", ".", "SetPrefix", "(", "c", ".", "logPrefix", ")", "\n", "}" ]
// enables a log prefix
[ "enables", "a", "log", "prefix" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L868-L871
147,752
go-resty/resty
client.go
getTLSConfig
func (c *Client) getTLSConfig() (*tls.Config, error) { transport, err := c.getTransport() if err != nil { return nil, err } if transport.TLSClientConfig == nil { transport.TLSClientConfig = &tls.Config{} } return transport.TLSClientConfig, nil }
go
func (c *Client) getTLSConfig() (*tls.Config, error) { transport, err := c.getTransport() if err != nil { return nil, err } if transport.TLSClientConfig == nil { transport.TLSClientConfig = &tls.Config{} } return transport.TLSClientConfig, nil }
[ "func", "(", "c", "*", "Client", ")", "getTLSConfig", "(", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "transport", ",", "err", ":=", "c", ".", "getTransport", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "transport", ".", "TLSClientConfig", "==", "nil", "{", "transport", ".", "TLSClientConfig", "=", "&", "tls", ".", "Config", "{", "}", "\n", "}", "\n", "return", "transport", ".", "TLSClientConfig", ",", "nil", "\n", "}" ]
// getting TLS client config if not exists then create one
[ "getting", "TLS", "client", "config", "if", "not", "exists", "then", "create", "one" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L880-L889
147,753
go-resty/resty
client.go
String
func (f *File) String() string { return fmt.Sprintf("ParamName: %v; FileName: %v", f.ParamName, f.Name) }
go
func (f *File) String() string { return fmt.Sprintf("ParamName: %v; FileName: %v", f.ParamName, f.Name) }
[ "func", "(", "f", "*", "File", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "ParamName", ",", "f", ".", "Name", ")", "\n", "}" ]
// String returns string value of current file details
[ "String", "returns", "string", "value", "of", "current", "file", "details" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/client.go#L916-L918
147,754
go-resty/resty
util.go
DetectContentType
func DetectContentType(body interface{}) string { contentType := plainTextType kind := kindOf(body) switch kind { case reflect.Struct, reflect.Map: contentType = jsonContentType case reflect.String: contentType = plainTextType default: if b, ok := body.([]byte); ok { contentType = http.DetectContentType(b) } else if kind == reflect.Slice { contentType = jsonContentType } } return contentType }
go
func DetectContentType(body interface{}) string { contentType := plainTextType kind := kindOf(body) switch kind { case reflect.Struct, reflect.Map: contentType = jsonContentType case reflect.String: contentType = plainTextType default: if b, ok := body.([]byte); ok { contentType = http.DetectContentType(b) } else if kind == reflect.Slice { contentType = jsonContentType } } return contentType }
[ "func", "DetectContentType", "(", "body", "interface", "{", "}", ")", "string", "{", "contentType", ":=", "plainTextType", "\n", "kind", ":=", "kindOf", "(", "body", ")", "\n", "switch", "kind", "{", "case", "reflect", ".", "Struct", ",", "reflect", ".", "Map", ":", "contentType", "=", "jsonContentType", "\n", "case", "reflect", ".", "String", ":", "contentType", "=", "plainTextType", "\n", "default", ":", "if", "b", ",", "ok", ":=", "body", ".", "(", "[", "]", "byte", ")", ";", "ok", "{", "contentType", "=", "http", ".", "DetectContentType", "(", "b", ")", "\n", "}", "else", "if", "kind", "==", "reflect", ".", "Slice", "{", "contentType", "=", "jsonContentType", "\n", "}", "\n", "}", "\n\n", "return", "contentType", "\n", "}" ]
// DetectContentType method is used to figure out `Request.Body` content type for request header
[ "DetectContentType", "method", "is", "used", "to", "figure", "out", "Request", ".", "Body", "content", "type", "for", "request", "header" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/util.go#L35-L52
147,755
go-resty/resty
util.go
Unmarshalc
func Unmarshalc(c *Client, ct string, b []byte, d interface{}) (err error) { if IsJSONType(ct) { err = c.JSONUnmarshal(b, d) } else if IsXMLType(ct) { err = xml.Unmarshal(b, d) } return }
go
func Unmarshalc(c *Client, ct string, b []byte, d interface{}) (err error) { if IsJSONType(ct) { err = c.JSONUnmarshal(b, d) } else if IsXMLType(ct) { err = xml.Unmarshal(b, d) } return }
[ "func", "Unmarshalc", "(", "c", "*", "Client", ",", "ct", "string", ",", "b", "[", "]", "byte", ",", "d", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "if", "IsJSONType", "(", "ct", ")", "{", "err", "=", "c", ".", "JSONUnmarshal", "(", "b", ",", "d", ")", "\n", "}", "else", "if", "IsXMLType", "(", "ct", ")", "{", "err", "=", "xml", ".", "Unmarshal", "(", "b", ",", "d", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Unmarshalc content into object from JSON or XML
[ "Unmarshalc", "content", "into", "object", "from", "JSON", "or", "XML" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/util.go#L77-L85
147,756
go-resty/resty
default.go
New
func New() *Client { cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) return createClient(&http.Client{Jar: cookieJar}) }
go
func New() *Client { cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) return createClient(&http.Client{Jar: cookieJar}) }
[ "func", "New", "(", ")", "*", "Client", "{", "cookieJar", ",", "_", ":=", "cookiejar", ".", "New", "(", "&", "cookiejar", ".", "Options", "{", "PublicSuffixList", ":", "publicsuffix", ".", "List", "}", ")", "\n", "return", "createClient", "(", "&", "http", ".", "Client", "{", "Jar", ":", "cookieJar", "}", ")", "\n", "}" ]
// New method creates a new go-resty client.
[ "New", "method", "creates", "a", "new", "go", "-", "resty", "client", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/default.go#L25-L28
147,757
go-resty/resty
request.go
SetMultipartField
func (r *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader) *Request { r.isMultiPart = true r.multipartFields = append(r.multipartFields, &MultipartField{ Param: param, FileName: fileName, ContentType: contentType, Reader: reader, }) return r }
go
func (r *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader) *Request { r.isMultiPart = true r.multipartFields = append(r.multipartFields, &MultipartField{ Param: param, FileName: fileName, ContentType: contentType, Reader: reader, }) return r }
[ "func", "(", "r", "*", "Request", ")", "SetMultipartField", "(", "param", ",", "fileName", ",", "contentType", "string", ",", "reader", "io", ".", "Reader", ")", "*", "Request", "{", "r", ".", "isMultiPart", "=", "true", "\n", "r", ".", "multipartFields", "=", "append", "(", "r", ".", "multipartFields", ",", "&", "MultipartField", "{", "Param", ":", "param", ",", "FileName", ":", "fileName", ",", "ContentType", ":", "contentType", ",", "Reader", ":", "reader", ",", "}", ")", "\n", "return", "r", "\n", "}" ]
// SetMultipartField method is to set custom data using io.Reader for multipart upload.
[ "SetMultipartField", "method", "is", "to", "set", "custom", "data", "using", "io", ".", "Reader", "for", "multipart", "upload", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L284-L293
147,758
go-resty/resty
request.go
ExpectContentType
func (r *Request) ExpectContentType(contentType string) *Request { r.fallbackContentType = contentType return r }
go
func (r *Request) ExpectContentType(contentType string) *Request { r.fallbackContentType = contentType return r }
[ "func", "(", "r", "*", "Request", ")", "ExpectContentType", "(", "contentType", "string", ")", "*", "Request", "{", "r", ".", "fallbackContentType", "=", "contentType", "\n", "return", "r", "\n", "}" ]
// ExpectContentType method allows to provide fallback `Content-Type` for automatic unmarshalling // when `Content-Type` response header is unavailable.
[ "ExpectContentType", "method", "allows", "to", "provide", "fallback", "Content", "-", "Type", "for", "automatic", "unmarshalling", "when", "Content", "-", "Type", "response", "header", "is", "unavailable", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L414-L417
147,759
go-resty/resty
request.go
Head
func (r *Request) Head(url string) (*Response, error) { return r.Execute(MethodHead, url) }
go
func (r *Request) Head(url string) (*Response, error) { return r.Execute(MethodHead, url) }
[ "func", "(", "r", "*", "Request", ")", "Head", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodHead", ",", "url", ")", "\n", "}" ]
// Head method does HEAD HTTP request. It's defined in section 4.3.2 of RFC7231.
[ "Head", "method", "does", "HEAD", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "4", ".", "3", ".", "2", "of", "RFC7231", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L437-L439
147,760
go-resty/resty
request.go
Post
func (r *Request) Post(url string) (*Response, error) { return r.Execute(MethodPost, url) }
go
func (r *Request) Post(url string) (*Response, error) { return r.Execute(MethodPost, url) }
[ "func", "(", "r", "*", "Request", ")", "Post", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodPost", ",", "url", ")", "\n", "}" ]
// Post method does POST HTTP request. It's defined in section 4.3.3 of RFC7231.
[ "Post", "method", "does", "POST", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "4", ".", "3", ".", "3", "of", "RFC7231", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L442-L444
147,761
go-resty/resty
request.go
Put
func (r *Request) Put(url string) (*Response, error) { return r.Execute(MethodPut, url) }
go
func (r *Request) Put(url string) (*Response, error) { return r.Execute(MethodPut, url) }
[ "func", "(", "r", "*", "Request", ")", "Put", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodPut", ",", "url", ")", "\n", "}" ]
// Put method does PUT HTTP request. It's defined in section 4.3.4 of RFC7231.
[ "Put", "method", "does", "PUT", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "4", ".", "3", ".", "4", "of", "RFC7231", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L447-L449
147,762
go-resty/resty
request.go
Delete
func (r *Request) Delete(url string) (*Response, error) { return r.Execute(MethodDelete, url) }
go
func (r *Request) Delete(url string) (*Response, error) { return r.Execute(MethodDelete, url) }
[ "func", "(", "r", "*", "Request", ")", "Delete", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodDelete", ",", "url", ")", "\n", "}" ]
// Delete method does DELETE HTTP request. It's defined in section 4.3.5 of RFC7231.
[ "Delete", "method", "does", "DELETE", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "4", ".", "3", ".", "5", "of", "RFC7231", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L452-L454
147,763
go-resty/resty
request.go
Options
func (r *Request) Options(url string) (*Response, error) { return r.Execute(MethodOptions, url) }
go
func (r *Request) Options(url string) (*Response, error) { return r.Execute(MethodOptions, url) }
[ "func", "(", "r", "*", "Request", ")", "Options", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodOptions", ",", "url", ")", "\n", "}" ]
// Options method does OPTIONS HTTP request. It's defined in section 4.3.7 of RFC7231.
[ "Options", "method", "does", "OPTIONS", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "4", ".", "3", ".", "7", "of", "RFC7231", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L457-L459
147,764
go-resty/resty
request.go
Patch
func (r *Request) Patch(url string) (*Response, error) { return r.Execute(MethodPatch, url) }
go
func (r *Request) Patch(url string) (*Response, error) { return r.Execute(MethodPatch, url) }
[ "func", "(", "r", "*", "Request", ")", "Patch", "(", "url", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "r", ".", "Execute", "(", "MethodPatch", ",", "url", ")", "\n", "}" ]
// Patch method does PATCH HTTP request. It's defined in section 2 of RFC5789.
[ "Patch", "method", "does", "PATCH", "HTTP", "request", ".", "It", "s", "defined", "in", "section", "2", "of", "RFC5789", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/request.go#L462-L464
147,765
go-resty/resty
response.go
Header
func (r *Response) Header() http.Header { if r.RawResponse == nil { return http.Header{} } return r.RawResponse.Header }
go
func (r *Response) Header() http.Header { if r.RawResponse == nil { return http.Header{} } return r.RawResponse.Header }
[ "func", "(", "r", "*", "Response", ")", "Header", "(", ")", "http", ".", "Header", "{", "if", "r", ".", "RawResponse", "==", "nil", "{", "return", "http", ".", "Header", "{", "}", "\n", "}", "\n\n", "return", "r", ".", "RawResponse", ".", "Header", "\n", "}" ]
// Header method returns the response headers
[ "Header", "method", "returns", "the", "response", "headers" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/response.go#L66-L72
147,766
go-resty/resty
response.go
Cookies
func (r *Response) Cookies() []*http.Cookie { if r.RawResponse == nil { return make([]*http.Cookie, 0) } return r.RawResponse.Cookies() }
go
func (r *Response) Cookies() []*http.Cookie { if r.RawResponse == nil { return make([]*http.Cookie, 0) } return r.RawResponse.Cookies() }
[ "func", "(", "r", "*", "Response", ")", "Cookies", "(", ")", "[", "]", "*", "http", ".", "Cookie", "{", "if", "r", ".", "RawResponse", "==", "nil", "{", "return", "make", "(", "[", "]", "*", "http", ".", "Cookie", ",", "0", ")", "\n", "}", "\n\n", "return", "r", ".", "RawResponse", ".", "Cookies", "(", ")", "\n", "}" ]
// Cookies method to access all the response cookies
[ "Cookies", "method", "to", "access", "all", "the", "response", "cookies" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/response.go#L75-L81
147,767
go-resty/resty
response.go
String
func (r *Response) String() string { if r.body == nil { return "" } return strings.TrimSpace(string(r.body)) }
go
func (r *Response) String() string { if r.body == nil { return "" } return strings.TrimSpace(string(r.body)) }
[ "func", "(", "r", "*", "Response", ")", "String", "(", ")", "string", "{", "if", "r", ".", "body", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "strings", ".", "TrimSpace", "(", "string", "(", "r", ".", "body", ")", ")", "\n", "}" ]
// String method returns the body of the server response as String.
[ "String", "method", "returns", "the", "body", "of", "the", "server", "response", "as", "String", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/response.go#L84-L90
147,768
go-resty/resty
response.go
Time
func (r *Response) Time() time.Duration { return r.receivedAt.Sub(r.Request.Time) }
go
func (r *Response) Time() time.Duration { return r.receivedAt.Sub(r.Request.Time) }
[ "func", "(", "r", "*", "Response", ")", "Time", "(", ")", "time", ".", "Duration", "{", "return", "r", ".", "receivedAt", ".", "Sub", "(", "r", ".", "Request", ".", "Time", ")", "\n", "}" ]
// Time method returns the time of HTTP response time that from request we sent and received a request. // See `response.ReceivedAt` to know when client recevied response and see `response.Request.Time` to know // when client sent a request.
[ "Time", "method", "returns", "the", "time", "of", "HTTP", "response", "time", "that", "from", "request", "we", "sent", "and", "received", "a", "request", ".", "See", "response", ".", "ReceivedAt", "to", "know", "when", "client", "recevied", "response", "and", "see", "response", ".", "Request", ".", "Time", "to", "know", "when", "client", "sent", "a", "request", "." ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/response.go#L95-L97
147,769
go-resty/resty
retry.go
WaitTime
func WaitTime(value time.Duration) Option { return func(o *Options) { o.waitTime = value } }
go
func WaitTime(value time.Duration) Option { return func(o *Options) { o.waitTime = value } }
[ "func", "WaitTime", "(", "value", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "{", "o", ".", "waitTime", "=", "value", "\n", "}", "\n", "}" ]
// WaitTime sets the default wait time to sleep between requests
[ "WaitTime", "sets", "the", "default", "wait", "time", "to", "sleep", "between", "requests" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/retry.go#L43-L47
147,770
go-resty/resty
retry.go
MaxWaitTime
func MaxWaitTime(value time.Duration) Option { return func(o *Options) { o.maxWaitTime = value } }
go
func MaxWaitTime(value time.Duration) Option { return func(o *Options) { o.maxWaitTime = value } }
[ "func", "MaxWaitTime", "(", "value", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "{", "o", ".", "maxWaitTime", "=", "value", "\n", "}", "\n", "}" ]
// MaxWaitTime sets the max wait time to sleep between requests
[ "MaxWaitTime", "sets", "the", "max", "wait", "time", "to", "sleep", "between", "requests" ]
fa5875c0caa5c260ab78acec5a244215a730247f
https://github.com/go-resty/resty/blob/fa5875c0caa5c260ab78acec5a244215a730247f/retry.go#L50-L54
147,771
nsf/gocode
_goremote/goremote.go
generate_server_rpc_wrapper
func generate_server_rpc_wrapper(out io.Writer, fun *ast.FuncDecl, name string, argcnt, replycnt int) { fmt.Fprintf(out, "func (r *RPC) RPC_%s(args *Args_%s, reply *Reply_%s) error {\n", name, name, name) fmt.Fprintf(out, "\t") for i := 0; i < replycnt; i++ { fmt.Fprintf(out, "reply.Arg%d", i) if i != replycnt-1 { fmt.Fprintf(out, ", ") } } fmt.Fprintf(out, " = %s(", fun.Name.Name) for i := 0; i < argcnt; i++ { fmt.Fprintf(out, "args.Arg%d", i) if i != argcnt-1 { fmt.Fprintf(out, ", ") } } fmt.Fprintf(out, ")\n") fmt.Fprintf(out, "\treturn nil\n}\n") }
go
func generate_server_rpc_wrapper(out io.Writer, fun *ast.FuncDecl, name string, argcnt, replycnt int) { fmt.Fprintf(out, "func (r *RPC) RPC_%s(args *Args_%s, reply *Reply_%s) error {\n", name, name, name) fmt.Fprintf(out, "\t") for i := 0; i < replycnt; i++ { fmt.Fprintf(out, "reply.Arg%d", i) if i != replycnt-1 { fmt.Fprintf(out, ", ") } } fmt.Fprintf(out, " = %s(", fun.Name.Name) for i := 0; i < argcnt; i++ { fmt.Fprintf(out, "args.Arg%d", i) if i != argcnt-1 { fmt.Fprintf(out, ", ") } } fmt.Fprintf(out, ")\n") fmt.Fprintf(out, "\treturn nil\n}\n") }
[ "func", "generate_server_rpc_wrapper", "(", "out", "io", ".", "Writer", ",", "fun", "*", "ast", ".", "FuncDecl", ",", "name", "string", ",", "argcnt", ",", "replycnt", "int", ")", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\\n", "\"", ",", "name", ",", "name", ",", "name", ")", "\n\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\\t", "\"", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "replycnt", ";", "i", "++", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "i", ")", "\n", "if", "i", "!=", "replycnt", "-", "1", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "fun", ".", "Name", ".", "Name", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "argcnt", ";", "i", "++", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "i", ")", "\n", "if", "i", "!=", "argcnt", "-", "1", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\\n", "\"", ")", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\\t", "\\n", "\\n", "\"", ")", "\n", "}" ]
// function that is being exposed to an RPC API, but calls simple "Server_" one
[ "function", "that", "is", "being", "exposed", "to", "an", "RPC", "API", "but", "calls", "simple", "Server_", "one" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_goremote/goremote.go#L154-L174
147,772
nsf/gocode
_gccgo/package.go
expect
func (this *import_data_parser) expect(x rune) string { if x == scanner.Ident { // special case, in gccgo import data identifier is not exactly a scanner.Ident return this.read_ident() } if x == scanner.Int { // another special case, handle negative ints as well return this.read_int() } if this.toktype != x { this.errorf("expected: %s, got: %s", scanner.TokenString(x), scanner.TokenString(this.toktype)) } tok := this.token() this.next() return tok }
go
func (this *import_data_parser) expect(x rune) string { if x == scanner.Ident { // special case, in gccgo import data identifier is not exactly a scanner.Ident return this.read_ident() } if x == scanner.Int { // another special case, handle negative ints as well return this.read_int() } if this.toktype != x { this.errorf("expected: %s, got: %s", scanner.TokenString(x), scanner.TokenString(this.toktype)) } tok := this.token() this.next() return tok }
[ "func", "(", "this", "*", "import_data_parser", ")", "expect", "(", "x", "rune", ")", "string", "{", "if", "x", "==", "scanner", ".", "Ident", "{", "// special case, in gccgo import data identifier is not exactly a scanner.Ident", "return", "this", ".", "read_ident", "(", ")", "\n", "}", "\n\n", "if", "x", "==", "scanner", ".", "Int", "{", "// another special case, handle negative ints as well", "return", "this", ".", "read_int", "(", ")", "\n", "}", "\n\n", "if", "this", ".", "toktype", "!=", "x", "{", "this", ".", "errorf", "(", "\"", "\"", ",", "scanner", ".", "TokenString", "(", "x", ")", ",", "scanner", ".", "TokenString", "(", "this", ".", "toktype", ")", ")", "\n", "}", "\n\n", "tok", ":=", "this", ".", "token", "(", ")", "\n", "this", ".", "next", "(", ")", "\n", "return", "tok", "\n", "}" ]
// makes sure that the current token is 'x', returns it and reads the next one
[ "makes", "sure", "that", "the", "current", "token", "is", "x", "returns", "it", "and", "reads", "the", "next", "one" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_gccgo/package.go#L215-L233
147,773
nsf/gocode
_gccgo/package.go
expect_special
func (this *import_data_parser) expect_special(special string) { i := 0 for i < len(special) { if this.toktype != rune(special[i]) { break } this.next() i++ } if i < len(special) { this.errorf("expected: \"%s\", got something else", special) } }
go
func (this *import_data_parser) expect_special(special string) { i := 0 for i < len(special) { if this.toktype != rune(special[i]) { break } this.next() i++ } if i < len(special) { this.errorf("expected: \"%s\", got something else", special) } }
[ "func", "(", "this", "*", "import_data_parser", ")", "expect_special", "(", "special", "string", ")", "{", "i", ":=", "0", "\n", "for", "i", "<", "len", "(", "special", ")", "{", "if", "this", ".", "toktype", "!=", "rune", "(", "special", "[", "i", "]", ")", "{", "break", "\n", "}", "\n\n", "this", ".", "next", "(", ")", "\n", "i", "++", "\n", "}", "\n\n", "if", "i", "<", "len", "(", "special", ")", "{", "this", ".", "errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "special", ")", "\n", "}", "\n", "}" ]
// makes sure that the following set of tokens matches 'special', reads the next one
[ "makes", "sure", "that", "the", "following", "set", "of", "tokens", "matches", "special", "reads", "the", "next", "one" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_gccgo/package.go#L236-L250
147,774
nsf/gocode
_gccgo/package.go
expect_ident
func (this *import_data_parser) expect_ident(ident string) { tok := this.expect(scanner.Ident) if tok != ident { this.errorf("expected identifier: \"%s\", got: \"%s\"", ident, tok) } }
go
func (this *import_data_parser) expect_ident(ident string) { tok := this.expect(scanner.Ident) if tok != ident { this.errorf("expected identifier: \"%s\", got: \"%s\"", ident, tok) } }
[ "func", "(", "this", "*", "import_data_parser", ")", "expect_ident", "(", "ident", "string", ")", "{", "tok", ":=", "this", ".", "expect", "(", "scanner", ".", "Ident", ")", "\n", "if", "tok", "!=", "ident", "{", "this", ".", "errorf", "(", "\"", "\\\"", "\\\"", "\\\"", "\\\"", "\"", ",", "ident", ",", "tok", ")", "\n", "}", "\n", "}" ]
// makes sure that the current token is scanner.Ident and is equals to 'ident', reads the next one
[ "makes", "sure", "that", "the", "current", "token", "is", "scanner", ".", "Ident", "and", "is", "equals", "to", "ident", "reads", "the", "next", "one" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_gccgo/package.go#L253-L258
147,775
nsf/gocode
autocompletefile.go
process_data
func (f *auto_complete_file) process_data(data []byte) { cur, filedata, block := rip_off_decl(data, f.cursor) file, err := parser.ParseFile(f.fset, "", filedata, parser.AllErrors) if err != nil && *g_debug { log_parse_error("Error parsing input file (outer block)", err) } f.package_name = package_name(file) f.decls = make(map[string]*decl) f.packages = collect_package_imports(f.name, file.Decls, f.context) f.filescope = new_scope(nil) f.scope = f.filescope for _, d := range file.Decls { anonymify_ast(d, 0, f.filescope) } // process all top-level declarations for _, decl := range file.Decls { append_to_top_decls(f.decls, decl, f.scope) } if block != nil { // process local function as top-level declaration decls, err := parse_decl_list(f.fset, block) if err != nil && *g_debug { log_parse_error("Error parsing input file (inner block)", err) } for _, d := range decls { anonymify_ast(d, 0, f.filescope) } for _, decl := range decls { append_to_top_decls(f.decls, decl, f.scope) } // process function internals f.cursor = cur for _, decl := range decls { f.process_decl_locals(decl) } } }
go
func (f *auto_complete_file) process_data(data []byte) { cur, filedata, block := rip_off_decl(data, f.cursor) file, err := parser.ParseFile(f.fset, "", filedata, parser.AllErrors) if err != nil && *g_debug { log_parse_error("Error parsing input file (outer block)", err) } f.package_name = package_name(file) f.decls = make(map[string]*decl) f.packages = collect_package_imports(f.name, file.Decls, f.context) f.filescope = new_scope(nil) f.scope = f.filescope for _, d := range file.Decls { anonymify_ast(d, 0, f.filescope) } // process all top-level declarations for _, decl := range file.Decls { append_to_top_decls(f.decls, decl, f.scope) } if block != nil { // process local function as top-level declaration decls, err := parse_decl_list(f.fset, block) if err != nil && *g_debug { log_parse_error("Error parsing input file (inner block)", err) } for _, d := range decls { anonymify_ast(d, 0, f.filescope) } for _, decl := range decls { append_to_top_decls(f.decls, decl, f.scope) } // process function internals f.cursor = cur for _, decl := range decls { f.process_decl_locals(decl) } } }
[ "func", "(", "f", "*", "auto_complete_file", ")", "process_data", "(", "data", "[", "]", "byte", ")", "{", "cur", ",", "filedata", ",", "block", ":=", "rip_off_decl", "(", "data", ",", "f", ".", "cursor", ")", "\n", "file", ",", "err", ":=", "parser", ".", "ParseFile", "(", "f", ".", "fset", ",", "\"", "\"", ",", "filedata", ",", "parser", ".", "AllErrors", ")", "\n", "if", "err", "!=", "nil", "&&", "*", "g_debug", "{", "log_parse_error", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "f", ".", "package_name", "=", "package_name", "(", "file", ")", "\n\n", "f", ".", "decls", "=", "make", "(", "map", "[", "string", "]", "*", "decl", ")", "\n", "f", ".", "packages", "=", "collect_package_imports", "(", "f", ".", "name", ",", "file", ".", "Decls", ",", "f", ".", "context", ")", "\n", "f", ".", "filescope", "=", "new_scope", "(", "nil", ")", "\n", "f", ".", "scope", "=", "f", ".", "filescope", "\n\n", "for", "_", ",", "d", ":=", "range", "file", ".", "Decls", "{", "anonymify_ast", "(", "d", ",", "0", ",", "f", ".", "filescope", ")", "\n", "}", "\n\n", "// process all top-level declarations", "for", "_", ",", "decl", ":=", "range", "file", ".", "Decls", "{", "append_to_top_decls", "(", "f", ".", "decls", ",", "decl", ",", "f", ".", "scope", ")", "\n", "}", "\n", "if", "block", "!=", "nil", "{", "// process local function as top-level declaration", "decls", ",", "err", ":=", "parse_decl_list", "(", "f", ".", "fset", ",", "block", ")", "\n", "if", "err", "!=", "nil", "&&", "*", "g_debug", "{", "log_parse_error", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "decls", "{", "anonymify_ast", "(", "d", ",", "0", ",", "f", ".", "filescope", ")", "\n", "}", "\n\n", "for", "_", ",", "decl", ":=", "range", "decls", "{", "append_to_top_decls", "(", "f", ".", "decls", ",", "decl", ",", "f", ".", "scope", ")", "\n", "}", "\n\n", "// process function internals", "f", ".", "cursor", "=", "cur", "\n", "for", "_", ",", "decl", ":=", "range", "decls", "{", "f", ".", "process_decl_locals", "(", "decl", ")", "\n", "}", "\n", "}", "\n\n", "}" ]
// this one is used for current file buffer exclusively
[ "this", "one", "is", "used", "for", "current", "file", "buffer", "exclusively" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/autocompletefile.go#L67-L110
147,776
nsf/gocode
package_ibin.go
pos
func (r *importReader) pos() { if r.int64() != deltaNewFile { } else if l := r.int64(); l == -1 { } else { r.string() } }
go
func (r *importReader) pos() { if r.int64() != deltaNewFile { } else if l := r.int64(); l == -1 { } else { r.string() } }
[ "func", "(", "r", "*", "importReader", ")", "pos", "(", ")", "{", "if", "r", ".", "int64", "(", ")", "!=", "deltaNewFile", "{", "}", "else", "if", "l", ":=", "r", ".", "int64", "(", ")", ";", "l", "==", "-", "1", "{", "}", "else", "{", "r", ".", "string", "(", ")", "\n", "}", "\n", "}" ]
// we don't care about that, let's just skip it
[ "we", "don", "t", "care", "about", "that", "let", "s", "just", "skip", "it" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_ibin.go#L340-L346
147,777
nsf/gocode
utils.go
readdir_lstat
func readdir_lstat(name string) ([]os.FileInfo, error) { f, err := os.Open(name) if err != nil { return nil, err } defer f.Close() names, err := f.Readdirnames(-1) if err != nil { return nil, err } out := make([]os.FileInfo, 0, len(names)) for _, lname := range names { s, err := os.Lstat(filepath.Join(name, lname)) if err != nil { continue } out = append(out, s) } return out, nil }
go
func readdir_lstat(name string) ([]os.FileInfo, error) { f, err := os.Open(name) if err != nil { return nil, err } defer f.Close() names, err := f.Readdirnames(-1) if err != nil { return nil, err } out := make([]os.FileInfo, 0, len(names)) for _, lname := range names { s, err := os.Lstat(filepath.Join(name, lname)) if err != nil { continue } out = append(out, s) } return out, nil }
[ "func", "readdir_lstat", "(", "name", "string", ")", "(", "[", "]", "os", ".", "FileInfo", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "names", ",", "err", ":=", "f", ".", "Readdirnames", "(", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "out", ":=", "make", "(", "[", "]", "os", ".", "FileInfo", ",", "0", ",", "len", "(", "names", ")", ")", "\n", "for", "_", ",", "lname", ":=", "range", "names", "{", "s", ",", "err", ":=", "os", ".", "Lstat", "(", "filepath", ".", "Join", "(", "name", ",", "lname", ")", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "s", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// our own readdir, which skips the files it cannot lstat
[ "our", "own", "readdir", "which", "skips", "the", "files", "it", "cannot", "lstat" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L17-L38
147,778
nsf/gocode
utils.go
readdir
func readdir(dirname string) []os.FileInfo { f, err := os.Open(dirname) if err != nil { return nil } fi, err := f.Readdir(-1) f.Close() if err != nil { panic(err) } return fi }
go
func readdir(dirname string) []os.FileInfo { f, err := os.Open(dirname) if err != nil { return nil } fi, err := f.Readdir(-1) f.Close() if err != nil { panic(err) } return fi }
[ "func", "readdir", "(", "dirname", "string", ")", "[", "]", "os", ".", "FileInfo", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "dirname", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "fi", ",", "err", ":=", "f", ".", "Readdir", "(", "-", "1", ")", "\n", "f", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "fi", "\n", "}" ]
// our other readdir function, only opens and reads
[ "our", "other", "readdir", "function", "only", "opens", "and", "reads" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L41-L52
147,779
nsf/gocode
utils.go
find_gb_project_root
func find_gb_project_root(path string) (string, error) { path = filepath.Dir(path) if path == "" { return "", fmt.Errorf("project root is blank") } start := path for path != "/" { root := filepath.Join(path, "src") if _, err := os.Stat(root); err != nil { if os.IsNotExist(err) { path = filepath.Dir(path) continue } return "", err } path, err := filepath.EvalSymlinks(path) if err != nil { return "", err } return path, nil } return "", fmt.Errorf("could not find project root in %q or its parents", start) }
go
func find_gb_project_root(path string) (string, error) { path = filepath.Dir(path) if path == "" { return "", fmt.Errorf("project root is blank") } start := path for path != "/" { root := filepath.Join(path, "src") if _, err := os.Stat(root); err != nil { if os.IsNotExist(err) { path = filepath.Dir(path) continue } return "", err } path, err := filepath.EvalSymlinks(path) if err != nil { return "", err } return path, nil } return "", fmt.Errorf("could not find project root in %q or its parents", start) }
[ "func", "find_gb_project_root", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "path", "=", "filepath", ".", "Dir", "(", "path", ")", "\n", "if", "path", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "start", ":=", "path", "\n", "for", "path", "!=", "\"", "\"", "{", "root", ":=", "filepath", ".", "Join", "(", "path", ",", "\"", "\"", ")", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "root", ")", ";", "err", "!=", "nil", "{", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "path", "=", "filepath", ".", "Dir", "(", "path", ")", "\n", "continue", "\n", "}", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "path", ",", "err", ":=", "filepath", ".", "EvalSymlinks", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "path", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "start", ")", "\n", "}" ]
// Code taken directly from `gb`, I hope author doesn't mind.
[ "Code", "taken", "directly", "from", "gb", "I", "hope", "author", "doesn", "t", "mind", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L130-L152
147,780
nsf/gocode
autocompletecontext.go
check_type_expr
func check_type_expr(e ast.Expr) bool { switch t := e.(type) { case *ast.StarExpr: return check_type_expr(t.X) case *ast.ArrayType: return check_type_expr(t.Elt) case *ast.SelectorExpr: return check_type_expr(t.X) case *ast.FuncType: a := check_func_field_list(t.Params) b := check_func_field_list(t.Results) return a && b case *ast.MapType: a := check_type_expr(t.Key) b := check_type_expr(t.Value) return a && b case *ast.Ellipsis: return check_type_expr(t.Elt) case *ast.ChanType: return check_type_expr(t.Value) case *ast.BadExpr: return false default: return true } }
go
func check_type_expr(e ast.Expr) bool { switch t := e.(type) { case *ast.StarExpr: return check_type_expr(t.X) case *ast.ArrayType: return check_type_expr(t.Elt) case *ast.SelectorExpr: return check_type_expr(t.X) case *ast.FuncType: a := check_func_field_list(t.Params) b := check_func_field_list(t.Results) return a && b case *ast.MapType: a := check_type_expr(t.Key) b := check_type_expr(t.Value) return a && b case *ast.Ellipsis: return check_type_expr(t.Elt) case *ast.ChanType: return check_type_expr(t.Value) case *ast.BadExpr: return false default: return true } }
[ "func", "check_type_expr", "(", "e", "ast", ".", "Expr", ")", "bool", "{", "switch", "t", ":=", "e", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "StarExpr", ":", "return", "check_type_expr", "(", "t", ".", "X", ")", "\n", "case", "*", "ast", ".", "ArrayType", ":", "return", "check_type_expr", "(", "t", ".", "Elt", ")", "\n", "case", "*", "ast", ".", "SelectorExpr", ":", "return", "check_type_expr", "(", "t", ".", "X", ")", "\n", "case", "*", "ast", ".", "FuncType", ":", "a", ":=", "check_func_field_list", "(", "t", ".", "Params", ")", "\n", "b", ":=", "check_func_field_list", "(", "t", ".", "Results", ")", "\n", "return", "a", "&&", "b", "\n", "case", "*", "ast", ".", "MapType", ":", "a", ":=", "check_type_expr", "(", "t", ".", "Key", ")", "\n", "b", ":=", "check_type_expr", "(", "t", ".", "Value", ")", "\n", "return", "a", "&&", "b", "\n", "case", "*", "ast", ".", "Ellipsis", ":", "return", "check_type_expr", "(", "t", ".", "Elt", ")", "\n", "case", "*", "ast", ".", "ChanType", ":", "return", "check_type_expr", "(", "t", ".", "Value", ")", "\n", "case", "*", "ast", ".", "BadExpr", ":", "return", "false", "\n", "default", ":", "return", "true", "\n", "}", "\n", "}" ]
// checks for a type expression correctness, it the type expression has // ast.BadExpr somewhere, returns false, otherwise true
[ "checks", "for", "a", "type", "expression", "correctness", "it", "the", "type", "expression", "has", "ast", ".", "BadExpr", "somewhere", "returns", "false", "otherwise", "true" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/autocompletecontext.go#L653-L678
147,781
nsf/gocode
package_bin.go
rawInt64
func (p *gc_bin_parser) rawInt64() int64 { i, err := binary.ReadVarint(p) if err != nil { panic(fmt.Sprintf("read error: %v", err)) } return i }
go
func (p *gc_bin_parser) rawInt64() int64 { i, err := binary.ReadVarint(p) if err != nil { panic(fmt.Sprintf("read error: %v", err)) } return i }
[ "func", "(", "p", "*", "gc_bin_parser", ")", "rawInt64", "(", ")", "int64", "{", "i", ",", "err", ":=", "binary", ".", "ReadVarint", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "\n", "return", "i", "\n", "}" ]
// rawInt64 should only be used by low-level decoders.
[ "rawInt64", "should", "only", "be", "used", "by", "low", "-", "level", "decoders", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_bin.go#L696-L702
147,782
nsf/gocode
package_bin.go
rawStringln
func (p *gc_bin_parser) rawStringln(b byte) string { p.buf = p.buf[:0] for b != '\n' { p.buf = append(p.buf, b) b = p.rawByte() } return string(p.buf) }
go
func (p *gc_bin_parser) rawStringln(b byte) string { p.buf = p.buf[:0] for b != '\n' { p.buf = append(p.buf, b) b = p.rawByte() } return string(p.buf) }
[ "func", "(", "p", "*", "gc_bin_parser", ")", "rawStringln", "(", "b", "byte", ")", "string", "{", "p", ".", "buf", "=", "p", ".", "buf", "[", ":", "0", "]", "\n", "for", "b", "!=", "'\\n'", "{", "p", ".", "buf", "=", "append", "(", "p", ".", "buf", ",", "b", ")", "\n", "b", "=", "p", ".", "rawByte", "(", ")", "\n", "}", "\n", "return", "string", "(", "p", ".", "buf", ")", "\n", "}" ]
// rawStringln should only be used to read the initial version string.
[ "rawStringln", "should", "only", "be", "used", "to", "read", "the", "initial", "version", "string", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_bin.go#L705-L712
147,783
nsf/gocode
declcache.go
collect_package_imports
func collect_package_imports(filename string, decls []ast.Decl, context *package_lookup_context) []package_import { pi := make([]package_import, 0, 16) for _, decl := range decls { if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT { for _, spec := range gd.Specs { imp := spec.(*ast.ImportSpec) path, alias := path_and_alias(imp) abspath, ok := abs_path_for_package(filename, path, context) if ok && alias != "_" { pi = append(pi, package_import{alias, abspath, path}) } } } else { break } } return pi }
go
func collect_package_imports(filename string, decls []ast.Decl, context *package_lookup_context) []package_import { pi := make([]package_import, 0, 16) for _, decl := range decls { if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT { for _, spec := range gd.Specs { imp := spec.(*ast.ImportSpec) path, alias := path_and_alias(imp) abspath, ok := abs_path_for_package(filename, path, context) if ok && alias != "_" { pi = append(pi, package_import{alias, abspath, path}) } } } else { break } } return pi }
[ "func", "collect_package_imports", "(", "filename", "string", ",", "decls", "[", "]", "ast", ".", "Decl", ",", "context", "*", "package_lookup_context", ")", "[", "]", "package_import", "{", "pi", ":=", "make", "(", "[", "]", "package_import", ",", "0", ",", "16", ")", "\n", "for", "_", ",", "decl", ":=", "range", "decls", "{", "if", "gd", ",", "ok", ":=", "decl", ".", "(", "*", "ast", ".", "GenDecl", ")", ";", "ok", "&&", "gd", ".", "Tok", "==", "token", ".", "IMPORT", "{", "for", "_", ",", "spec", ":=", "range", "gd", ".", "Specs", "{", "imp", ":=", "spec", ".", "(", "*", "ast", ".", "ImportSpec", ")", "\n", "path", ",", "alias", ":=", "path_and_alias", "(", "imp", ")", "\n", "abspath", ",", "ok", ":=", "abs_path_for_package", "(", "filename", ",", "path", ",", "context", ")", "\n", "if", "ok", "&&", "alias", "!=", "\"", "\"", "{", "pi", "=", "append", "(", "pi", ",", "package_import", "{", "alias", ",", "abspath", ",", "path", "}", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "return", "pi", "\n", "}" ]
// Parses import declarations until the first non-import declaration and fills // `packages` array with import information.
[ "Parses", "import", "declarations", "until", "the", "first", "non", "-", "import", "declaration", "and", "fills", "packages", "array", "with", "import", "information", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L29-L46
147,784
nsf/gocode
declcache.go
autobuild
func autobuild(p *build.Package) error { if p.Dir == "" { return fmt.Errorf("no files to build") } ps, err := os.Stat(p.PkgObj) if err != nil { // Assume package file does not exist and build for the first time. return build_package(p) } pt := ps.ModTime() fs, err := readdir_lstat(p.Dir) if err != nil { return err } for _, f := range fs { if f.IsDir() { continue } if f.ModTime().After(pt) { // Source file is newer than package file; rebuild. return build_package(p) } } return nil }
go
func autobuild(p *build.Package) error { if p.Dir == "" { return fmt.Errorf("no files to build") } ps, err := os.Stat(p.PkgObj) if err != nil { // Assume package file does not exist and build for the first time. return build_package(p) } pt := ps.ModTime() fs, err := readdir_lstat(p.Dir) if err != nil { return err } for _, f := range fs { if f.IsDir() { continue } if f.ModTime().After(pt) { // Source file is newer than package file; rebuild. return build_package(p) } } return nil }
[ "func", "autobuild", "(", "p", "*", "build", ".", "Package", ")", "error", "{", "if", "p", ".", "Dir", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "ps", ",", "err", ":=", "os", ".", "Stat", "(", "p", ".", "PkgObj", ")", "\n", "if", "err", "!=", "nil", "{", "// Assume package file does not exist and build for the first time.", "return", "build_package", "(", "p", ")", "\n", "}", "\n", "pt", ":=", "ps", ".", "ModTime", "(", ")", "\n", "fs", ",", "err", ":=", "readdir_lstat", "(", "p", ".", "Dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "f", ":=", "range", "fs", "{", "if", "f", ".", "IsDir", "(", ")", "{", "continue", "\n", "}", "\n", "if", "f", ".", "ModTime", "(", ")", ".", "After", "(", "pt", ")", "{", "// Source file is newer than package file; rebuild.", "return", "build_package", "(", "p", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// autobuild compares the mod time of the source files of the package, and if any of them is newer // than the package object file will rebuild it.
[ "autobuild", "compares", "the", "mod", "time", "of", "the", "source", "files", "of", "the", "package", "and", "if", "any", "of", "them", "is", "newer", "than", "the", "package", "object", "file", "will", "rebuild", "it", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L192-L216
147,785
nsf/gocode
declcache.go
try_autobuild
func try_autobuild(p *build.Package) { if g_config.Autobuild { err := autobuild(p) if err != nil && *g_debug { log.Printf("Autobuild error: %s\n", err) } } }
go
func try_autobuild(p *build.Package) { if g_config.Autobuild { err := autobuild(p) if err != nil && *g_debug { log.Printf("Autobuild error: %s\n", err) } } }
[ "func", "try_autobuild", "(", "p", "*", "build", ".", "Package", ")", "{", "if", "g_config", ".", "Autobuild", "{", "err", ":=", "autobuild", "(", "p", ")", "\n", "if", "err", "!=", "nil", "&&", "*", "g_debug", "{", "log", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// executes autobuild function if autobuild option is enabled, logs error and // ignores it
[ "executes", "autobuild", "function", "if", "autobuild", "option", "is", "enabled", "logs", "error", "and", "ignores", "it" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L257-L264
147,786
nsf/gocode
declcache.go
gopath
func (ctxt *package_lookup_context) gopath() []string { var all []string for _, p := range filepath.SplitList(ctxt.GOPATH) { if p == "" || p == ctxt.GOROOT { // Empty paths are uninteresting. // If the path is the GOROOT, ignore it. // People sometimes set GOPATH=$GOROOT. // Do not get confused by this common mistake. continue } if strings.HasPrefix(p, "~") { // Path segments starting with ~ on Unix are almost always // users who have incorrectly quoted ~ while setting GOPATH, // preventing it from expanding to $HOME. // The situation is made more confusing by the fact that // bash allows quoted ~ in $PATH (most shells do not). // Do not get confused by this, and do not try to use the path. // It does not exist, and printing errors about it confuses // those users even more, because they think "sure ~ exists!". // The go command diagnoses this situation and prints a // useful error. // On Windows, ~ is used in short names, such as c:\progra~1 // for c:\program files. continue } all = append(all, p) } return all }
go
func (ctxt *package_lookup_context) gopath() []string { var all []string for _, p := range filepath.SplitList(ctxt.GOPATH) { if p == "" || p == ctxt.GOROOT { // Empty paths are uninteresting. // If the path is the GOROOT, ignore it. // People sometimes set GOPATH=$GOROOT. // Do not get confused by this common mistake. continue } if strings.HasPrefix(p, "~") { // Path segments starting with ~ on Unix are almost always // users who have incorrectly quoted ~ while setting GOPATH, // preventing it from expanding to $HOME. // The situation is made more confusing by the fact that // bash allows quoted ~ in $PATH (most shells do not). // Do not get confused by this, and do not try to use the path. // It does not exist, and printing errors about it confuses // those users even more, because they think "sure ~ exists!". // The go command diagnoses this situation and prints a // useful error. // On Windows, ~ is used in short names, such as c:\progra~1 // for c:\program files. continue } all = append(all, p) } return all }
[ "func", "(", "ctxt", "*", "package_lookup_context", ")", "gopath", "(", ")", "[", "]", "string", "{", "var", "all", "[", "]", "string", "\n", "for", "_", ",", "p", ":=", "range", "filepath", ".", "SplitList", "(", "ctxt", ".", "GOPATH", ")", "{", "if", "p", "==", "\"", "\"", "||", "p", "==", "ctxt", ".", "GOROOT", "{", "// Empty paths are uninteresting.", "// If the path is the GOROOT, ignore it.", "// People sometimes set GOPATH=$GOROOT.", "// Do not get confused by this common mistake.", "continue", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "p", ",", "\"", "\"", ")", "{", "// Path segments starting with ~ on Unix are almost always", "// users who have incorrectly quoted ~ while setting GOPATH,", "// preventing it from expanding to $HOME.", "// The situation is made more confusing by the fact that", "// bash allows quoted ~ in $PATH (most shells do not).", "// Do not get confused by this, and do not try to use the path.", "// It does not exist, and printing errors about it confuses", "// those users even more, because they think \"sure ~ exists!\".", "// The go command diagnoses this situation and prints a", "// useful error.", "// On Windows, ~ is used in short names, such as c:\\progra~1", "// for c:\\program files.", "continue", "\n", "}", "\n", "all", "=", "append", "(", "all", ",", "p", ")", "\n", "}", "\n", "return", "all", "\n", "}" ]
// gopath returns the list of Go path directories.
[ "gopath", "returns", "the", "list", "of", "Go", "path", "directories", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L431-L459
147,787
nsf/gocode
decl.go
infer_type
func (d *decl) infer_type() (ast.Expr, *scope) { // special case for range vars if d.is_rangevar() { var scope *scope d.typ, scope = infer_range_type(d.value, d.scope, d.value_index) return d.typ, scope } switch d.class { case decl_package: // package is handled specially in inferType return nil, nil case decl_type: return ast.NewIdent(d.name), d.scope } // shortcut if d.typ != nil && d.value == nil { return d.typ, d.scope } // prevent loops if d.is_visited() { return nil, nil } d.set_visited() defer d.clear_visited() var scope *scope d.typ, scope, _ = infer_type(d.value, d.scope, d.value_index) return d.typ, scope }
go
func (d *decl) infer_type() (ast.Expr, *scope) { // special case for range vars if d.is_rangevar() { var scope *scope d.typ, scope = infer_range_type(d.value, d.scope, d.value_index) return d.typ, scope } switch d.class { case decl_package: // package is handled specially in inferType return nil, nil case decl_type: return ast.NewIdent(d.name), d.scope } // shortcut if d.typ != nil && d.value == nil { return d.typ, d.scope } // prevent loops if d.is_visited() { return nil, nil } d.set_visited() defer d.clear_visited() var scope *scope d.typ, scope, _ = infer_type(d.value, d.scope, d.value_index) return d.typ, scope }
[ "func", "(", "d", "*", "decl", ")", "infer_type", "(", ")", "(", "ast", ".", "Expr", ",", "*", "scope", ")", "{", "// special case for range vars", "if", "d", ".", "is_rangevar", "(", ")", "{", "var", "scope", "*", "scope", "\n", "d", ".", "typ", ",", "scope", "=", "infer_range_type", "(", "d", ".", "value", ",", "d", ".", "scope", ",", "d", ".", "value_index", ")", "\n", "return", "d", ".", "typ", ",", "scope", "\n", "}", "\n\n", "switch", "d", ".", "class", "{", "case", "decl_package", ":", "// package is handled specially in inferType", "return", "nil", ",", "nil", "\n", "case", "decl_type", ":", "return", "ast", ".", "NewIdent", "(", "d", ".", "name", ")", ",", "d", ".", "scope", "\n", "}", "\n\n", "// shortcut", "if", "d", ".", "typ", "!=", "nil", "&&", "d", ".", "value", "==", "nil", "{", "return", "d", ".", "typ", ",", "d", ".", "scope", "\n", "}", "\n\n", "// prevent loops", "if", "d", ".", "is_visited", "(", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "d", ".", "set_visited", "(", ")", "\n", "defer", "d", ".", "clear_visited", "(", ")", "\n\n", "var", "scope", "*", "scope", "\n", "d", ".", "typ", ",", "scope", ",", "_", "=", "infer_type", "(", "d", ".", "value", ",", "d", ".", "scope", ",", "d", ".", "value_index", ")", "\n", "return", "d", ".", "typ", ",", "scope", "\n", "}" ]
// Uses Value, ValueIndex and Scope to infer the type of this // declaration. Returns the type itself and the scope where this type // makes sense.
[ "Uses", "Value", "ValueIndex", "and", "Scope", "to", "infer", "the", "type", "of", "this", "declaration", ".", "Returns", "the", "type", "itself", "and", "the", "scope", "where", "this", "type", "makes", "sense", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/decl.go#L954-L985
147,788
nsf/gocode
scope.go
add_named_decl
func (s *scope) add_named_decl(d *decl) *decl { return s.add_decl(d.name, d) }
go
func (s *scope) add_named_decl(d *decl) *decl { return s.add_decl(d.name, d) }
[ "func", "(", "s", "*", "scope", ")", "add_named_decl", "(", "d", "*", "decl", ")", "*", "decl", "{", "return", "s", ".", "add_decl", "(", "d", ".", "name", ",", "d", ")", "\n", "}" ]
// adds declaration or returns an existing one
[ "adds", "declaration", "or", "returns", "an", "existing", "one" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/scope.go#L39-L41
147,789
nsf/gocode
cursorcontext.go
deduce_cursor_decl
func (c *auto_complete_context) deduce_cursor_decl(iter *token_iterator) (*decl, ast.Expr) { expr, err := parser.ParseExpr(iter.extract_go_expr()) if err != nil { return nil, nil } return expr_to_decl(expr, c.current.scope), expr }
go
func (c *auto_complete_context) deduce_cursor_decl(iter *token_iterator) (*decl, ast.Expr) { expr, err := parser.ParseExpr(iter.extract_go_expr()) if err != nil { return nil, nil } return expr_to_decl(expr, c.current.scope), expr }
[ "func", "(", "c", "*", "auto_complete_context", ")", "deduce_cursor_decl", "(", "iter", "*", "token_iterator", ")", "(", "*", "decl", ",", "ast", ".", "Expr", ")", "{", "expr", ",", "err", ":=", "parser", ".", "ParseExpr", "(", "iter", ".", "extract_go_expr", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "expr_to_decl", "(", "expr", ",", "c", ".", "current", ".", "scope", ")", ",", "expr", "\n", "}" ]
// this function is called when the cursor is at the '.' and you need to get the // declaration before that dot
[ "this", "function", "is", "called", "when", "the", "cursor", "is", "at", "the", ".", "and", "you", "need", "to", "get", "the", "declaration", "before", "that", "dot" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/cursorcontext.go#L264-L270
147,790
nsf/gocode
cursorcontext.go
deduce_struct_type_decl
func (c *auto_complete_context) deduce_struct_type_decl(iter *token_iterator) *decl { typ := iter.extract_struct_type() if typ == "" { return nil } expr, err := parser.ParseExpr(typ) if err != nil { return nil } decl := type_to_decl(expr, c.current.scope) if decl == nil { return nil } // we allow only struct types here, but also support type aliases if decl.is_alias() { dd := decl.type_dealias() if _, ok := dd.typ.(*ast.StructType); !ok { return nil } } else if _, ok := decl.typ.(*ast.StructType); !ok { return nil } return decl }
go
func (c *auto_complete_context) deduce_struct_type_decl(iter *token_iterator) *decl { typ := iter.extract_struct_type() if typ == "" { return nil } expr, err := parser.ParseExpr(typ) if err != nil { return nil } decl := type_to_decl(expr, c.current.scope) if decl == nil { return nil } // we allow only struct types here, but also support type aliases if decl.is_alias() { dd := decl.type_dealias() if _, ok := dd.typ.(*ast.StructType); !ok { return nil } } else if _, ok := decl.typ.(*ast.StructType); !ok { return nil } return decl }
[ "func", "(", "c", "*", "auto_complete_context", ")", "deduce_struct_type_decl", "(", "iter", "*", "token_iterator", ")", "*", "decl", "{", "typ", ":=", "iter", ".", "extract_struct_type", "(", ")", "\n", "if", "typ", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "expr", ",", "err", ":=", "parser", ".", "ParseExpr", "(", "typ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "decl", ":=", "type_to_decl", "(", "expr", ",", "c", ".", "current", ".", "scope", ")", "\n", "if", "decl", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "// we allow only struct types here, but also support type aliases", "if", "decl", ".", "is_alias", "(", ")", "{", "dd", ":=", "decl", ".", "type_dealias", "(", ")", "\n", "if", "_", ",", "ok", ":=", "dd", ".", "typ", ".", "(", "*", "ast", ".", "StructType", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "}", "else", "if", "_", ",", "ok", ":=", "decl", ".", "typ", ".", "(", "*", "ast", ".", "StructType", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "decl", "\n", "}" ]
// try to find and extract the surrounding struct literal type
[ "try", "to", "find", "and", "extract", "the", "surrounding", "struct", "literal", "type" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/cursorcontext.go#L273-L298
147,791
nsf/gocode
package.go
new_package_file_cache_forever
func new_package_file_cache_forever(name, defalias string) *package_file_cache { m := new(package_file_cache) m.name = name m.mtime = -1 m.defalias = defalias return m }
go
func new_package_file_cache_forever(name, defalias string) *package_file_cache { m := new(package_file_cache) m.name = name m.mtime = -1 m.defalias = defalias return m }
[ "func", "new_package_file_cache_forever", "(", "name", ",", "defalias", "string", ")", "*", "package_file_cache", "{", "m", ":=", "new", "(", "package_file_cache", ")", "\n", "m", ".", "name", "=", "name", "\n", "m", ".", "mtime", "=", "-", "1", "\n", "m", ".", "defalias", "=", "defalias", "\n", "return", "m", "\n", "}" ]
// Creates a cache that stays in cache forever. Useful for built-in packages.
[ "Creates", "a", "cache", "that", "stays", "in", "cache", "forever", ".", "Useful", "for", "built", "-", "in", "packages", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package.go#L43-L49
147,792
nsf/gocode
package.go
append_packages
func (c package_cache) append_packages(ps map[string]*package_file_cache, pkgs []package_import) { for _, m := range pkgs { if _, ok := ps[m.abspath]; ok { continue } if mod, ok := c[m.abspath]; ok { ps[m.abspath] = mod } else { mod = new_package_file_cache(m.abspath, m.path) ps[m.abspath] = mod c[m.abspath] = mod } } }
go
func (c package_cache) append_packages(ps map[string]*package_file_cache, pkgs []package_import) { for _, m := range pkgs { if _, ok := ps[m.abspath]; ok { continue } if mod, ok := c[m.abspath]; ok { ps[m.abspath] = mod } else { mod = new_package_file_cache(m.abspath, m.path) ps[m.abspath] = mod c[m.abspath] = mod } } }
[ "func", "(", "c", "package_cache", ")", "append_packages", "(", "ps", "map", "[", "string", "]", "*", "package_file_cache", ",", "pkgs", "[", "]", "package_import", ")", "{", "for", "_", ",", "m", ":=", "range", "pkgs", "{", "if", "_", ",", "ok", ":=", "ps", "[", "m", ".", "abspath", "]", ";", "ok", "{", "continue", "\n", "}", "\n\n", "if", "mod", ",", "ok", ":=", "c", "[", "m", ".", "abspath", "]", ";", "ok", "{", "ps", "[", "m", ".", "abspath", "]", "=", "mod", "\n", "}", "else", "{", "mod", "=", "new_package_file_cache", "(", "m", ".", "abspath", ",", "m", ".", "path", ")", "\n", "ps", "[", "m", ".", "abspath", "]", "=", "mod", "\n", "c", "[", "m", ".", "abspath", "]", "=", "mod", "\n", "}", "\n", "}", "\n", "}" ]
// Function fills 'ps' set with packages from 'packages' import information. // In case if package is not in the cache, it creates one and adds one to the cache.
[ "Function", "fills", "ps", "set", "with", "packages", "from", "packages", "import", "information", ".", "In", "case", "if", "package", "is", "not", "in", "the", "cache", "it", "creates", "one", "and", "adds", "one", "to", "the", "cache", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package.go#L228-L242
147,793
nsf/gocode
package_text.go
parse_package
func (p *gc_parser) parse_package() *ast.Ident { path, err := strconv.Unquote(p.expect(scanner.String)) if err != nil { panic(err) } return ast.NewIdent(path) }
go
func (p *gc_parser) parse_package() *ast.Ident { path, err := strconv.Unquote(p.expect(scanner.String)) if err != nil { panic(err) } return ast.NewIdent(path) }
[ "func", "(", "p", "*", "gc_parser", ")", "parse_package", "(", ")", "*", "ast", ".", "Ident", "{", "path", ",", "err", ":=", "strconv", ".", "Unquote", "(", "p", ".", "expect", "(", "scanner", ".", "String", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "ast", ".", "NewIdent", "(", "path", ")", "\n", "}" ]
// ImportPath = string_lit . // quoted name of the path, but we return it as an identifier, taking an alias // from 'pathToAlias' map, it is filled by import statements
[ "ImportPath", "=", "string_lit", ".", "quoted", "name", "of", "the", "path", "but", "we", "return", "it", "as", "an", "identifier", "taking", "an", "alias", "from", "pathToAlias", "map", "it", "is", "filled", "by", "import", "statements" ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L161-L168
147,794
nsf/gocode
package_text.go
parse_name
func (p *gc_parser) parse_name() (string, ast.Expr) { switch p.tok { case scanner.Ident: name := p.lit p.next() return name, ast.NewIdent(name) case '?': p.next() return "?", ast.NewIdent("?") case '@': en := p.parse_exported_name() return en.Sel.Name, en } p.error("name expected") return "", nil }
go
func (p *gc_parser) parse_name() (string, ast.Expr) { switch p.tok { case scanner.Ident: name := p.lit p.next() return name, ast.NewIdent(name) case '?': p.next() return "?", ast.NewIdent("?") case '@': en := p.parse_exported_name() return en.Sel.Name, en } p.error("name expected") return "", nil }
[ "func", "(", "p", "*", "gc_parser", ")", "parse_name", "(", ")", "(", "string", ",", "ast", ".", "Expr", ")", "{", "switch", "p", ".", "tok", "{", "case", "scanner", ".", "Ident", ":", "name", ":=", "p", ".", "lit", "\n", "p", ".", "next", "(", ")", "\n", "return", "name", ",", "ast", ".", "NewIdent", "(", "name", ")", "\n", "case", "'?'", ":", "p", ".", "next", "(", ")", "\n", "return", "\"", "\"", ",", "ast", ".", "NewIdent", "(", "\"", "\"", ")", "\n", "case", "'@'", ":", "en", ":=", "p", ".", "parse_exported_name", "(", ")", "\n", "return", "en", ".", "Sel", ".", "Name", ",", "en", "\n", "}", "\n", "p", ".", "error", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", ",", "nil", "\n", "}" ]
// Name = identifier | "?" | ExportedName .
[ "Name", "=", "identifier", "|", "?", "|", "ExportedName", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L185-L200
147,795
nsf/gocode
package_text.go
parse_type_decl
func (p *gc_parser) parse_type_decl() (string, *ast.GenDecl) { p.expect_keyword("type") name := p.parse_exported_name() typ := p.parse_type() return name.X.(*ast.Ident).Name, &ast.GenDecl{ Tok: token.TYPE, Specs: []ast.Spec{ &ast.TypeSpec{ Name: name.Sel, Type: typ, }, }, } }
go
func (p *gc_parser) parse_type_decl() (string, *ast.GenDecl) { p.expect_keyword("type") name := p.parse_exported_name() typ := p.parse_type() return name.X.(*ast.Ident).Name, &ast.GenDecl{ Tok: token.TYPE, Specs: []ast.Spec{ &ast.TypeSpec{ Name: name.Sel, Type: typ, }, }, } }
[ "func", "(", "p", "*", "gc_parser", ")", "parse_type_decl", "(", ")", "(", "string", ",", "*", "ast", ".", "GenDecl", ")", "{", "p", ".", "expect_keyword", "(", "\"", "\"", ")", "\n", "name", ":=", "p", ".", "parse_exported_name", "(", ")", "\n", "typ", ":=", "p", ".", "parse_type", "(", ")", "\n", "return", "name", ".", "X", ".", "(", "*", "ast", ".", "Ident", ")", ".", "Name", ",", "&", "ast", ".", "GenDecl", "{", "Tok", ":", "token", ".", "TYPE", ",", "Specs", ":", "[", "]", "ast", ".", "Spec", "{", "&", "ast", ".", "TypeSpec", "{", "Name", ":", "name", ".", "Sel", ",", "Type", ":", "typ", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// TypeDecl = "type" ExportedName Type .
[ "TypeDecl", "=", "type", "ExportedName", "Type", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L538-L551
147,796
nsf/gocode
package_text.go
parse_var_decl
func (p *gc_parser) parse_var_decl() (string, *ast.GenDecl) { p.expect_keyword("var") name := p.parse_exported_name() typ := p.parse_type() return name.X.(*ast.Ident).Name, &ast.GenDecl{ Tok: token.VAR, Specs: []ast.Spec{ &ast.ValueSpec{ Names: []*ast.Ident{name.Sel}, Type: typ, }, }, } }
go
func (p *gc_parser) parse_var_decl() (string, *ast.GenDecl) { p.expect_keyword("var") name := p.parse_exported_name() typ := p.parse_type() return name.X.(*ast.Ident).Name, &ast.GenDecl{ Tok: token.VAR, Specs: []ast.Spec{ &ast.ValueSpec{ Names: []*ast.Ident{name.Sel}, Type: typ, }, }, } }
[ "func", "(", "p", "*", "gc_parser", ")", "parse_var_decl", "(", ")", "(", "string", ",", "*", "ast", ".", "GenDecl", ")", "{", "p", ".", "expect_keyword", "(", "\"", "\"", ")", "\n", "name", ":=", "p", ".", "parse_exported_name", "(", ")", "\n", "typ", ":=", "p", ".", "parse_type", "(", ")", "\n", "return", "name", ".", "X", ".", "(", "*", "ast", ".", "Ident", ")", ".", "Name", ",", "&", "ast", ".", "GenDecl", "{", "Tok", ":", "token", ".", "VAR", ",", "Specs", ":", "[", "]", "ast", ".", "Spec", "{", "&", "ast", ".", "ValueSpec", "{", "Names", ":", "[", "]", "*", "ast", ".", "Ident", "{", "name", ".", "Sel", "}", ",", "Type", ":", "typ", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// VarDecl = "var" ExportedName Type .
[ "VarDecl", "=", "var", "ExportedName", "Type", "." ]
5bee97b488366fd20b054d0861b89834ff5bbfb2
https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L554-L567
147,797
veandco/go-sdl2
ttf/sdl_ttf.go
RenderUTF8BlendedWrapped
func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) { _text := C.CString(text) defer C.free(unsafe.Pointer(_text)) _c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)} surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength)))) if surface == nil { return nil, GetError() } return surface, nil }
go
func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) { _text := C.CString(text) defer C.free(unsafe.Pointer(_text)) _c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)} surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength)))) if surface == nil { return nil, GetError() } return surface, nil }
[ "func", "(", "f", "*", "Font", ")", "RenderUTF8BlendedWrapped", "(", "text", "string", ",", "fg", "sdl", ".", "Color", ",", "wrapLength", "int", ")", "(", "*", "sdl", ".", "Surface", ",", "error", ")", "{", "_text", ":=", "C", ".", "CString", "(", "text", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "_text", ")", ")", "\n", "_c", ":=", "C", ".", "SDL_Color", "{", "C", ".", "Uint8", "(", "fg", ".", "R", ")", ",", "C", ".", "Uint8", "(", "fg", ".", "G", ")", ",", "C", ".", "Uint8", "(", "fg", ".", "B", ")", ",", "C", ".", "Uint8", "(", "fg", ".", "A", ")", "}", "\n", "surface", ":=", "(", "*", "sdl", ".", "Surface", ")", "(", "unsafe", ".", "Pointer", "(", "C", ".", "TTF_RenderUTF8_Blended_Wrapped", "(", "f", ".", "f", ",", "_text", ",", "_c", ",", "C", ".", "Uint32", "(", "wrapLength", ")", ")", ")", ")", "\n", "if", "surface", "==", "nil", "{", "return", "nil", ",", "GetError", "(", ")", "\n", "}", "\n", "return", "surface", ",", "nil", "\n", "}" ]
// RenderUTF8BlendedWrapped creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. Text is wrapped to multiple lines on line endings and on word boundaries if it extends beyond wrapLength in pixels.
[ "RenderUTF8BlendedWrapped", "creates", "a", "32", "-", "bit", "ARGB", "surface", "and", "render", "the", "given", "text", "at", "high", "quality", "using", "alpha", "blending", "to", "dither", "the", "font", "with", "the", "given", "color", ".", "Text", "is", "wrapped", "to", "multiple", "lines", "on", "line", "endings", "and", "on", "word", "boundaries", "if", "it", "extends", "beyond", "wrapLength", "in", "pixels", "." ]
649ea85188106bf99d15daf5cdcd93b0da65ada9
https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/ttf/sdl_ttf.go#L176-L185
147,798
veandco/go-sdl2
raster/painter.go
Paint
func (p *ImagePainter) Paint(ss []raster.Span, done bool) { // Convert color to RGBA dr, dg, db, da := p.c.RGBA() // 16 bit values // Alpha mask const m = 1<<16 - 1 // Draw spans b := p.Image.Bounds() for _, s := range ss { if s.Y < b.Min.Y || s.Y >= b.Max.Y { continue } if s.X0 < b.Min.X { s.X0 = b.Min.X } if s.X1 > b.Max.X { s.X1 = b.Max.X } if s.X0 >= s.X1 { continue } for x := s.X0; x < s.X1; x++ { y := s.Y - b.Min.Y var ma uint32 = s.Alpha // 16 bit value // Get destination pixel color in RGBA64 sr, sg, sb, sa := p.Image.At(x, y).RGBA() // 16 bit values // Compute destination color in RGBA64 var a = (m - (da * ma / m)) rr := uint16((dr*ma + sr*a) / m) gg := uint16((dg*ma + sg*a) / m) bb := uint16((db*ma + sb*a) / m) aa := uint16((da*ma + sa*a) / m) // Use image model to convert p.Image.Set(x, y, color.RGBA64{rr, gg, bb, aa}) } } }
go
func (p *ImagePainter) Paint(ss []raster.Span, done bool) { // Convert color to RGBA dr, dg, db, da := p.c.RGBA() // 16 bit values // Alpha mask const m = 1<<16 - 1 // Draw spans b := p.Image.Bounds() for _, s := range ss { if s.Y < b.Min.Y || s.Y >= b.Max.Y { continue } if s.X0 < b.Min.X { s.X0 = b.Min.X } if s.X1 > b.Max.X { s.X1 = b.Max.X } if s.X0 >= s.X1 { continue } for x := s.X0; x < s.X1; x++ { y := s.Y - b.Min.Y var ma uint32 = s.Alpha // 16 bit value // Get destination pixel color in RGBA64 sr, sg, sb, sa := p.Image.At(x, y).RGBA() // 16 bit values // Compute destination color in RGBA64 var a = (m - (da * ma / m)) rr := uint16((dr*ma + sr*a) / m) gg := uint16((dg*ma + sg*a) / m) bb := uint16((db*ma + sb*a) / m) aa := uint16((da*ma + sa*a) / m) // Use image model to convert p.Image.Set(x, y, color.RGBA64{rr, gg, bb, aa}) } } }
[ "func", "(", "p", "*", "ImagePainter", ")", "Paint", "(", "ss", "[", "]", "raster", ".", "Span", ",", "done", "bool", ")", "{", "// Convert color to RGBA", "dr", ",", "dg", ",", "db", ",", "da", ":=", "p", ".", "c", ".", "RGBA", "(", ")", "// 16 bit values", "\n", "// Alpha mask", "const", "m", "=", "1", "<<", "16", "-", "1", "\n", "// Draw spans", "b", ":=", "p", ".", "Image", ".", "Bounds", "(", ")", "\n", "for", "_", ",", "s", ":=", "range", "ss", "{", "if", "s", ".", "Y", "<", "b", ".", "Min", ".", "Y", "||", "s", ".", "Y", ">=", "b", ".", "Max", ".", "Y", "{", "continue", "\n", "}", "\n", "if", "s", ".", "X0", "<", "b", ".", "Min", ".", "X", "{", "s", ".", "X0", "=", "b", ".", "Min", ".", "X", "\n", "}", "\n", "if", "s", ".", "X1", ">", "b", ".", "Max", ".", "X", "{", "s", ".", "X1", "=", "b", ".", "Max", ".", "X", "\n", "}", "\n", "if", "s", ".", "X0", ">=", "s", ".", "X1", "{", "continue", "\n", "}", "\n", "for", "x", ":=", "s", ".", "X0", ";", "x", "<", "s", ".", "X1", ";", "x", "++", "{", "y", ":=", "s", ".", "Y", "-", "b", ".", "Min", ".", "Y", "\n", "var", "ma", "uint32", "=", "s", ".", "Alpha", "// 16 bit value", "\n", "// Get destination pixel color in RGBA64", "sr", ",", "sg", ",", "sb", ",", "sa", ":=", "p", ".", "Image", ".", "At", "(", "x", ",", "y", ")", ".", "RGBA", "(", ")", "// 16 bit values", "\n", "// Compute destination color in RGBA64", "var", "a", "=", "(", "m", "-", "(", "da", "*", "ma", "/", "m", ")", ")", "\n", "rr", ":=", "uint16", "(", "(", "dr", "*", "ma", "+", "sr", "*", "a", ")", "/", "m", ")", "\n", "gg", ":=", "uint16", "(", "(", "dg", "*", "ma", "+", "sg", "*", "a", ")", "/", "m", ")", "\n", "bb", ":=", "uint16", "(", "(", "db", "*", "ma", "+", "sb", "*", "a", ")", "/", "m", ")", "\n", "aa", ":=", "uint16", "(", "(", "da", "*", "ma", "+", "sa", "*", "a", ")", "/", "m", ")", "\n", "// Use image model to convert", "p", ".", "Image", ".", "Set", "(", "x", ",", "y", ",", "color", ".", "RGBA64", "{", "rr", ",", "gg", ",", "bb", ",", "aa", "}", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Paint a batch of Spans using the current ImagePainter image and color. // Image's Color model will be used to convert the color.
[ "Paint", "a", "batch", "of", "Spans", "using", "the", "current", "ImagePainter", "image", "and", "color", ".", "Image", "s", "Color", "model", "will", "be", "used", "to", "convert", "the", "color", "." ]
649ea85188106bf99d15daf5cdcd93b0da65ada9
https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/raster/painter.go#L23-L58
147,799
veandco/go-sdl2
mix/sdl_mixer.go
LoadMUSTypeRW
func LoadMUSTypeRW(src *sdl.RWops, type_ MusicType, freesrc int) (mus *Music, err error) { _src := (*C.SDL_RWops)(unsafe.Pointer(src)) _type := (C.Mix_MusicType)(type_) _freesrc := (C.int)(freesrc) mus = (*Music)(unsafe.Pointer(C.Mix_LoadMUSType_RW(_src, _type, _freesrc))) if mus == nil { err = sdl.GetError() } return }
go
func LoadMUSTypeRW(src *sdl.RWops, type_ MusicType, freesrc int) (mus *Music, err error) { _src := (*C.SDL_RWops)(unsafe.Pointer(src)) _type := (C.Mix_MusicType)(type_) _freesrc := (C.int)(freesrc) mus = (*Music)(unsafe.Pointer(C.Mix_LoadMUSType_RW(_src, _type, _freesrc))) if mus == nil { err = sdl.GetError() } return }
[ "func", "LoadMUSTypeRW", "(", "src", "*", "sdl", ".", "RWops", ",", "type_", "MusicType", ",", "freesrc", "int", ")", "(", "mus", "*", "Music", ",", "err", "error", ")", "{", "_src", ":=", "(", "*", "C", ".", "SDL_RWops", ")", "(", "unsafe", ".", "Pointer", "(", "src", ")", ")", "\n", "_type", ":=", "(", "C", ".", "Mix_MusicType", ")", "(", "type_", ")", "\n", "_freesrc", ":=", "(", "C", ".", "int", ")", "(", "freesrc", ")", "\n", "mus", "=", "(", "*", "Music", ")", "(", "unsafe", ".", "Pointer", "(", "C", ".", "Mix_LoadMUSType_RW", "(", "_src", ",", "_type", ",", "_freesrc", ")", ")", ")", "\n", "if", "mus", "==", "nil", "{", "err", "=", "sdl", ".", "GetError", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// LoadMUSTypeRW loads a music file from an sdl.RWop object assuming a specific format.
[ "LoadMUSTypeRW", "loads", "a", "music", "file", "from", "an", "sdl", ".", "RWop", "object", "assuming", "a", "specific", "format", "." ]
649ea85188106bf99d15daf5cdcd93b0da65ada9
https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L209-L219