1, create new project "test8_method"

$ cd ~/project
$ mkdir test8_method
$ cd test8_method
$ touch method.go

2,add following lines in “method.go”

package mainimport ("fmt"
)type Book struct {author stringpublish uint64
}type Bus struct {startStation stringterminalStation string
}type Number intfunc (book Book) printInfo() {fmt.Println("Book", book)
}func (bus Bus) printInfo() {fmt.Println("Bus:", bus)
}
func (bus *Bus) printInfoP() {fmt.Println("BusP:", bus)
}
func (bus Bus) changeInfo() {bus.startStation = "Unseo" // this line will not change bus.startStation when return
}
func (bus *Bus) changeInfoP() {bus.startStation = "Unseo" // this line will change bus.startStation when return
}func (n Number) selfAdd() (r Number) {r = n + 1return
}func main() {// TEST 1, methodvar _book = Book{"Henry David Thoreau", 1854}var _bus = Bus{"Souel", "Incheon"}var _n = Number(3)_book.printInfo()_bus.printInfo()fmt.Println(_n.selfAdd())// TEST 2, method and pointervar _busP = &Bus{"Incheon", "Souel"}fmt.Println("_bus:", _bus)fmt.Println("_busP:", _busP)_bus.printInfo()_busP.printInfo()_bus.printInfoP()_busP.printInfoP()_bus.changeInfo()_busP.changeInfo()fmt.Println("_bus:", _bus)fmt.Println("_busP:", _busP)_bus.changeInfoP()_busP.changeInfoP()fmt.Println("_bus:", _bus)fmt.Println("_busP:", _busP)
}

3, run “method.go”

go run method.go

you should get result like this:

Book {Henry David Thoreau 1854}
Bus: {Souel Incheon}
4
_bus: {Souel Incheon}
_busP: &{Incheon Souel}
Bus: {Souel Incheon}
Bus: {Incheon Souel}
BusP: &{Souel Incheon}
BusP: &{Incheon Souel}
_bus: {Souel Incheon}
_busP: &{Incheon Souel}
_bus: {Unseo Incheon}
_busP: &{Unseo Souel}

create Golang project with method相关推荐

  1. create Golang project with interface #1

    1, create new project "test9_interface" $ cd ~/project $ mkdir test9_interface $ cd test9_ ...

  2. SRPG游戏开发(三十一)第八章 游戏中的数据 - 一 创建新项目(Create New Project)

    返回总目录 第八章 游戏中的数据(Data in Game) 在之前的章节中,我们进行地图对象的生成,移动等操作. 这一章本来可以进行战斗的编写,不过数据缺失是一个问题. 所以这一章我们先来建立一些数 ...

  3. fatal: Unable to create ‘D:/project/.git/index.lock‘: File exists

    git 命令行报错:fatal: Unable to create 'D:/project/.git/index.lock': File exists 出现这种错误 解决办法: //在git bash ...

  4. Golang rpc:service/method request ill-formed错误

    Golang rpc:service/method request ill-formed错误 在学习golang中rpc的时候遇到了这个错误,无法成功远程调用方法 这里是我想要远程调用的函数的签名部分 ...

  5. python 正则表达式生成_Python Create Re Project (python自动生成正则表达式项目)

    CreateRe Python生成正则表达式模块,此模块用来逆向的生成正则表达式.只需要传入待匹配的字符串,以及预期想要匹配出的结果列表,即可以生成一个正则表达式. 当然目前模块还不够成熟,具体表现在 ...

  6. create maven android project

    2019独角兽企业重金招聘Python工程师标准>>> Getting Started The Android Configurator is an Maven Integratio ...

  7. golang物联网_使用golang谷歌云平台和grafana监控物联网设备

    golang物联网 In this article, we'll be setting up step by step, a monitoring environment for IoT device ...

  8. golang微信机器人_如何使用Golang从头开始创建Twitter机器人

    golang微信机器人 by Kofo Okesola 由Kofo Okesola 如何使用Golang从头开始创建Twitter机器人 (How to create a Twitter bot fr ...

  9. 使用 VS Code 快速搭建 Golang 开发环境

      刚开始接触 Golang 时使用的是 Eclipse + Goclipse 开发环境,但是你懂的,Eclipse的体量有点大,当有一个非常好的 idea 时 Launch and Create t ...

最新文章

  1. 物体检测中的评价指标【文末赠书】
  2. Java的API及Object类、String类、字符串缓存区
  3. Book Review 《构建之法》-2
  4. [导入]C++ GUi 选择
  5. 计算机网络网关作用,默认网关的作用
  6. 面试时如何介绍自己的项目经验
  7. HTTP协议具体解释
  8. 12 操作系统第三章 内存管理 非连续分配管理方式 基本分页存储管理 基本分段存储管理 段页式存储管理
  9. Oracle view 小结片段
  10. Spring官方阅读笔记-@Controller官方解析与实例(5.0.12)
  11. 计算机老师任课教师寄语,任课老师寄语大全
  12. python dataframe索引转成列_如何将 Pandas DataFrame 的索引转换为列
  13. hpml350服务器安装系统,安装HP ML350
  14. linux off_t类型的头文件,linux下32位机与64位机基本数据类型长度对比
  15. 【深入理解JVM】:Java对象的创建、内存布局、访问定位
  16. ACM 学习笔记(三) 数学入门
  17. Ubuntu 解压缩
  18. 从离职之日起,一年内仲裁
  19. 毕设项目 - 基于SSM的房屋租赁系统(含源码+论文)
  20. c语言.jpg图片转成数组_如何把PDF图片转成JPG?两个方法快速搞定PDF转图片!

热门文章

  1. Java开发必学:java核心技术电子书资源
  2. 语音信号处理 | Python实现端点检测
  3. eclipse安装angularjs
  4. 小程序实现猜数字游戏
  5. windows虚拟桌面_在Windows中使用虚拟桌面的最佳免费程序
  6. requests-html 爬虫新库
  7. 信息管理与信息系统考研专业方向计算机,信息管理与信息系统考研专业方向
  8. 入侵网站的黑客被我抓到了!
  9. 试题 算法训练 盾神与离散老师2
  10. uniapp离线打包SDK