go安装包
- go语言的sdk安装
- goland安装
- goland公司内安装
下载msi
下载jetbrain.7z
点击unsintall all users和install users脚本
重新打开goland输入激活码
goframe安装
如果直接git clone https://github.com/gogf/gf && cd gf/cmd/gf && go install
会报错如下
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
因为远程仓库太大了!
https://github.com/gogf/gf/releases下载gf_windows_amd64.exe
使用go命令下载包
go mod init modulename
go mod tidy
然后再同目录下go get 资源地址
go语言的代理配置
- windows下
go env -w GOPROXY="http://af-proxy.公司名.com.cn/artifactory/api/go/go-proxy"
- linux下
export GOPROXY="http://af-proxy.公司名.com.cn/artifactory/api/go/go-proxy"
ORM
package main
import (
"demo/internal/cmd"
_ "demo/internal/packed"
"fmt"
_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
db, err := gdb.New(gdb.ConfigNode{
Link: "oracle:username:password@tcp(10.19.200.167:1521)/ORAC",
})
if err != nil {
fmt.Print(err)
}
//UPDATE
//_, err = db.Model("table22").Data(g.Map{"name": "john guo"}).Where("name", "try1").Update()
//
//if err != nil {
// fmt.Print(err)
//}
//DELETE
//_, err = db.Model("table22").Where("note", "555").Delete()
//if err != nil {
// fmt.Print(err)
//}
//INSERT
type oneItem struct {
ID int `orm:"id"`
Name string `orm:"name"`
Note2 string `orm:"note2"`
Note string `orm:"note"`
Item int `orm:"item"`
Item1 int `orm:"item1"`
}
//
//oneitem := &oneItem{
// ID: 5,
// Name: "try3",
// Note2: "p1",
// Note: "p1",
// Item: 1002,
// Item1: 1002}
//_, err = db.Model("table22").Data(oneitem).Insert()
//
//if err != nil {
// fmt.Print(err)
//}
//INSERT
//_, err = db.Model("table22").Data(g.Map{
// "id": 1,
// "name": "try1",
// "note": "p1",
// "note2": "p1",
// "item": 1002,
// "item1": 1002,
//}).Insert()
//SELECT
Where(&oneItem{Name: "try3"})不可以成功查询
//result, err := db.Model("table22").Where(g.Map{"name": "try3"}).All()
//
//if err != nil {
// fmt.Println("查询出错:", err)
//} else {
// // 输出查询结果
// fmt.Println("查询结果:", result)
//}
//group和orderby
//result, err := db.Model("table22").Fields("COUNT(*) total,item1").Group("item1").Having("total>2")All()
result, err := db.Model("table22").Order("id asc,item asc,item1 desc").All()
if err != nil {
fmt.Println("查询出错:", err)
} else {
// 输出查询结果
fmt.Println("查询结果:", result)
}
cmd.Main.Run(gctx.GetInitCtx())
}