在golang中,如果要实现private/public的话,则需要使用到golang中的export/unexport,而这个要注意几个事情
package util
import (
"fmt"
)
func Print() {
fmt.Println("hello")
}
如果需import上述的档案,下面两种方式皆可
package main
import (
"first-project/test"
)
func main() {
util.Print()
}
或是
package main
import (
test "first-project/test"
)
func main() {
test.Print()
}
以下内容会放在下述连结中,可搭配观看
https://github.com/kevinyay945/ithelp-2021/tree/master/go-package
我在其中建立了以下档案
主程序为main.go,而我在里面做了几件事
呼叫util里的
PrintHelloWorld()
并把里面宣告的
util.ExportedVar
util.Var1.ExportedProperty
util.Var1.unexportedProperty
util.unexportedVar
印出
但在最下面两句,会发生取不到unexported的值
可以试着将下面两句注解解开,看看有什麽错误发生
Agenda 资安宣言 序 系列与规划 下期预告 资安宣言 撰写本系列文章目的在於提升资讯安全之实务...
一. self-attention的编码方式 昨天说明了注意力主要是要明确算出input与outpu...
前言:讲解完了基础的排序法後,接着要来讲解比较高等的排序法,今天和明天要介绍的都是始於分割资料的排序...
在讲else、elif之前,先来让我们看看什麽是"if" 程序码如下: [In]...
有效的使用 Observability 的资料 系列文章 (1/4) - 透过 Machine Le...