go 初始化之路

来源:互联网 发布:吉林数据造假 编辑:程序博客网 时间:2024/05/20 23:08

一:git仓库

下载git仓库代码

在文件夹页面 ctrl +shift+鼠标右键  打开命令窗 输入 git clone +(代码地址)

命令窗提交代码 或vscode 终端输入

git pull -->git status -->git add . -->git commit -m"备注" -->git push

二:http://192.168.0.89:8050/solr/

sql语句检测,判断go文件中sql语句是否输出了正确的结果

三:操作结构体(对象)

1:

package syslogtype Syslog struct {    AppId          string `bson:"appid"`    VisitTime      string `bson:"visitTime"`    VisitInterface string `bson:"visitInteface"`    VisitCount     string `bson:"visitCount`}package mainimport "syslog"func main(){_s := syslog.Syslog{AppId:          utils.GetParam(r, "appId"),VisitInterface: r.URL.Path,VisitTime:      utils.GenerateGSTDateTime(),VisitCount:     row,}}

2:

type Books struct {   title string   author string   subject string   book_id int}func main() {   var Book1 Books        /* 声明 Book1 为 Books 类型 */   /* book 1 描述 */   Book1.title = "Go 语言"   Book1.author = "www.runoob.com"   Book1.subject = "Go 语言教程"   Book1.book_id = 64954

四:方法和函数的区别

package mainimport "fmt"type myint int//乘2func (p *myint) mydouble() int {*p = *p * 2return 0}//平方func (p myint) mysquare() int {p = p * pfmt.Println("mysquare p = ", p)return 0}func main() {var i myint = 2i.mydouble()fmt.Println("i = ", i)//输出i=4i.mysquare()     //输出mysquare p = 16fmt.Println("i = ", i)//输出i=4}

方法和函数的区别:方法在func关键字后是接收者而不是函数名,接收者可以是自己定义的一个类型,这个类型可以是struct,interface,甚至我们可以重定义基本数据类型。我们可以给他一些我们想要的方法来满足我们的实际工程中的需求,就像上面一样我重定义了int并给了它一个乘2和平法的方法,这里我们要注意一个细节,接收者是指针和非指针的区别,我们可以看到当接收者为指针式,我们可以通过方法改变该接收者的属性(传引用),但是非指针类型(传值)却做不到。
这里的接收者和c++中的this指针有一些相似,我们可以把接受者当作一个class,而这些方法就是类的成员函数,当接收者为指针类型是就是c++中的非const成员函数,为非指针时就是const成员函数,不能通过此方法改变累的成员变量。