10 examples of 'golang struct initialization' in Go

Every line of 'golang struct initialization' 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
92func init() { fn() }
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

478func StructInit(args ...interface{}) interface{} {
479
480 if (len(args) & 1) != 1 {
481 panic("call with invalid argument count: please use `structInit(structType, member1, val1, ...)")
482 }
483
484 got, ok := args[0].(qlang.GoTyper)
485 if !ok {
486 panic(fmt.Sprintf("`%v` is not a qlang type", args[0]))
487 }
488 t := got.GoType()
489 if t.Kind() != reflect.Struct {
490 panic(fmt.Sprintf("`%v` is not a struct type", args[0]))
491 }
492 ret := reflect.New(t)
493 setStructMember(ret.Elem(), args[1:]...)
494 return ret.Interface()
495}
16func init() {
17 tm := []glib.TypeMarshaler{
18 {glib.Type(C.gtk_alignment_get_type()), marshalAlignment},
19 {glib.Type(C.gtk_arrow_get_type()), marshalArrow},
20 {glib.Type(C.gtk_misc_get_type()), marshalMisc},
21 {glib.Type(C.gtk_status_icon_get_type()), marshalStatusIcon},
22 }
23 glib.RegisterGValueMarshalers(tm)
24
25 //Contribute to casting
26 for k, v := range map[string]WrapFn{
27 "GtkAlignment": wrapAlignment,
28 "GtkArrow": wrapArrow,
29 "GtkMisc": wrapMisc,
30 "GtkStatusIcon": wrapStatusIcon,
31 } {
32 WrapMap[k] = v
33 }
34}
107func (s *Survey) Init(length, intval int) {
108 s.sent.Init(length/intval, intval)
109 s.recved.Init(length/intval, intval)
110 s.latencyMin = -1
111}
21func init() {
22 netPkg := ast.MakePackage("tcp")
23
24 dialerStrct := ast.MakeStruct("Dialer")
25
26 netPkg.AddStruct(dialerStrct)
27
28 ast.PROGRAM.AddPackage(netPkg)
29}
16func init() {
17 tm := []glib.TypeMarshaler{
18 // Enums
19 {glib.Type(C.cairo_gobject_region_overlap_get_type()), marshalRegionOverlap},
20
21 // Boxed
22 {glib.Type(C.cairo_gobject_region_get_type()), marshalRegion},
23 }
24 glib.RegisterGValueMarshalers(tm)
25}
2340func (p *pooler) init() {
2341 p.sf8.New = func() interface{} { return new([8]structField) }
2342 p.sf16.New = func() interface{} { return new([16]structField) }
2343 p.sf32.New = func() interface{} { return new([32]structField) }
2344 p.sf64.New = func() interface{} { return new([64]structField) }
2345 p.sf128.New = func() interface{} { return new([128]structField) }
2346 p.dn.New = func() interface{} { x := new(decNaked); x.init(); return x }
2347 p.tiload.New = func() interface{} { return new(typeInfoLoadArray) }
2348 p.cfn.New = func() interface{} { return new(codecFner) }
2349}
176func init() {
177 pool.init()
178}
38func (p *PtrKindNode) initialize(field string, parent NodeInterface, t reflect.Type, rt *ResourceTree) {
39 p.NodeData.initialize(field, parent, t, rt)
40 p.objKind = t.Elem().Kind()
41}
68func init() {
69 var memStats MemStats
70 if sizeof_C_MStats != unsafe.Sizeof(memStats) {
71 println(sizeof_C_MStats, unsafe.Sizeof(memStats))
72 throw("MStats vs MemStatsType size mismatch")
73 }
74}

Related snippets