标签: Go

aizuda | 2023-08-27 | Go

Go 编译可执行文件时去掉运行时窗口

Windows exe 去掉 cmd 窗口 编译命令 go build -ldflags "-s -w -H=windowsgui" js -s 省略符号表和调试信息 -w 省略DWARF符号表(Omit the DWARF symbol table ) -H windowsgui 在Windows中 “-H windowsgui”写入的是GUI二进制流,而不是控制台二进制流 On Windows, -H windowsgui writes a "GUI binary" instead of a "console binary." MacOS 去掉 终端 窗口 制作.app bundle 可以使用工具 https://github.com/kettek/go-apper cmd aizuda.app/ └── Contents ├── Info.plist ├── MacOS │ └── aizuda └── Resources

 264 |  0 |  0 Go

青苗 | 2023-08-22 | Go

go-sqlite3 gcc问题

go sqlite 编译异常 cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH% 下载地址:[MinGW-w64 for 32 and 64 bit Windows](https://sourceforge.net/projects/mingw-w64/files/mingw-w64/) 解压后将 bin 目录配置环境变量 path 然后打开CMD 输入 gcc -v 输出版本信息,然后重启 goland 即可

 200 |  0 |  0 Go

青苗 | 2023-05-05 | Go

Go 获取1分钟前的时间,一天前的时间

go 获取1分钟前的时间 go time.Now().Add(-time.Minute 1) go 当前时间向上取整: go var endTime = timeUtil.TruncateHourStr(time.Now().UTC() .Format("2006/01/02 15:04:05")).Unix() go 获取一天前的时间 go var startTime = time.Now().AddDate(0, 0, -1).Unix()

 230 |  1 |  0 Go

青苗 ㅤ | 2023-02-22 | Go

Kplayer 媒体资源推流程序的搭建

念头 有了闲置的服务器,就想搞一个 7 24 小时的直播间,通过搜索引擎以及论坛的了解,接触到 Kplayer 这个项目不错,满足基本需求。 [官方文档](https://docs.kplayer.net/) [官方仓库](https://github.com/bytelang/kplayer-go) 其他同类产品: [Ant-Media (Java,有 WEB 页面)](https://github.com/ant-media/Ant-Media-Server/):体验一下,不怎们会操作,估计是我的姿势不对:( [SRS (C )](https://github.com/ossrs/srs):文档里的专有名词看不懂,有点懵逼:( 开始 安装方式有多种:一键下载、手动下载压缩包、Docker部署。目前仅支持 Linux 部署。 1. 我这里使用的是手动下载方式,把压缩包下载到指定的文件夹然后解压: wget http://download.bytelang.cn/kplayer-v0.5.8-linux_amd64.tar.gz

 507 |  0 |  0 Go

青苗 | 2023-01-02 | Go

golang 日期格式化

golang 日期格式化 go import ( "fmt" "testing" "time" ) func TestDate(t testing.T) { var _t = time.Now() fmt.Printf("当前时间: %v\n", _t.Format("2006-01-02 15:04:05")) fmt.Println("年", _t.Year()) fmt.Println("月", _t.Month()) fmt.Println("月", _t.Format("01")) fmt.Println("日", _t.Day()) fmt.Println("时", _t.Hour()) fmt.Println("分", _t.Minute()) fmt.Println("秒", _t.Second()) } 输出内容: js 当前时间: 2023-01-02 20:05:38 年 2023 月 January 月 01 日 2 时 20 分 5 秒 38

 241 |  0 |  0 Go

青苗 | 2022-12-10 | Go

Golang 模板引擎

用于模板化和词汇化的库和工具。 [ace](https://github.com/yosssi/ace) Ace是Go语言的HTML模板引擎,其灵感来自Slim和Jade。王牌是黄金的提炼。 [amber](https://github.com/eknkc/amber) 琥珀色是Go编程语言的优雅模板引擎,其灵感来自HAML和Jade。 [damsel](https://github.com/dskinner/damsel) 标记语言,具有通过css-selectors进行html概述的功能,可通过pkg html / template等扩展。 [ego](https://github.com/benbjohnson/ego) 轻量级的模板语言,可让您在Go中编写模板。模板被翻译成Go并被编译。 [extemplate](https://github.com/dannyvankooten/extemplate) 围绕html / template的微型包装器,可轻松实现基于文件的模板继承。 [fasttemplate](https://github.com/val

 497 |  0 |  0 Go

青苗 | 2022-11-29 | Go

Golang生成exe时如何添加一个图标

Go 打包 exe 如何看起来更正规?那么肯定是要有一个漂亮的图标,本文介绍如何加上这个图标。 制作图标 找到一个漂亮的图标 在线制作 ico 图标 https://www.bitbug.net/ https://cloudconvert.com/png-to-ico 生成 main.syso 文件 上一步的 ico 文件放到项目根目录 新建文件 main.rc 添加如下内容 cmd IDI_ICON1 ICON "logo.ico" 项目根目录 cmd 命令窗口打开,执行以下命令行 cmd windres -o main.syso main.rc 成功 会生成 main.syso 文件 (保留) 文件 ico main.rc 可以删除 打包项目 这里就是正常打包了,不用多说。打包完成会有一个带图标 exe 可执行文件

 504 |  0 |  0 Go

青苗 | 2022-11-16 | Go

golang 文件上传,上传下载速度限制

文件上传,大小写获取 go package main import ( "fmt" "io" "log" "net/http" "os" ) // 获取文件大小的接口 type Size interface { Size() int64 } // 获取文件信息的接口 type Stat interface { Stat() (os.FileInfo, error) } // hello world, the web server func HelloServer(w http.ResponseWriter, r http.Request) { if "POST" r.Method { file, _, err := r.FormFile("userfile") if err != nil { http.Error(w, err.Error(), 500) return } if statInterface, ok := file.(Stat); ok { fileInfo, _ := statInterfa

 744 |  0 |  0 Go

青苗 | 2022-10-30 | Go

go swagger :cannot find type definition error

go swagger 文档生成异常 :cannot find type definition https://github.com/go-swagger/go-swagger 原因: 默认不会解析外部引用类型 解决办法: 1,最简单 CV 相应包到本地 2,执行命令行 swag init --parseDependency --parseInternal 缺点影响生成文档速度。 | 参数名 | 含义解释 | | - | - | |parseInternal |解析内部依赖包,默认值: false | |parseDependency |解析外部依赖包,默认值: false | |parseDepth | 解析依赖包深度,默认值:100 |

 669 |  0 |  0 Go

青苗 | 2022-10-22 | Go

golang 一键多平台打包 goreleaser

![e493f48770de429ca58e83f723deea2e.png](//img01.aizuda.com/v1/image/preview/1583698047240507392) golang 一键多平台打包 goreleaser goreleaser 是一个自动化打包工具, 自动初始化编译脚本, 支持对接CI/CD 等平台,一行命令轻松实现快速交叉编译跨平台打包。 [goreleaser项目官网](https://goreleaser.com/) [goreleaser源码仓库](https://github.com/goreleaser/goreleaser) 安装使用 https://goreleaser.com/install/ 本文采用命令行 go install github.com/goreleaser/goreleaser@latest 初始化编译脚本 执行命令 goreleaser init 会在项目根目录生成文件 .goreleaser.yaml 原内容做如下调整, 注释不需要的 ...

 630 |  0 |  0 Go

青苗 | 2022-10-21 | JavaTypeScriptJavaScriptGo

Protobuf 生成 Go Java Javascript 等文件

protobuf 简介 [protocol-buffers 官网](https://developers.google.com/protocol-buffers/) protobuf (protocol buffer) 是谷歌内部的混合语言数据标准。通过将结构化的数据进行序列化(串行化),用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。 ![3f3fca408c324376bec46e03d6ecf00b.png](//img01.aizuda.com/v1/image/preview/1583274127333003264) ProtoBuf 中的数据是按顺序进行排列,而整体的结构为若干个 field ,每一个 field 中由 Tag-[Length]-Value 组成。Length是可选的,而是否存在 Length 是通过 Tag 的类型来决定的。也就是说如果是指定的类型,比如 int64 ,那我们就可以知道 Value 的长度,也就不用在依靠 Length 来对其空间进行描述。 对比 JSON 和 XML XML

 3111 |  0 |  0 JavaTypeScript

青苗 | 2022-08-04 | Go

go 语言识别文件 content type

上传文件如果是只允许上传指定文件,可以识别文件扩展名来区分,但是着并不是最优最准确解决方案。本文介绍 go 语言读取文件头的方式识别 contentType 来确定文件类型。 代码如下: package main import ( "fmt" "net/http" "os" ) func main() { // Open the file whose type you // want to check file, err := os.Open("sample.pdf") if err != nil { panic(err) } defer file.Close() // Get the file content contentType, err := GetFileContentType(file) if err != nil { panic(err) } fmt.Println("Content Type of file is: " + conte

 352 |  1 |  1 Go

没有更多啦~