Go
kogwang
这个作者很懒,什么都没留下…
展开
-
gin框架使用logrus日志模块
gin框架使用logrus日志模块,自定义输出格式原创 2023-02-01 17:37:54 · 445 阅读 · 1 评论 -
golang的CGO_ENABLED交叉编译(Linux, Windows)
安装mingw-w64 kog@kogdeMacBook-Pro % brew install mingw-w64==> Downloading https://homebrew.bintray.com/bottles/gmp-6.2.1.big_sur.bottle.tar.gz==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6a44705536f25c4b9f8547d44d129ae3b3657755039..原创 2021-05-13 14:36:52 · 13595 阅读 · 10 评论 -
go正则表达式
package mainimport ( "fmt" "regexp")func main(){ reg := regexp.MustCompile(`正则表达式`) val := reg.FindAllString("需要匹配的字符串", -1) // -1匹配所有 fmt.Println(val)}原创 2021-05-07 11:42:51 · 87 阅读 · 0 评论 -
golang日期字符串的互转
绝不BB 上代码package mainimport ( "fmt" "time")func main() { // 日期转字符串 currentTime := time.Now() fmt.Println("Current Time in String: ", currentTime.String()) fmt.Println("MM-DD-YYYY : ", currentTime.Format("01-02-2006")) fmt.Println("YYYY-MM-DD :原创 2021-04-29 15:50:00 · 4883 阅读 · 0 评论 -
beego的orm原生SQL查询
这种是我目前看到最简单的写法了(没有之一) 欢迎打脸 func testdata(){ o := orm.NewOrm() var list []orm.Params nums, err := o.Raw("select 1 as 'haha'").Values(&list) if nums == 0 { } fmt.Println(list,err)}原创 2021-04-27 15:47:05 · 441 阅读 · 2 评论 -
Go判断文件是否存在,不存在创建
看代码_, exist := os.Stat("logs")if os.IsNotExist(exist) { os.Mkdir("logs", os.ModePerm)}原创 2021-04-25 11:45:06 · 952 阅读 · 0 评论 -
GO的ssh连接方案
不BB直接看代码 package mainimport ( "fmt" gossh "golang.org/x/crypto/ssh" "net")// 连接信息type Cli struct { user string pwd string addr string client *gossh.Client session *gossh.Session LastResult string}// 连接对象func原创 2021-04-02 10:54:15 · 3741 阅读 · 2 评论 -
GoLand项目导入报红,项目正常运行
setting--> Go Moudules--> 勾上Enable Go modules intergration原创 2021-01-21 15:47:17 · 1940 阅读 · 0 评论 -
Golang发起GET POST请求
package mainimport ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" "time")func httpGet() { //func Get(url string) (resp *Response, err error) //url := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx1.原创 2020-11-25 20:32:08 · 200 阅读 · 0 评论 -
beego不建立模型,ORM执行SQL
main.gopackage mainimport ( _ "beegoDemo001/routers" "fmt" "github.com/astaxie/beego" "github.com/astaxie/beego/logs" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" "os")//初始化连接数据库func init() { //此处可以读取你的config配置 //u.原创 2020-10-13 12:29:00 · 230 阅读 · 0 评论 -
Golang操作MySQL
怕原作者删了转载一波(侵删)go get github.com/go-sql-driver/mysqlpackage main; import ( "database/sql" _ "github.com/go-sql-driver/mysql" // 包的初始化,执行包中所有的init()方法 具体参见http://blog.csdn.net/wanglei9876/article/details/50475864 "fmt") func main() {转载 2020-10-03 22:31:16 · 98 阅读 · 0 评论 -
Go交叉编译,后台启动执行、停止
编译Mac下编译Linux, Windows平台的64位可执行程序:CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build test.goCGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build test.goLinux下编译Mac, Windows平台的64位可执行程序:CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build test.goCGO_ENABLED=0 G原创 2020-09-27 11:36:24 · 720 阅读 · 0 评论 -
Golang beego跨域请求及中间件
跨域请求 (推荐抽离)package routersimport ( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/cors")func init() { //跨域配置 beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{ AllowAllOrigins: true, //AllowOrigins:原创 2020-09-18 15:35:05 · 752 阅读 · 0 评论 -
go get 报错:dial tcp 34.64.4.113:443: i/o timeout解决方案
切换为国内资源即可go env -w GO111MODULE=on设置环境代理go env -w GOPROXY=https://goproxy.cn,direct原创 2020-09-16 14:50:55 · 9259 阅读 · 2 评论 -
Golang文件写入常用的三种方式
走起 package mainimport ( "bufio" "fmt" "io/ioutil" "os")func writeByte(path, str string) { fileObj, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 132) if err != nil { fmt.Println(err) return } defer func() { err := fil原创 2020-09-14 14:01:32 · 1919 阅读 · 0 评论 -
Golang文件读取常用的三种方式
golang读取文件原创 2020-09-14 12:44:15 · 717 阅读 · 0 评论