10 examples of 'go slice' in Go

Every line of 'go slice' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
363func (sc scopedArray) Slice(from, to int64) msg.Source { return sc.under.Slice(from, to) }
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

415func (v *BaseKParserVisitor) VisitSlice(ctx *SliceContext) interface{} {
416 return v.VisitChildren(ctx)
417}
171func (w *walker) Slice(s reflect.Value) error {
172 if w.ignoring() {
173 return nil
174 }
175
176 var newS reflect.Value
177 if s.IsNil() {
178 newS = reflect.Indirect(reflect.New(s.Type()))
179 } else {
180 newS = reflect.MakeSlice(s.Type(), s.Len(), s.Cap())
181 }
182
183 w.cs = append(w.cs, newS)
184 w.valPush(newS)
185 return nil
186}
80func (x AstSlice) Slice(lo, hi int) AstWithSlice { x.X = x.X[lo:hi]; return x }
131func (x Expr) Slice(start int, rest ...int) Expr {
132 return append(x, Slice(append([]int{start}, rest...)))
133}
103func slice(s string, from int, to int) string {
104 from = maxInt(from, 0)
105 to = minInt(to, len(s))
106 return s[minInt(from, to):to]
107}
711func (r *protoRepeated) Slice(x, y, step int) starlark.Value { return r.list.Slice(x, y, step) }
24func Slice(arr []byte, count int) [][]byte {
25
26 sliceCount := len(arr) / count
27 result := make([][]byte, sliceCount)
28
29 for i := 0; i < sliceCount; i++ {
30 start := i * count
31 end := i*count + count
32
33 result[i] = arr[start:end]
34 }
35
36 return result
37}
594func (ns *Namespace) Slice(args ...interface{}) interface{} {
595 if len(args) == 0 {
596 return args
597 }
598
599 return collections.Slice(args...)
600}
243func (matrix *SparseInt32Matrix) Slice(rfrom, rto, cfrom, cto int) Matrix {
244 return matrix.SLICE(rfrom, rto, cfrom, cto)
245}

Related snippets