Go/Gin/Docker/k8s/Redis
Go/Gin/Docker/k8s/Redis/负载均衡/centos/云原生
userxxcc
周日
展开
-
【Golang map并发报错】panic: assignment to entry in nil map
就会遇到并发nil值报错,什么test[key-xxx] = make()根本不行。Lock锁那个比较麻烦,不建议使用。推荐使用sync.Map。原创 2024-01-11 15:25:56 · 1119 阅读 · 2 评论 -
成品+思路:wails+Go+JS实现系统托盘小插件(状态栏小插件)功能
wails+Go+JS实现系统托盘小插件(状态栏小插件),如图,实现了状态栏实时显示CPU占用率、硬盘占用率功能。原创 2023-12-28 02:39:06 · 916 阅读 · 0 评论 -
Wails中js调用go函数(1种go写法,2种js调用方法)
b)运行 wails dev命令,系统将会在frontend/wailsjs/go中自动生成JSCallGo函数的export对象。官方js调用go方法文档:https://wails.io/zh-Hans/docs/howdoesitwork。原创 2023-12-22 22:20:07 · 1057 阅读 · 0 评论 -
Mac报错:zsh: command not found: wails
特别注意的是PATH参数是否配置正确(这个逻辑同样适用于Win平台),这关系到,你可以参考搭建。1. 安装wails依赖(原创 2023-04-25 23:21:01 · 1185 阅读 · 1 评论 -
Go1.18开始在老Goland中关于泛型any在recover()时的写法
Go1.18开始关于泛型any在recover()时的写法原创 2022-12-13 16:55:25 · 788 阅读 · 0 评论 -
Ginvel是web MVC框架,基础特性基于Gin、gRPC、Go1.17+、Redis5+
Ginvel是GinLaravel的难度版(升级版)。Ginvel使用起来可能比较难,入门难、操作难、阅读难。Ginvel是Golang的web MVC框架,基础特性基于Gin、gRPC、Go1.17+、Redis5+。原创 2022-07-06 01:24:35 · 585 阅读 · 0 评论 -
为gRPC-Server添加自定义中间件
1. 目标:欲自定义一个捕捉grpc-server里面的全局代码500报错(panic报错)的中间件。2. 书写中间件:安装插件依赖:go get github.com/grpc-ecosystem/go-grpc-middleware中间件全部代码,其中返回值类型为固定的形式(为go-grpc-middleware插件返回最值形式):package middlewaresimport ( "context" "fmt" "google.golang.org/grpc"原创 2021-07-12 10:59:49 · 1214 阅读 · 0 评论 -
go生成uuid
uuid是与其他人、同系统相同时间生成永不相同的id。方法一:package mainimport ( "fmt" "github.com/go-basic/uuid")func main() { uuid := uuid.New() fmt.Println(uuid)}方法二,Google官方,推荐:package mainimport ( "fmt" "github.com/google/uuid")func main() { id := uu原创 2021-07-08 11:57:59 · 684 阅读 · 0 评论 -
Docker安装ElasticSearch (Centos7机器环境)
1. 拉取镜像:docker pull docker.elastic.co/elasticsearch/elasticsearch:7.13.02. 重启docker:service docker restart3. 创建网络:docker network create esnet4. 启动docker-es容器:4.1 安装窗口寄存管理screen,目标实现关闭cmd虚拟窗口后,命令仍然执行:yum install screen4.2 新建一个名叫es的窗口:scr原创 2021-07-03 09:58:43 · 219 阅读 · 0 评论 -
Go输出大一段字符块
-package mainimport ( "fmt")func main() { var str string = "2021" var div string = `<div style="color:blue;" data-id='1'> <!-- 动态渲染html内容 --> <h3 class="red"> ` + str + ` </h3></div> ` fmt.Println(div)原创 2021-06-17 15:06:07 · 737 阅读 · 0 评论 -
Go+Gin做一个WebSocket,(Ginlaravel演示)
控制器代码:package WebSocketimport ( "ginvel.com/app/Common" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "net/http" "time")// WebSocket参数var upGrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, Handsha...原创 2021-06-16 09:32:47 · 735 阅读 · 0 评论 -
Centos7编译Golang报错:/usr/bin/ld: /tmp/go-link-xx0.o: unrecognized relocation (0x2a) in section `.text‘
-[root@xxx ginlaravel]# go run main.go# command-line-arguments/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1/usr/bin/ld: /tmp/go-link-038275771/000010.o: unrecognized relocation (0x2a) in section `.text'/usr/bin/ld: final原创 2021-06-15 14:18:08 · 4415 阅读 · 1 评论 -
【k8s教程-4】将docker镜像推送到镜像库里面,并将镜像推送到k8s-v1.20
-1. 将docker镜像推送到镜像库里面。在docker服务器里面,cd到项目根目录。比如我的:cd /home/wwwroot/go/src/ginvel# 在终端登录docker账户(https://hub.docker.com/repository)[root@go-docker ginvel]# docker loginLogin with your Docker ID to push and pull images from Docker Hub. If you don'原创 2021-06-08 16:52:49 · 1847 阅读 · 0 评论 -
【k8s教程-2】安装kubernetes-dashboard
参考:https://www.kubernetes.org.cn/7189.htmlhttp://blog.51yip.com/cloud/2399.html# 安装kubernetes-dashboard# 需要科学攀登:wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc7/aio/deploy/recommended.yaml# 用自己下载好的[root@master1 ~]# wge..原创 2021-06-07 18:06:44 · 669 阅读 · 0 评论 -
Go调用struct或interface自定义的内部方法(函数)
-package mainimport "fmt"// ------------------------------// Function 封装接口,仅暴露参数type Function struct { Name string}func (fun *Function)Get() (name string) { name = fun.Name + "-Get" return}func (fun *Function)Set(name string) { fun.Nam原创 2021-06-04 14:29:38 · 1055 阅读 · 0 评论 -
【k8s教程-1】kubeadm方法来安装k8s-v1.20(Centos7环境)
-kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具。这个工具能通过两条指令完成一个kubernetes集群的部署:# 创建一个 Master 节点$ kubeadm init# 将一个 Node 节点加入到当前集群中$ kubeadm join <Master节点的IP和端口 >1. 安装要求在开始之前,部署Kubernetes集群机器需要满足以下几个条件:一台或多台机器,操作系统 CentOS7.x-86_x64 硬..原创 2021-06-02 23:32:42 · 413 阅读 · 0 评论 -
【k8s教程-3】制作dockerfile,并将go项目部署到docker里(docker镜像制作,centos7环境)
centos7安装go环境:https://blog.csdn.net/weixin_41827162/article/details/116048754centos7安装docker:--原创 2021-05-28 15:02:03 · 559 阅读 · 0 评论 -
Go按行读txt
-// TxtReadLine 按行读txt文件func TxtReadLine(filepath string, filename string) (txtArray []string) { // 计数 lineNumHave := 0 // 有值 lineNumNull := 0 // 空值 // 打开txt文件 file, err := os.Open(filepath + filename) if err != nil{ fmt.Println("无效的txt文件", er原创 2021-05-25 11:38:36 · 269 阅读 · 0 评论 -
go定时器robfig/cron v3和robfig/cron v1使用示例
cron v3和cron v1的定时器示例:1)以下适用于cron v3的写法:安装依赖:go getgithub.com/robfig/cron/v3import ( "github.com/robfig/cron/v3" "log")核心代码:??打印日志:??-2)以下适用于cron v1的写法:安装依赖:go getgithub.com/robfig/cronimport ( "github.com/robfig/cron" "log"..原创 2021-05-22 10:39:49 · 2076 阅读 · 0 评论 -
Go获取n天前或后的日期、日期转秒时间戳、计算两个日期之间的天数差
获取n天前或后的日期:// GetBeforeTime 获取n天前的秒时间戳、日期时间戳// _day为负则代表取前几天,为正则代表取后几天,0则为今天func GetBeforeTime(_day int) (int64, string) { // 时区 //timeZone, _ := time.LoadLocation(ServerInfo["timezone"]) timeZone := time.FixedZone("CST", 8*3600) // 东八区 // 前n天 n原创 2021-05-17 11:54:53 · 4321 阅读 · 0 评论 -
Go将for循环分开,自定义多线程数量
-package mainimport ( "fmt" "math")func RunRoutine(f int, theStart int, theEnd int) { fmt.Printf("~ 本次线程参数:线程index=%d,本次开始=%d,本次结束=%d \n", f, theStart, theEnd) for l:= theStart; l< theEnd; l++ { //time.Sleep(123 * time.Millisecond) fmt.原创 2021-05-14 11:01:17 · 671 阅读 · 0 评论 -
Go按多组id数组出现次数,由多到少排序并去重,输出权重id数组
这个算法用在按分词在数据库中查询的id集合,最后输出带有权重的id数组。类似的思路是Elasticsearch中的中文检索算法。算法:package KitLibimport ( "fmt" "sort")type Recommend struct { //Array []int}// RecommendArraysInt 分词ID推荐// 多组int数组// 重复int组成优先级第一的,不重复int各数组跟在后面// 调用:rec := KitLib.Recommen原创 2021-05-12 14:34:29 · 299 阅读 · 0 评论 -
gorm+ginlaravel的多条件查询(包含LIKE模糊查询、Map、Not、Order)、增、改、删MVC示例
-GinLaravel框架:Github(推荐):https://github.com/fyonecon/ginlaravelGitee(备用):https://gitee.com/fyonecon/ginlaravel-示例User数据库数据:多条件查询多一个列表:-Kit数据库定义:var Db *sql.DB = driver.MysqlDb // 连接gomysql扩展var DB *gorm.DB = driver.GDB // 连接gorm扩原创 2021-05-03 01:56:51 · 2438 阅读 · 0 评论 -
postman调试GinLaravel数据需要注意(针对POST方法)
给接口发送post请求,参数值为空时,需要将body的content-type设置成:multipart/form-data或application/x-www-form-urlencoded如下:-使用axios提交post数据时,请确保数据的组合格式是否正确。可以选如下方法来提交正确组合格式的数据: const map = new Map([ // 要提交数据 ["id", 20221],原创 2021-04-28 17:49:42 · 265 阅读 · 0 评论 -
【GO-教程7】GinLaravel操作MySQL数据:增删改查示例
-自动判断请求类型并自动输出参数值,没有键则返回空:// 自动判断请求类型并自动输出参数值func Input(ctx *gin.Context, key string) string { var _value string var value string var hasKey bool _method := ctx.Request.Method if _method == "GET" { value, hasKey = ctx.GetQuery(key) }else if原创 2021-04-26 16:13:08 · 150 阅读 · 0 评论 -
GO运行时报错: cannot find package “.“ in:
improt导入文件的时候,路径的大小写没写对。Mac下编译通过,但是docker和centos下编译不了。===运行如下报错:[root@localhost ginlaravel]# go run server.goroutes/route.go:19:2: cannot find package "." in: /home/wwwroot/go/src/ginlaravel/app/http/Controllerroutes/route.go:20:2: cannot find pa原创 2021-04-23 15:43:16 · 7303 阅读 · 0 评论 -
【GO-教程6】Centos7安装Golang环境(基于ginlaravel框架演示,简单ab压测)
安装lamp环境(这里是装MySQL5.7+nginx环境,使用lnmp可以自动化安装):(安装教程请参考:https://lnmp.org/install.html)[root@localhost ~]# yum install wget[root@localhost ~]# wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd原创 2021-04-23 11:46:19 · 794 阅读 · 0 评论 -
centos7安装docker
1、参考博客:https://blog.csdn.net/zhang__rong/article/details/886471972.1、建议centos安装岑centos7.7以上版本。2.2、更新系统使用root 权限登录 CentOS。确保 yum 包更新到最新。yum -y update2.3、卸载旧版本(如果安装过就版本的话):yum remove docker docker-common docker-selinux docker-engine如果安装过旧版本,就会卸载当前版本原创 2021-04-21 22:30:16 · 162 阅读 · 0 评论 -
Go+MySQL示例:多条件查询、多条件排序、数据总数、分页数据、遍历数组(结构体)数据
-Go+MySQL示例:多条件查询、多条件排序、数据总数、分页数据、遍历数组(结构体)数据空间命名函数Common和Kit请参考打包项目:https://blog.csdn.net/weixin_41827162/article/details/115712700import ( "database/sql" "ginlaravel/app/Common" "ginlaravel/app/Kit" "ginlaravel/bootstrap/driver" "github.com/g原创 2021-04-20 15:35:42 · 1705 阅读 · 0 评论 -
解决tollbooth限制http请求速率中间件报错:cannot use XXX (type time.Duration) as type *limiter.ExpirableOptions
在做tollbooth_gin引入时报错:cannot use time.XXX(type time.Duration) as type *limiter.ExpirableOptions in argument to tollbooth.NewLimiter解决:方法1:使用默认nil(time.Second):limiter := tollbooth.NewLimiter(10, nil)方法2:var tbOptions limiter.ExpirableOptionstb..原创 2021-04-18 15:36:56 · 1275 阅读 · 0 评论 -
基于Golang框架Gin开发的MVC轮子框架:GinLaravel
GinLaravel项目开源地址:https://github.com/fyonecon/ginlaravel基于GO语言框架Gin开发,项目结构和项目哲学参考Laravel。MVC开发模式、必要的拦截器、扩展函数、灵活部署等特点。支持:Gin的模版输出、Gin的api输出。--获取源代码:git clone https://github.com/fyonecon/ginlaravel.gitcd ginlaravel使用 govendor 安装依赖包:go get -u原创 2021-04-14 23:43:15 · 3744 阅读 · 0 评论 -
【GO教程5】Mac搭建简单Gin项目
-官方文档:https://github.com/gin-gonic/gin# 搭建go环境:请参考:【GO教程-3】Mac搭建go环境https://blog.csdn.net/weixin_41827162/article/details/115612993如果不想使用以上搭建go的教程,则可用下面教程:1. Mac直接安装go安装包:https://golang.google.cn/dl/go1.16.3.darwin-amd64.pkg2. 写入自定义参数:进入M.原创 2021-04-14 11:23:38 · 1208 阅读 · 1 评论 -
【GO教程-4】Mac搭建beego环境(模版或api项目)
# 搭建go环境:请参考:【GO教程-3】Mac搭建go环境https://blog.csdn.net/weixin_41827162/article/details/115612993如果不想使用以上搭建go的教程,则可用下面教程:1. Mac直接安装go安装包:https://golang.google.cn/dl/go1.16.3.darwin-amd64.pkg2. 写入自定义参数:进入Mac用户根目录:cd ~创建 .bash_profile:touch ...原创 2021-04-12 11:52:23 · 364 阅读 · 3 评论 -
【GO教程-3】Mac搭建go环境
# 安装GO:1.1在https://golang.google.cn/dl/下载pkg安装包来直接运行安装:1.2查看是否安装成功:go version1.3查看go env:go env1.4设置(更换)大陆镜像代理:$ go env -w GO111MODULE=on$ go env -w GOPROXY=https://goproxy.cn,direct# 配置GoPath2.1:打开终端Terminal 进入user目录:cd ~2.2:(你也.原创 2021-04-12 10:09:35 · 648 阅读 · 0 评论 -
【GO开发教程-2】win10搭建GO环境、Beego环境,创建新的Beego项目,Beego项目上线生产
2原创 2020-09-29 10:59:05 · 584 阅读 · 0 评论