Initial commit with methods module
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -18,8 +18,12 @@
|
|||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
#go.work
|
||||||
go.work.sum
|
#go.work.sum
|
||||||
|
|
||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Intellij IDEA files
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
# golang-nutshell
|
# golang-nutshell
|
||||||
|
|
||||||
This repository is a nutshell for Golang
|
This repository is a nutshell for Golang
|
||||||
|
|||||||
1
methods/go.mod
Normal file
1
methods/go.mod
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module nutshell/methods
|
||||||
22
methods/main.go
Normal file
22
methods/main.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
dto "nutshell/methods/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
student := dto.Student{
|
||||||
|
Person: dto.Person{
|
||||||
|
Name: "Joe",
|
||||||
|
LastName: "Doe",
|
||||||
|
Age: 33,
|
||||||
|
},
|
||||||
|
Class: "5A",
|
||||||
|
}
|
||||||
|
showUp(student)
|
||||||
|
}
|
||||||
|
|
||||||
|
func showUp(p dto.Presenter) {
|
||||||
|
fmt.Println(p.Presentation())
|
||||||
|
}
|
||||||
14
methods/models/person.go
Normal file
14
methods/models/person.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
Name string
|
||||||
|
LastName string
|
||||||
|
Age int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Presentation - Greet everyone and show up
|
||||||
|
func (p Person) Presentation() string {
|
||||||
|
return fmt.Sprintf("Hi, everyone! I'm %s %s and I have %d years old.\n", p.Name, p.LastName, p.Age)
|
||||||
|
}
|
||||||
5
methods/models/presenter.go
Normal file
5
methods/models/presenter.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Presenter interface {
|
||||||
|
Presentation() string
|
||||||
|
}
|
||||||
13
methods/models/student.go
Normal file
13
methods/models/student.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Student struct {
|
||||||
|
Person
|
||||||
|
Class string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Presentation - Greet the teacher and show up
|
||||||
|
func (s Student) Presentation() string {
|
||||||
|
return fmt.Sprintf("Good morning teacher, I'm %s %s.\n", s.Person.Name, s.Person.LastName)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user