From c27feedd30daf2ffb9142192f482959f1309564f Mon Sep 17 00:00:00 2001 From: skimrme Date: Sun, 16 Nov 2025 04:17:11 +0000 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E5=8C=85=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- main.go | 34 +++++++++++++++++++++++++++++++++- packages/stg.go | 4 ++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 packages/stg.go diff --git a/.gitignore b/.gitignore index cad2309..1c2f433 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/tmp \ No newline at end of file +tmp \ No newline at end of file diff --git a/main.go b/main.go index 508ff1b..96e656a 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,16 @@ package main import "fmt" +import ( + "gitea.ww3.tw/skimrme/go_test/packages" // 跨包变量引用 应该 建立 go.mod 并且使用 go.mod 里面的 module 中的地址 +) + + // 蓝图思想萌发 func main() { - + hello_world() // hello_world表 + } @@ -23,9 +29,35 @@ func hello_world() { var age int // 变量的数字可以不用引号 age = 32 + //fmt.Printf("\nHello World\n") // 划重点print的p要大写 fmt.Print(H_W) // 变量的print不用f fmt.Print(换行) // 变量可以用中文,但是不建议 fmt.Print(age) 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) // 使用包里面的 单个 go 文件的 package 名字来引用,第二个就是变量了 + + } \ No newline at end of file diff --git a/packages/stg.go b/packages/stg.go new file mode 100644 index 0000000..aa95ae4 --- /dev/null +++ b/packages/stg.go @@ -0,0 +1,4 @@ +package stg + +var Stg string = "STG_TEST" // 可以用 +var test string = "test" // 用不了,跨包使用要大写 \ No newline at end of file