10 examples of 'golang when to use pointers' in Go

Every line of 'golang when to use pointers' 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
438func (ctx *Context) wrapDuktapePointer(
439 ptr unsafe.Pointer,
440 t reflect.Type,
441) func(in []reflect.Value) []reflect.Value {
442 return func(in []reflect.Value) []reflect.Value {
443 ctx.PushGlobalObject()
444 ctx.GetPropString(-1, "CandyJS")
445 obj := ctx.NormalizeIndex(-1)
446 ctx.PushString("_call")
447 ctx.PushPointer(ptr)
448 ctx.pushValues(in)
449 ctx.CallProp(obj, 2)
450
451 return ctx.getCallResult(t)
452 }
453}
117func memclrHasPointers(ptr unsafe.Pointer, n uintptr)
148func (s Nested) SetPointers(v Pointer_List) error {
149 return s.Struct.SetPtr(1, v.List.ToPtr())
150}
180func sanitizePtrType(t *reflect.Type) (success bool) {
181 x := *t
182 if x.Kind() == reflect.Ptr {
183 *t = x.Elem()
184
185 if (*t).Kind() == reflect.Ptr {
186 return false
187 }
188 }
189 return true
190}
121func (pm *pointerMap) addPrimitivePointer(ptr uintptr) {
122 for _, have := range pm.primitivePointers {
123 if ptr == have {
124 return
125 }
126 }
127 pm.primitivePointers = append(pm.primitivePointers, ptr)
128}
1436func (x *EmbeddedSt4) GetPointersStructField() *PointersStruct {
1437 if x != nil {
1438 return x.PointersStructField
1439 }
1440 return nil
1441}
740func (g *genDeepCopy) doPointer(t *types.Type, sw *generator.SnippetWriter) {
741 sw.Do("if *in == nil { *out = nil } else {\n", t)
742 if hasDeepCopyMethod(t.Elem) {
743 sw.Do("*out = new($.Elem|raw$)\n", t)
744 sw.Do("**out = (*in).DeepCopy()\n", nil)
745 } else if t.Elem.IsAssignable() {
746 sw.Do("*out = new($.Elem|raw$)\n", t)
747 sw.Do("**out = **in", nil)
748 } else {
749 switch t.Elem.Kind {
750 case types.Map, types.Slice:
751 sw.Do("*out = new($.Elem|raw$)\n", t)
752 sw.Do("if **in != nil {\n", t)
753 sw.Do("in, out := *in, *out\n", nil)
754 g.generateFor(t.Elem, sw)
755 sw.Do("}\n", nil)
756 default:
757 sw.Do("*out = new($.Elem|raw$)\n", t)
758 sw.Do("(*in).DeepCopyInto(*out)\n", nil)
759 }
760 }
761 sw.Do("}", t)
762}
14func resolvePointers(obj interface{}) interface{} {
15 if obj == nil {
16 return obj
17 }
18 obj_val := reflect.ValueOf(obj)
19 for obj_val.Kind() == reflect.Ptr {
20 obj_val = obj_val.Elem()
21 }
22 if obj_val.CanInterface() {
23 return obj_val.Interface()
24 } else {
25 return nil
26 }
27}
186func ensurePointer(T types.Type) types.Type {
187 if _, ok := T.(*types.Named); ok && !IsInterface(T) {
188 return types.NewPointer(T)
189 }
190
191 return T
192}
143func (s Nested) HasPointers() bool {
144 p, err := s.Struct.Ptr(1)
145 return p.IsValid() || err != nil
146}

Related snippets