课程: Treating Go as an Object-Oriented Language

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Creating a struct

Creating a struct

- [Instructor] So now it's time to create a struct together in our IVs. So I want you to open up the exercise files to the beginning of this and you'll have an empty project other than a few read mes and other things. We are going to create a file and it's going to be called main.go right at the root. Now I'm going to rename the package here to main and I'm going to create a main function and we'll leave it empty for right now. We will get to that here in a little bit. Now we're going to create a new directory also called a package. And we are going to call this pets. And in the pets package let's create a new go file called dog. Now in our dog file we are going to create a type. A type of dog and it will be a struct. Now to this we're going to add some elements. So we will put a name. Our dog needs a name. Our dog will have a color and our dog will have a breed. Now let's add our first function onto this dog. So the…

内容