跨包引用
This commit is contained in:
32
main.go
32
main.go
@@ -4,11 +4,17 @@ package main
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitea.ww3.tw/skimrme/go_test/packages"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
// 蓝图思想萌发
|
// 蓝图思想萌发
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
hello_world() // hello_world表
|
hello_world() // hello_world表
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -23,9 +29,35 @@ func hello_world() {
|
|||||||
var age int // 变量的数字可以不用引号
|
var age int // 变量的数字可以不用引号
|
||||||
age = 32
|
age = 32
|
||||||
|
|
||||||
|
|
||||||
//fmt.Printf("\nHello World\n") // 划重点print的p要大写
|
//fmt.Printf("\nHello World\n") // 划重点print的p要大写
|
||||||
fmt.Print(H_W) // 变量的print不用f
|
fmt.Print(H_W) // 变量的print不用f
|
||||||
fmt.Print(换行) // 变量可以用中文,但是不建议
|
fmt.Print(换行) // 变量可以用中文,但是不建议
|
||||||
fmt.Print(age)
|
fmt.Print(age)
|
||||||
fmt.Print(换行) // 变量可以用中文,但是不建议
|
fmt.Print(换行) // 变量可以用中文,但是不建议
|
||||||
|
|
||||||
|
// 多个顺序变量
|
||||||
|
var a1,a2 int
|
||||||
|
a1,a2 = 1,2
|
||||||
|
fmt.Print(a1,a2)
|
||||||
|
fmt.Print(换行)
|
||||||
|
|
||||||
|
// 多个变量集合
|
||||||
|
var (
|
||||||
|
b1 string = "bitch1"
|
||||||
|
b2 string = "bitch2"
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Print(b1,b2) // string类型不会自动空格 int类型会
|
||||||
|
fmt.Print(换行)
|
||||||
|
|
||||||
|
// 常量变量
|
||||||
|
const QwQ string = "2.0.1" // 虽然没搞懂,但是就是这个格式吧
|
||||||
|
fmt.Print(age, "\n" ,QwQ) // 原来可以又有变量又输入文字啊!!!
|
||||||
|
fmt.Print(换行)
|
||||||
|
|
||||||
|
// 跨包使用
|
||||||
|
fmt.Println(stg.Stg)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
4
packages/stg.go
Normal file
4
packages/stg.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package stg
|
||||||
|
|
||||||
|
var Stg string = "STG_TEST" // 可以用
|
||||||
|
var test string = "test" // 用不了,跨包使用要大写
|
||||||
Reference in New Issue
Block a user