Func函数处理

This commit is contained in:
2025-10-06 17:10:05 +08:00
parent 98e74e07c0
commit 5e7ef46ea6
18 changed files with 228 additions and 0 deletions

8
05 - Calc And Convert/operations/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/operations.iml" filepath="$PROJECT_DIR$/.idea/operations.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,3 @@
module operations
go 1.20

View File

@@ -0,0 +1,16 @@
package main
import "fmt"
func main() {
fmt.Println("Hello,Operations")
add()
}
func add() {
value := 10.2
fmt.Println("value:", value)
value++
fmt.Println("value:", value)
}

View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Collections.iml" filepath="$PROJECT_DIR$/.idea/Collections.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,3 @@
module Collections
go 1.22

View File

@@ -0,0 +1,89 @@
package main
import (
"fmt"
"reflect"
)
func main() {
collections()
collections1()
collections2()
arrayCollection()
arrayCollection1()
}
func collections() {
fmt.Println("\ncollections:")
names := []string{"James", "Bond", "Chloe"}
names = append(names, "Mike", "Mary")
fmt.Println(names)
for i, v := range names {
fmt.Println(i, v)
}
fmt.Println(reflect.TypeOf(names))
fmt.Println(len(names))
fmt.Println(cap(names))
}
func collections1() {
fmt.Println("\ncollections1:")
names := make([]string, 3)
names[0] = "James"
names[1] = "Bond"
names[2] = "Chloe"
fmt.Println(names)
fmt.Println(reflect.TypeOf(names))
fmt.Println(len(names))
fmt.Println(cap(names))
}
func collections2() {
fmt.Println("\ncollections2:")
names := make([]string, 3, 6)
names[0] = "James"
names[1] = "Bond"
names[2] = "Chloe"
appendedNames := append(names, "Mike", "Mary")
names[0] = "James1"
fmt.Println("names:", names)
fmt.Println("appendedNames:", appendedNames)
}
func arrayCollection() {
fmt.Println("\narrayCollection:")
products := [4]string{"Apple", "Banana", "Orange", "Hat"}
someNames := products[1:3]
allNames := products[:]
products[1] = "Mango"
fmt.Println("products:", products)
fmt.Println("someNames:", someNames)
fmt.Println("someNames len:", len(someNames), " cap:", cap(someNames))
fmt.Println("allNames:", allNames)
fmt.Println("allNames len:", len(allNames), " cap:", cap(allNames))
}
func arrayCollection1() {
fmt.Println("\narrayCollection1:")
products := [4]string{"Apple", "Banana", "Orange", "Hat"}
someNames := products[1:3]
allNames := products[:]
products[1] = "Mango"
someNames = append(someNames, "Mike")
fmt.Println("products:", products)
fmt.Println("someNames:", someNames)
fmt.Println("someNames len:", len(someNames), " cap:", cap(someNames))
fmt.Println("allNames:", allNames)
fmt.Println("allNames len:", len(allNames), " cap:", cap(allNames))
}

8
09-FuncAndTypes/funcTypes/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/funcTypes.iml" filepath="$PROJECT_DIR$/.idea/funcTypes.iml" />
</modules>
</component>
</project>

6
09-FuncAndTypes/funcTypes/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,3 @@
module funcTypes
go 1.22

View File

@@ -0,0 +1,21 @@
package main
import (
"fmt"
)
//TIP <p>To run your code, right-click the code and select <b>Run</b>.</p> <p>Alternatively, click
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.</p>
func main() {
//TIP <p>Press <shortcut actionId="ShowIntentionActions"/> when your caret is at the underlined text
// to see how GoLand suggests fixing the warning.</p><p>Alternatively, if available, click the lightbulb to view possible fixes.</p>
s := "gopher"
fmt.Printf("Hello and welcome, %s!\n", s)
for i := 1; i <= 5; i++ {
//TIP <p>To start your debugging session, right-click your code in the editor and select the Debug option.</p> <p>We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.</p>
fmt.Println("i =", 100/i)
}
}