#GO

go helloworld

 //Sampleprogramtoshowhowabytes.Buffercanalsobeused//withtheio.Copyfunction.packagemainimport("bytes""fmt""io""os")//mainistheentrypointfortheapplication.f...
代码星球 ·2020-08-09

go 获取网址html 源码

 //Sampleprogramtoshowhowtowriteasimpleversionofcurlusing//theio.Readerandio.Writerinterfacesupport.packagemainimport("fmt""io""net/http""os")//initiscalle...

go 接口以及对象的使用

 //SampleprogramtoshowhowtodeclaremethodsandhowtheGo//compilersupportsthem.packagemainimport("fmt")//userdefinesauserintheprogram.typeuserstruct{namestring...

Go 结构体

  1.packagemainimport"fmt"typeBooksstruct{titlestringauthorstringsubjectstringbook_idint}funcmain(){//创建一个新的结构体fmt.Println(Books{"Go语言","www.runoob.co...
代码星球 ·2020-08-09

go 异常处理

 packagemainimport"fmt"funcmain(){deferfunc(){iferr:=recover();err!=nil{fmt.Println(err)}}()deferfunc(){panic("three")}()deferfunc(){panic("two")}()panic("...
代码星球 ·2020-08-09

go 类型转换

 packagemainimport"fmt"funcmain(){varsumint=17varcountint=5varmeanfloat32mean=float32(sum)/float32(count)fmt.Printf("mean的值为:%f",mean)}输出mean的值为:3.400000&n...
代码星球 ·2020-08-09

go 接口

 1.packagemainimport("fmt")typePhoneinterface{call()}typeNokiaPhonestruct{}func(nokiaPhoneNokiaPhone)call(){fmt.Println("IamNokia,Icancallyou!")}typeIPhone...
代码星球 ·2020-08-09

go 并发 demo

 两个进程执行两个goroutine//Thissampleprogramdemonstrateshowtocreategoroutinesand//howtheschedulerbehaves.packagemainimport("fmt""runtime""sync")//mainistheentrypo...
代码星球 ·2020-08-09

go 通道

 1.packagemainimport"fmt"funcsum(s[]int,cchanint){sum:=0for_,v:=ranges{sum+=v}c<-sum//把sum发送到通道c}funcmain(){s:=[]int{7,2,8,-9,4,0}c:=make(chanint)gosum(...
代码星球 ·2020-08-09

go 并发

 packagemainimport("fmt""time")funcsay(sstring){fori:=0;i<5;i++{time.Sleep(100*time.Millisecond)fmt.Println(s)}}funcmain(){gosay("hello1")say("hello2")}...
代码星球 ·2020-08-09

Mac下安装与配置Go语言开发环境

 安装gobrewinstallgo如果提示-bash:brew:commandnotfound,可以看这:https://www.cnblogs.com/sea-stream/p/10309985.html安装完毕,一般安装好go之后,使用goenv查看一下当前环境。此时显示出来的GOROOT就是你使用br...
代码星球 ·2020-08-09

go 修改字符串

 在Go中字符串是不可变的,例如下面的代码编译时会报错:cannotassigntos[0]varsstring="hello"s[0]='c'但如果真的想要修改怎么办呢?下面的代码可以实现:s:="hello"c:=[]byte(s)//将字符串s转换为[]byte类型c[0]='c's2:=string(...
代码星球 ·2020-08-09

go 字符串拼接

 s:="hello,"m:="world"a:=s+mfmt.Printf("%s",a) ...
代码星球 ·2020-08-09

go 语言字典元素删除

 packagemainimport"fmt"funcmain(){/*创建map*/countryCapitalMap:=map[string]string{"France":"Paris","Italy":"Rome","Japan":"Tokyo","India":"Newdelhi"}fmt.Prin...

go 语言字典遍历

 packagemainimport"fmt"funcmain(){varcountryCapitalMapmap[string]string/*创建集合*/countryCapitalMap=make(map[string]string)/*map插入key-value对,各个国家对应的首都*/countr...
代码星球 ·2020-08-09
首页上一页...7879808182...下一页尾页