feat(Go-StudyExample):包方法重构

This commit is contained in:
Huangzj
2020-12-16 11:30:31 +08:00
parent 1d21a9634e
commit a97c2c9bcc
17 changed files with 74 additions and 125 deletions
@@ -6,9 +6,12 @@
package originGoLanguage
import "fmt"
import (
"fmt"
"testing"
)
func TestChannel() {
func TestChannel(t *testing.T) {
list := []int{0, 1, 45, -12, 33, 90, -22, 100}
//通道的初始化
@@ -8,10 +8,11 @@ package originGoLanguage
import (
"fmt"
"testing"
"time"
)
func TestDefer() {
func TestDefer(t *testing.T) {
//defer会在所有函数执行完成之后才进行执行
testDeferExe()
//defer产生的值是在对应位置的值,后面的变化不会产生影响
@@ -22,7 +23,7 @@ func TestDefer() {
testDeferRecoverOut() //外层异常捕获
}
func TestCtripException() {
func TestCtripException(t *testing.T) {
fmt.Println("测试不进行捕获的情况")
testNotDefer()
@@ -9,9 +9,10 @@ package originGoLanguage
import (
"errors"
"fmt"
"testing"
)
func TestError() {
func TestError(t *testing.T) {
fmt.Println("测试创建一个新的错误")
testNewError()
@@ -6,9 +6,12 @@
package originGoLanguage
import "fmt"
import (
"fmt"
"testing"
)
func TestMap() {
func TestMap(t *testing.T) {
//没有初始化的是nil,不能进行赋值
var countryMap1 map[string]string
fmt.Println(countryMap1 == nil)
@@ -9,9 +9,10 @@ package originGoLanguage
import (
"fmt"
"net"
"testing"
)
func NetTest() {
func TestNet(t *testing.T) {
//InterfaceAddrs 返回该系统的网络接口的地址列表。
addr, _ := net.InterfaceAddrs()
@@ -1,37 +0,0 @@
/*
* @Author : huangzj
* @Time : 2020/7/13 14:35
* @Description
*/
package originGoLanguage
func TestOriginLang() {
//网络及端口测试
NetTest()
//传值和传址的比较
TestQuote()
//切片测试
TestSlice()
//测试Map
TestMap()
//通道测试
TestChannel()
//测试init,只要在当前结构体中有引入对应的包,就会调用相应的init方法,具体可以查看 上面的import
//测试error的生成
TestError()
//测试defer关键字
TestDefer()
//测试携程的异常捕获 --- 好像有没有捕获,主函数都可以正常运行
TestCtripException()
}
@@ -6,9 +6,12 @@
package originGoLanguage
import "fmt"
import (
"fmt"
"testing"
)
func TestQuote() {
func TestQuote(t *testing.T) {
x, y := "i am x", "i am y"
fmt.Println("回参的值2")
@@ -6,9 +6,12 @@
package originGoLanguage
import "fmt"
import (
"fmt"
"testing"
)
func TestSlice() {
func TestSlice(t *testing.T) {
//定义切片
var number []int
fmt.Println(number)