Sep 7, 2021 · Creating a struct. Yes, this is the correct solution and there are several advantages of choosing such solution. Oct 2, 2014 · Go has a few differences. May 24, 2015 · The common pattern is to provide a New method that initializes your fields: myType := &MyType{} myType. Sep 30, 2014 · Golang is not OOP language in its official documents. In this post, we will go through the different types of constructors that we can use in Go, and in what situations you should use them. Structs in Golang Structs or Structures in Golang are the sequences or Defining a struct type. The receiver, the struct itself, is a parameter that provides access to its own fields. We show how to initialize struct types in Go. 1. You can initialize a struct value using: resource := struct2{} As @nothingmuch pointed out, if you have a struct pointer and need the underlying value, you can dereference the pointer using: deref := *resource. Aug 30, 2021 at 17:12. r. } We created a struct named Rectangle with length and breadth data fields of type float64. Structs are user-defined types. This statement retrieves the value stored under the key "route" and assigns it to a new variable i: i := m["route"] If the requested key doesn’t exist, we get the value type’s zero value . In src folder, create new file named main. This concept is generally compared with the classes in object-oriented programming. Example 1: package main. A struct is used to store variables of different data types. A common used pattern is. Struct literal syntax is just assigning values when declaring and it is really easy. See this question for more details + practical examples: Keyed items in golang array initialization Nov 29, 2017 · 106. Sprintf("A: %s, %s, %s", p. The same story with Jan 19, 2022 · You can, do something like this by embedding a common struct in both PersonA and PersonB. Oct 1, 2019 · fmt. Jan 10, 2019 · I did google the question, learnt a new word "avtovivification", but still failing to see the reason. As was said, Go does not support constant struct variables. answered Dec 13, 2016 at 7:06. The general syntax for initializing an array of structs is as follows: var arr [n]struct {. Given that, there is no sense in what you want to do. containing a pointer). However, if you have some struct: package main. It’s a smallest building block in Go. 00 PM"}) or. Name string. Op *Operation. field1 type1. To create a struct, we will use the type keyword in Go, then define its name and data fields with their respective data types: type Rectangle struct {. As long as the state of the Once object is not changed, the supplied function will only be called once. It would be easier to just initialize these embeds by composite literal, and default remaining (unspecified) fields to zero values so as to set them appropriate later. go as below: package entities type Product struct { Id string Name string Price float64 Quantity int Status bool } Application Create new folder named src. Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand Aug 11, 2017 · For further clarification, anonymous structs are ones that have no separate type definition. , then this Feb 6, 2013 · Go provides a familiar syntax for working with maps. For example (playgound link):package main import "fmt" type commonPerson struct { A string B string C string } type PersonA struct { commonPerson } func (p PersonA) String() string { return fmt. Question ¶ There are multiple ways to initialize a struct in Go: Nov 18, 2019 · When there is logic between keys and values, you may also use a loop to initialize the map. go as below: package main import ( "entities" "fmt" ) func main() { var products = []entities. First off, you can't initialize arrays and slices as const. When creating structs with literals, we have to initialize the embedding explicitly; here the embedded type serves as the field name. It's not possible to get the address (to point) of a constant value, which is why your initialization fails. Jan 14, 2022 · From Effective Go, to cast an interface to a struct, we can make use of the syntax notation below: v = x. Power. } To be able to initialize you need to input a type to the interface and not an array of type, so suggest you to change as follow: type Pixel struct {. The list should be defined as var instead. However, suppose we want to store the same information of multiple people. The second. Rather than creating a structure directly, we can use a constructor to assign custom default values to all or some of its members. You can use make () to allocate the slice in "full-size", and then use a for range to iterate over it and fill the numbers: tmp := make ( []LuckyNumber, 10) for i := range tmp { tmp [i]. Basically, it is used to group related data together to form a single unit. When instantiating with keys, you would write the value of each field name next to the field name like such: type Employee struct { name string age int boss bool } employee := Employee{name: "John", age: 30} Each element of such a variable or value is set to the zero value for its type: false for booleans, 0 for integers, 0. Dec 21, 2010 · You just need a constructor. Go’s structs are typed collections of fields. } The reason your program panics is because you're trying to access an area in memory (an item in your Object s array) that hasn't been allocated yet. A struct variable in Golang can be copied to another variable easily using the assignment statement(=). May 18, 2021 · I have the following struct: type InstructionSet struct { Inst map[string]interface{} } In the Inst map I'd like to put something like. Access struct using pointer in Golang. 📌. Less typing, and clearer code. In conclusion, mastering the use of structs in GoLang will equip you with a powerful tool to organize and manage data in your programs. A structure or struct in Golang is a user-defined type that allows to group/combine items of possibly different types into a single type. I have listed down some of them: To declare a struct, you can create a new variable and assign it the type of the newly created struct. Zero value of the string type is the empty string "". B, p. Using struct Literal Syntax. The built-in function new takes a type T, allocates storage for a variable of that type at run time, and returns a value of type *T pointing to it. How can I define and access people inside the struct? Aug 30, 2021 · 2. Apr 4, 2020 · Those who are new to Golang are often troubled by the struct in Golang, whether it's the initialization method, various data types, or the combination of structs, all of which are quite different from other languages they have encountered before. "fmt". This may be significantly shorter than using a composite literal enumerating all key-value pairs, especially if the number of key-value pairs is big. Note that the &T{} syntax is only allowed when T is a Jan 10, 2019 · 10. There are a few ways we could do that. 177. For arrays of structs, this needs to be done with make. e they can be modified throughout the Oct 17, 2015 · Nov 5, 2014 at 1:11. Address string. pattern names. Intn (100) } a := Person {tmp} fmt. The calls to nextNumber() are operands in the expression. e1 := Event{Id: 1, Name: "event 1"} is initializing the variable e1 as a value with type Event. Cheers, Fango golang initialize or new struct with default value Topics go golang new function golang-library default-value defaults initializer default golang-examples Mar 15, 2016 · 1. An empty string ("") for the name & favorite color field and an a zero (0) for the age. Mutex)} This code fails to compile: So basically the question is how to refer to the struct itself (because it has an embedded member sync. Sep 1, 2020 · In golang, there's to ways to instantiate structs: with keys and without keys. type Define struct {. Or, by using field:value initializers for any number of fields in. Any changes made to the second struct will not be reflected back to the first struct. Jul 28, 2017 · type important struct { client string `json:"client"` Response Summary `json:"response"` } type Summary struct { Name string `json:"name"` Metadata Clie Jul 25, 2013 · The zero value of a mutex should be a ready-to-use mutex, so you're good simply including it as an embedded value: var hits struct { sync. type Vertex struct {. If a value receiver is used or the struct value is copied, go vet (which runs on any test) will pickup the incorrect usage. New(something) to instantiate an object without actually just instantiate the struct the usual way, as that something is supposed to be passed in to the code from a function parameter. newPerson constructs a new person struct with the given name. You would likely write something like this. Jun 20, 2018 · The Go Object Lifecycle. edited Mar 15, 2016 at 2:54. – Apr 11, 2023 · Nested Structure in Golang. In Golang, you can have constructor-like factory functions (like the one you defined above) to initialize default values when initializing structs. Println(console) Output: This pattern is widely used in golang, but I believe this is not useful for initializing structs embedded in other structs, only for creating new pointers to them. Jun 7, 2017 · return &someThing{cv:sync. Go is a very consistent language: it always automatically initializes variables: A variable's value is retrieved by referring to the variable in an expression; it is the most recent value assigned to the variable. To declare a struct in Golang, you use the type keyword followed by the name of the struct and the struct keyword. Golang Struct Initialization. v := "my:default". From the section on composite literals: The fields of a composite literal are laid out in order and must all be present. If a variable has not yet been assigned a value, its value is the zero value for its type. If you have anonymous, unnamed struct types, you can only initialize them with composite literals if you repeat the struct definition. return &p. Also that could just be var mutex sync. Consider the following codes. Despite such a simple language, Go developers have found a surprising number of ways to create and use objects. return myType. area int. dalton_c. May 5, 2013 · 6. Typical for Go: Write several lines, each lines doing one thing instead of one monster line doing everything. Oct 21, 2011 · I want it to take the struct itself (not its instantiated object), get its type, and instantiate it using reflection. //Define declare variables. The variable is initialized as described in the section on initial values. The method set of any other named type T consists of all methods with receiver type T. At first, I thought they were different but they are not. Go struct. But Go has structs. See this bit of effective go: Sep 17, 2017 · Similarly, slices cannot be re-sliced below zero to access earlier elements in the array. Mutex, there's no need for a pointer, same for the int values, there's no need to set them to 0, so that example you found could be improved. Print("mine is empty") I wanted to shorten this a bit so I moved the empty struct initialization into the if statement: Feb 15, 2018 · How do I initialize a struct with a double pointer field? I am trying to initialize a struct as below: type atype struct { val string } a := &struct { StringValue string Pointer ** May 14, 2016 · Initialization vs. age int. You want to create a generic anonymous type and instantiate it right away. co := container{ base: base{ num: 1, }, str: "some name", } We can access the base’s fields directly on Feb 26, 2023 · There are two ways to fix the problem. a. import ("fmt"; "math") func distance(x1, y1, x2, y2 float64) float64 {. This option allows us to declare and initialize an instance of a struct with fields having “zero” values. type Config struct {. Field = "default". field2 int. UserName string `json:"user_name"`. You don't need to name the fields in the data part, and you only need one string definition which can make it shorter if you want id := struct {name, ltype, value string}{name, ltype, value} – Nick Craig-Wood. Jan 12, 2010 · Max_retry int = 3. In this case, creating variables for a person might be a tedious task. The code TwoNumbers{a: nextNumber(), b: nextNumber()} is a composite literal expression. u := User{. Nov 22, 2013 · They explain about making zero-value structs a useful default. breadth float64. Type parameters are introduced so when you instantiate the type, you can give concrete types to type parameters. If you need to store the null value, use a pointer to string. e2 := &Event{Id: 1, Name: "event1"} Jan 1, 2020 · Creating and initializing a Struct in Golang. But remember that you cannot compare structs that contain non-comparable fields such as maps. g. – JimB. In this post we’ll look at a 3-step approach to object management—instantiation, initialization, & initiation. For example, Suppose we want to store the name and age of a person. empty := MyStruct{} // Check if mine is empty. Sep 9, 2023 · Inline structs in Go are declared and initialized directly within a function or code block using a compact syntax without specifying a struct name. Unable to initialise embedded struct. Let’s first take the following as an example of code without the init() function: Apr 11, 2023 · Last Updated : 11 Apr, 2023. Compare structs. var person1 Person When I create a variable and assign a type of the struct, Golang will add default values. LastName string `json:"last_name"`. Because really Go stores only a number of them in the slice but not them itself. Y int. This article will sort these out. Initialization is a more general term, whereas if you are set the fields (properties, etc. So, in the case of maps, there is no difference between using make and using an empty map literal. For the sake of completeness: For initialization work besides of the init function in a package there is sync. Apr 18, 2023 · To define a structure in Golang, you use the struct keyword, followed by a list of field names and their respective data types, enclosed in curly braces. The specification says this about expressions in general: when evaluating the operands of an expression, assignment, or return statement Oct 12, 2020 · Moreover, you can't define default values for struct fields. So, a structis a user-defined type that contains a collection of named fields. Oct 18, 2013 · The first expression returns value which is an initialized Vertex struct. In essence, T must implement the interface type of x. Sep 30, 2023 · One of the main benefits is enhanced code efficiency. // If no special logic is needed. An example of declaring an inline struct might look like this: data := struct { field1 int field2 string }{ field1: 10, field2: "example", } Structure Initialization Dec 13, 2016 · 0. Now, we will create structs and initialize them with values. Providing the values for each (and every) field in order, eg. Mar 3, 2017 · 23. You create an Once object and call Do with your function on it. Structs in Golang are mutable i. name string. Type (and your other fields) have a default of zero, then Go struct literals already give you exactly the feature you're requesting. Inside the curly braces, you define the properties with their respective types. return powers. if mine == empty {. Proxy struct {. For example, a field of type string gets an empty (“”) string, an integer initializes to zero, a boolean gets false, etc. fmt. The Go language doesn’t have any concrete “constructor” as such, but we can use a number of different language features to idiomatically initialize variables. So instead use named struct types, so you can use them in composite literals like this: Types: type domain struct {. ) of a struct or a variable to its type default such as 0, nil, "", false, etc. Any real-world entity which has some set of properties/fields can be represented as a struct. Solution is rather simple: just use normal variable: type Person struct {. This initialization is done recursively, so for instance each element of an array of structs will have its fields zeroed if Feb 5, 2019 · To copy a complete struct value, just assign the struct value. You can't use this anonymous struct elsewhere (because it's anonymous), so leave out the type Initializing structures that contain any type of pointer fields, including recursive struct fields; Preventing panics by ensuring that all fields of a struct are initialized; Initializing golang protobuf struct (the golang protobuf makes heavy use of pointers to embedded structs that contain pointers to embedded structs, ad infinitum) Mar 4, 2017 · 94. The term const has a different meaning in Go, as it does in C. An anonymous struct is a struct with no associated type definition. import "fmt". Unlock() (from 10 things you probably didn't know about Go) – Flowchartsman. 0 for floats, "" for strings, and nil for pointers, functions, interfaces, slices, channels, and maps. This syntax of initializing values without referring to the type is essential to making the manageable: Aug 15, 2020 · We'll start with a simple example demonstrating the embedding of a struct in another struct: type Base struct { b int } type Container struct { // Container is the embedding struct Base // Base is the embedded struct c string } Instances of Container will now have the field b as well. In entities folder, create new file named product. Unless given with a composite literal, all fields will get their zero values. return &SyncMap{hm: make(map[string]string)} } In case of more fields inside your struct, starting a goroutine as backend, or registering a finalizer everything could be done in this constructor. "Put" the logic into the loop body. Here's a basic syntax followed by an example: type StructName struct {. } type user2 struct {. return &Console{X: 5} fmt. This is just because Go has no classes, no objects, no exceptions, and no templates. In the previous section, we discussed how to define a struct in Golang. For example, the type [4]int represents an array of four integers. breath int. Go language allows nested structure. Val string. Product Feb 21, 2022 · A structure or struct in Golang is a user-defined data type that allows to combine data types of different kinds and act as a record. You can view the code Dec 30, 2023 · Two structs are only equal if they are of the same type and all their fields have the same values. The zero value is: Aug 14, 2022 · How to initialize nested struct in golang? 0. To define a zero value golang struct , create a variable name and initialize it with the struct name followed by parenthesis e. Note that inside the for I did not create new "instances" of the An embedding looks like a field without a name. A struct is a typed collection of fields, useful for grouping data into records. How to initialize a struct? Aug 24, 2016 · 4. (T) Here, x is the interface type and T is the actual concrete type. id string. There is no char type in Go. } func init() {. g var user1 user. type container struct { base str string } func main() {. The first and preferred way is to initialize the value in the variable declaration using a composite literal. Most Go code will use a mutex value to ease in struct value initialization and also prevent accidentally sharing mutexes. This statement sets the key "route" to the value 66: m["route"] = 66. Name = "Alice" // a == Student{"Alice", 0} Aug 28, 2019 · The first method. Simply speaking, zeroing is a form of initialization. An array type definition specifies a length and an element type. Uri *string. type Configuration struct {. default values will be overridden. Instantiating struct using constructor of embedded Apr 11, 2024 · Go initialize struct. X float64. If you define a variable and pass its address, your example will work. It is followed by the name of the type ( Person) and the keyword struct to indicate that we’re defining a struct. Empty struct struct{} is realized in a special way in Go. Structs and Interfaces. Apr 12, 2017 · 0. Golang's community suggest New. Methods are added outside the struct. Inst["cmd"] = "dir" Inst["timeout"] = 10 Now I'd like to initialize it directly from code, but I'm not finding the proper way to do it Sep 19, 2022 · A constructor is a language feature that is used to initialize variables. A structure or struct in Golang is a user-defined type, which allows us to create a group of elements of different types into a single unit. Slice e. Age int }{ Name: "Alex", Age: 35} // employee is defined, initialized, and ready to use here. A struct consists of both built-in and user-defined types (struct itself is a user-defined type). Jul 7, 2021 · These methods of defining structs in Golang are referred to as Named Structs, as it involves assigning a name to each of the defined structs. You may us make to initialize the slice with capacity and assign with index or use append to add values to slice. 2. Or, I want to somehow uses reflect. you may create a slice of 1000’s empty structures and this slice will be very tiny. number = rand. } var a Student // a == Student{"", 0} . The struct fields are initialized with the values provided between the curly brackets. } Mar 10, 2022 · You have used a slice instead of an array here, so you would need to append to the slice. Age int. A struct is a collection of multiple data fields with their defined data types grouped together. If you need assign some fields some special values, use factory functions. If you ever want to append or insert any values however, I suggest you avoid the anonymous structs and just stick with the standard named types to avoid having to write the struct type out every time. Struct types. len int. Secondly, as a style rule, Go prefers basenameOpts as opposed to basename_opts. ) type Student struct{. Syntax for initializing an array of structs. type Person struct{ FirstName string LastName string Age int} The type keyword introduces a new type. An array’s size is fixed; its length is part of its type ( [4]int and [5 Aug 5, 2016 · To create and initialize a variable to the value [3]int{369, 0, 963}, you may also do it like this: // Value at index 1 implicitly gets 0: g := [3]int{369, 2: 963} h := []int{369, 2: 963} Try all the examples on the Go Playground. var day = make([]DayAndTime, 1) day[0 Dec 22, 2020 · If you are writing a single literal value, then the syntax is the same as if you were using a named struct type. Both are valid code. In this post, we are going to take a look at Go’s init function. For instance, a receiver function is needed which will have a reference to the struct, to allow it to operate on the structs’ data. The size may be omitted, in which case a small starting size is allocated. We can create two variables: name and age and store value. literals", you can construct structs using { } syntax in two ways: 1. This person struct type has name and age fields. NewCond(sync. Aug 14, 2015 · T {size:1} return T. type user1 struct {. } type Pixels []Pixel. . n++ hits. I am not talking about struct literal. Mar 25, 2022 · Option 3 – Create a Blank Instance of a struct. In the latter it should probably be added to whatever code is composing the value. Combined with exporting it allows you to encapsulate initialization by hiding specifics of calculation from callers: package main. day = append(day, DayAndTime{"Monday", "8. My issue is that the obj := make([]*mystruct, 15) creates a slices of 15 *mystruc pointers initialized to nil; which causes the code within the for loop to raise a panic of type "invalid memory or nil pointer dereference Jun 12, 2023 · This way of initialization is handy to set all the field values at once. employee := struct {. var mine MyStruct. If you have a function receiving a non-pointer Person, that is already a copy, so just return its address: func copyPerson(p Person) *Person {. Finally, we have option 3. type Student struct { Name string. Any real-world entity which has some set of properties or fields can be represented as a struct. We will be understanding the basics of operating on structs like declaration, initialization and adding functional logic into those structs. u := User{"John Doe", "gardener", 34} A new User struct is created. } That's all, this will copy all present and future fields of Person. Port string. You can define a new struct type like this -. We’ll also contrast this with other methodologies for creating and using objects and we’ll Jun 22, 2020 · Default values can be assigned to a struct by using a constructor function. Y float64. FirstValue string. SecondValue *string. For example, // Program to access the field of a struct using pointer package main import "fmt" func main() { // declare a struct Person type Person struct { name string age int } person := Person{"John", 25} // create a struct type pointer that // stores the address of person var ptr Arrays. Yes, you can explicitly initialize a map by providing values such as m := map[int]int{1: 1}. var Comma = Symbol{Name: "Comma", Format: ","} The second way is to move the assignment statements to an init function: Comma. Mar 4, 2014 · 12. From the docs for the make keyword: Map: An initial allocation is made according to the size but the resulting map has length 0. Note that x is usually a dynamic type, and its value is known at runtime. If you don't want to go with separate struct definition for nested struct and you don't like second method suggested by @OneOfOne you can use this third method: package main. Adding a Method. Once, which runs a supplied function only once. Go struct initialization. In all these cases the zero value is fine. Now, let’s dive into the crucial step of initializing a struct. powers[i] = s. dude := Employee { Person {"Me"}, 1 } 2. Mar 31, 2013 · Go doesn't have implicit constructors. If the second structure is a clone of the first one with fewer fields you can convert the structures via json. Jul 31, 2020 · Introduction. If you're coming from an objected-oriented background, think of structs as lightweight classes which that support composition but not inheritance. These are anonymous types, but not anonymous structs. } var Luke = Person{10} You can also use anonymous struct: Jan 1, 2024 · A zero value golang struct has its corresponding field values set to their respective zero value. They’re useful for grouping data together to form records. g user1 := user{} or use a keyword var followed by the variable name , followed by the struct name e. Apr 14, 2022 · Structs are an important aspect of programming in Golang, they provide a way to define custom types and add functionality to them. Consider a program that interacts with shapes: package main. A, p. Field1 FieldType1. Println(extractpowers(obj)) powers := make([]int, len(obj)) for i, s := range obj {. Apr 14, 2019 · Entities Create new folder named entities. Its a shame - that struct is embedded inside another struct in my code, so initializing this There are two ways to initialize an array of structs in Golang: Initializing an array of structs with zero values. We can also access the individual member of a struct using the pointer. Mar 14, 2010 · If so, as described in Effective Go, "Constructors and composite. Mutex n int } hits. If you can make Object. Although it would be possible for us to write programs only using Go's built-in data types, at some point it would become quite tedious. length float64. Name = "Comma". What is the init function in Golang? The init function is a function that takes no argument and returns nothing. It’s size is literally 0 bytes. Initializing an array of structs with specific values. {op: new (Operation)} If field values are provided during construction time, then the. In Go you probably will not find a proper way to define composition or aggregation as you may find in many other languages that are OOP based. In the spec it's called a promoted field. This has a reason, compiler cannot ensure immutability of any struct (e. This is very inconvenient. Finally, if you can work it out you should make the zero values of your struct sensible defaults Nov 24, 2015 · Objects []MyStruct. Here's a simple example of defining a Mar 20, 2022 · 5. var day []DayAndTime. // return &myType{"default"} Alternatively, you can return a non-pointer type. a := x2 – x1. It allows doing things like initialization of a package that otherwise really hard to achieve. Oct 16, 2014 at 20:27. Println (a) Try it on the Go Playground. Anonymous structs allow you to define, initialize, and use a data structure all at once without having to declare a new type. object and the rest would be initialized to default as s := MyStorage. Example Syntax. Nov 22, 2021 · The evaluation order of the function calls is specified. FirstName string `json:"first_name"`. In the former case, adding a new parameter may involve adding a new field initializer. Zeroing. With 6g's alignment rules, this means that you will get 8+8 = 16 bytes worth of Vertex struct, since every float64 is 8 bytes in size. If it has zero size. C) } // This function is just here so that PersonA implements 0. In this case, the order of the fields is relevant. func NewSyncMap() *SyncMap {. Such as. A mutex does not need initialization. Objects = make([]MyStruct, 0) Then, in order to add to your array safely, you're better off instantiating an Sep 26, 2019 · Any time you declare an init() function, Go will load and run it prior to anything else in that package. 0. import (. Nov 5, 2014 at 7:19. Mutex) while initializing it ? (c++ has this, for example). } In struct construction, I then only need to provide the Operation. I prefer {} when the full value of the type is known and new() when the value is going to be populated incrementally. A structure which is the field of another Nov 24, 2021 · 6. Sep 13, 2023 · Declaring A Struct. var list []person is a slice. Example 1: // Golang progr May 13, 2018 · Go has the concept of "Constructors" that may cover your use case. X int. The slice type is an abstraction built on top of Go’s array type, and so to understand slices we must first understand arrays. Zero value for pointers is nil: type Values struct {. The second expression allocates memory, enough for 8+8 = 16 bytes, uses it as a Vertex struct, initializes it and returns a pointer Sep 12, 2010 · Suppose the Job is a much larger struct embedding *log as the first field, and maybe more embeddings follow. 2 ways to create and initialize a new struct. g: package main import "fmt" type person struct { name string age int } var n int var p person var list []person func main() { //Enter your code here. . The following works as expected: field1 string. Lock() hits. All fields of Golang struct has a determined value(not like c/c++), so constructor function is not so necessary as cpp. Your example can be implemented with this: May 3, 2020 · 1. They are useful for grouping data together to form custom records. To demonstrate this, this section will walk through how to define an init() function and show the effects on how the package runs. The struct contains a list of fields inside the curly In this tutorial, we will learn about structs. Jun 11, 2018 · Suppose I have a struct named Test, type Test struct { Value1 int `json:"value1"` Value2 int `json:"Value2"` People map[string]string `json:"Value3"` Timeupdate string `json:"Timeupdate"` } and people variable is a collection of key value pairs. var config = Config{ Uri: &v } Feb 7, 2020 · The init function is a powerful function in Go. dc ge dr ju jz bp hn tf go mm