https://github.com/tobychui/golang-oop-example
A very basic example showcasing the use of go module and struct for OOP in Golang project
https://github.com/tobychui/golang-oop-example
Last synced: 10 months ago
JSON representation
A very basic example showcasing the use of go module and struct for OOP in Golang project
- Host: GitHub
- URL: https://github.com/tobychui/golang-oop-example
- Owner: tobychui
- Created: 2020-08-10T13:06:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-10T13:18:05.000Z (over 5 years ago)
- Last Synced: 2025-01-18T02:25:51.472Z (11 months ago)
- Language: Go
- Size: 1.05 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Golang-OOP-Example
A very basic example showcasing the use of go module and struct for OOP in Golang project
## Qestions you might want to ask
1. Why the import module is "GoOOP/demo/printer" instead of just "printer" or "Golang-OOP-Example/printer"?
It is because this project is initialized with
```
go mod init GoOOP/demo
```
2. Why the compiled binary is named "demo.exe" instead of the folder name "Golang-OOP-Example.exe"?
It is because this project is initialized with
```
go mod init GoOOP/demo
```
and the go build command will use the last section of the module name as the binary executable name.
3. If I am starting a new project, how can I name my module?
Use the go mod command as follows.
```
go mod init {your module name}
/*
Example of module names:
github.com/tobychui/mymodule
mydomain.com/mymodule
anything/you/want
*/
go mod tidy
```
4. Why the module has to be initialize with ```p := printer.NewPrinter("Tim")``` instead of other module name?
You can choose to import "GoOOP/demo/printer" with other names like
```
import (
magic "GoOOP/demo/printer"
)
```
and call to the imported module using
```
p := magic.NewPrinter("Tim")
```
## Questions?
Feel free to open a new issue and I will add your Q&A into the README.md file.