随笔分类 -  go

go
摘要:1. goroutine 1. 重点 1.要搞清楚goroutine什么时候退出2. 控制goroutine退出3. 把并发给调用者 2. 代码示例 package main import ( "context" "fmt" "time" ) //1. 使用chan创建 //2 run函数消费cha 阅读全文
posted @ 2023-04-19 10:49 wanghhhh 阅读(18) 评论(0) 推荐(0) 编辑
摘要:1. sentinel error 预定义的特定错误,我们叫为 sentinel error,这个名字来源于计算机编程中使用一个特定值来表示不可能进行进一步处理的做法。所以对于 Go,我们使用特定的值来表示错误。if err == ErrSomething { … }类似的 io.EOF,更底层的 阅读全文
posted @ 2023-04-17 14:07 wanghhhh 阅读(77) 评论(0) 推荐(0) 编辑
摘要:一. 数组 1. 特征 静态语言的数组特征: 1.大小确定 2.类型一致 只能取值,修改值 由于数组长度固定,在Go里很少直接使用 2. 定义 // 3种方式,声明,初始,省略号 // 变量arr1类型为[5]int var arr1 [5]int // 变量arr2类型为[3]int,同时初始化赋 阅读全文
posted @ 2023-04-03 11:08 wanghhhh 阅读(37) 评论(0) 推荐(0) 编辑
摘要:import os import sys import subprocess import shutil """ 功能: 1. 拷贝python的proto到go的对应目录之下 2. 生成python的源码 - import . 3. 生成go的源码 """ class cd: def __init 阅读全文
posted @ 2022-11-27 15:30 wanghhhh 阅读(77) 评论(0) 推荐(0) 编辑
摘要:一.新建商品 1. 配置路由 goods-web/router/goods.go package router import ( "github.com/gin-gonic/gin" "mxshop-api/goods-web/api/goods" ) func InitGoodsRoute(Rou 阅读全文
posted @ 2022-11-26 14:56 wanghhhh 阅读(125) 评论(0) 推荐(0) 编辑
摘要:一.目录 1. 新建目录 goods-web/utils/register/consul/register.go 2.目录截图 二.注册配置 1. 概述 1. 创建目录:为了后续支持其他注册中心,保证程序的拓展性,目前只支持consul 2. 利用go语言的特性,实现struct和interfact 阅读全文
posted @ 2022-11-26 12:35 wanghhhh 阅读(89) 评论(0) 推荐(0) 编辑
摘要:一.项目初始化 1.目录结构 C:. │ config-debug.yaml │ config-pro.yaml │ main.go │ ├─api │ └─goods │ goods.go │ ├─config │ config.go │ ├─forms │ goods.go │ ├─global 阅读全文
posted @ 2022-11-15 18:41 wanghhhh 阅读(45) 评论(0) 推荐(0) 编辑
摘要:一.项目初始化 1. 微服务接口分析 2. 数据库表分析 3. 订单支付全流程 4.目录结构 5.初始化model代码 创建goods_srv及model目录 创建goods_srv/model/models.py文件 from datetime import datetime from peewe 阅读全文
posted @ 2022-11-15 11:34 wanghhhh 阅读(80) 评论(0) 推荐(0) 编辑
摘要:一. nacos介绍及安装 1. 官网 https://nacos.io/zh-cn/docs/quick-start.html 二.集成go 1.官网地址 https://github.com/nacos-group/nacos-sdk-go 2. 使用 package main import ( 阅读全文
posted @ 2022-11-12 13:54 wanghhhh 阅读(296) 评论(0) 推荐(0) 编辑
摘要:一. nacos介绍及安装 1. 官网 https://nacos.io/zh-cn/docs/quick-start.html 二.集成python 1.官网地址 https://github.com/nacos-group/nacos-sdk-python 2. 使用 import json i 阅读全文
posted @ 2022-11-11 16:44 wanghhhh 阅读(1208) 评论(0) 推荐(0) 编辑
摘要:一.配置全局变量 global/golbal.go中添加: UserSrvClient proto.UserClient package global import ( ut "github.com/go-playground/universal-translator" "mxshop-api/us 阅读全文
posted @ 2022-11-09 16:04 wanghhhh 阅读(65) 评论(0) 推荐(0) 编辑
摘要:一. 在python项目中使用 1.目录存放 创建公共目录存放common/register,创建base.py register.py 2.base.py基础类 import abc class Resister(metaclass=abc.ABCMeta): @abc.abstractmetho 阅读全文
posted @ 2022-11-08 17:27 wanghhhh 阅读(45) 评论(0) 推荐(0) 编辑
摘要:一. 使用requests使用注册 1. python服务注册及检查 可以对http接口和grpc接口进行状态健康检测 import requests headers = { "contentType": "application/json" } def register(name, id, add 阅读全文
posted @ 2022-11-07 18:12 wanghhhh 阅读(90) 评论(0) 推荐(0) 编辑
摘要:1.在middlewares中创建cors.go文件 package middlewares import ( "github.com/gin-gonic/gin" "net/http" ) func Cors() gin.HandlerFunc { return func(c *gin.Conte 阅读全文
posted @ 2022-11-03 10:09 wanghhhh 阅读(105) 评论(0) 推荐(0) 编辑
摘要:一. 如何使用JWT结合gin实现token生成 1. 创建文件,在mxshop-api/user-web/middlewares 下面添加固定文件 package middlewares import ( "errors" "github.com/dgrijalva/jwt-go" "github 阅读全文
posted @ 2022-11-01 15:08 wanghhhh 阅读(429) 评论(0) 推荐(0) 编辑
摘要:一. 表单验证的初始化 1. 定义forms验证 在forms目录下创建user.go文件 增加验证的struct内容 package forms type PassWordLoginForm struct { Mobile string `form:"mobile" json:"mobile" b 阅读全文
posted @ 2022-10-31 14:05 wanghhhh 阅读(157) 评论(0) 推荐(0) 编辑
摘要:1. 使用库viper 使用示例 package main import ( "fmt" "github.com/spf13/viper" ) type ServerConfig struct { ServiceName string `mapstructure:"name"` Port int ` 阅读全文
posted @ 2022-10-28 13:41 wanghhhh 阅读(227) 评论(0) 推荐(0) 编辑
摘要:1. 项目目录结构 2. 定义main函数 package main import ( "fmt" "go.uber.org/zap" "mxshop-api/user-web/initialize" ) func main() { //初始化logger initialize.InitLogger 阅读全文
posted @ 2022-10-28 09:55 wanghhhh 阅读(140) 评论(0) 推荐(0) 编辑
摘要:package main import ( "context" "log" "net/http" "os" "os/signal" "syscall" "time" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() 阅读全文
posted @ 2022-10-25 18:05 wanghhhh 阅读(217) 评论(0) 推荐(0) 编辑
摘要:1. 无中间件启动 #使用 r := gin.New() #替代 // 默认启动方式,包含 Logger、Recovery 中间件 r := gin.Default() 2. 中间件启动 func main() { // 创建一个不包含中间件的路由器 r := gin.New() // 全局中间件 阅读全文
posted @ 2022-10-25 16:09 wanghhhh 阅读(54) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示