1 Star 0 Fork 3

zengning2015 / learning_tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

LEARNING_TOOLS

博客: hwholiday

  • 🤪 golang 基础,微服务,架构,web,k8s,DDD 各种工具任君取用
  • 📫 contact me: WECHAT HW_loner
  • 📫 contact me: QQ 3355168235

go-kit 微服务实践,从入门到精通

go-kit 系列文章归档地址 (详细介绍)

1: v1 go-kit 微服务 基础使用 (HTTP)
2: v2 go-kit 微服务 添加日志(user/zap ,并为每个请求添加UUID)
3: v3 go-kit 微服务 身份认证 (JWT)
4: v4 go-kit 微服务 限流 (uber/ratelimit 和 golang/rate 实现)
5: v5 go-kit 微服务 使用GRPC(并为每个请求添加UUID)
6: v6 go-kit 微服务 服务注册与发现(etcd实现)
7: v7 go-kit 微服务 服务监控(prometheus 实现)
8: v8 go-kit 微服务 服务熔断(hystrix-go 实现)
9: v9 go-kit 微服务 服务链路追踪(jaeger 实现)(1)
10: v10 go-kit 微服务 服务链路追踪(jaeger 实现)(2)
11: v11 go-kit 微服务 日志分析管理 (ELK + Filebeat)

用 go 实现的高性能长连接网络库

dove 用 go 实现的高性能长连接网络库 https://github.com/hwholiday/ghost

gRPC负载均衡(自定义负载均衡策略--etcd 实现)

hlb-grpc (gRPC负载均衡(自定义负载均衡策略--etcd 实现)

实现基于版本(version)的grpc负载均衡器,了解过程后可自己实现更多的负载均衡功能

详细介绍

  • 注册中心
    • Etcd Lease 是一种检测客户端存活状况的机制。 群集授予具有生存时间的租约。 如果etcd 群集在给定的TTL 时间内未收到keepAlive,则租约到期。 为了将租约绑定到键值存储中,每个key 最多可以附加一个租约
  • 服务注册 (注册服务)
    • 定时把本地服务(APP)地址,版本等信息注册到服务器
  • 服务发现 (客户端发起服务解析请求(APP))
    • 查询注册中心(APP)下有那些服务
    • 并向所有的服务建立HTTP2长链接
    • 通过Etcd watch 监听服务(APP),通过变化更新链接
  • 负载均衡 (客户端发起请求(APP))
    • 负载均衡选择合适的服务(APP HTTP2长链接)
    • 发起调用
├── discovery
│   ├── customize_balancer.go
│   ├── discovery.go
│   └── options.go
├── example
│   ├── api
│   │   └── api.pb.go
│   ├── api.proto
│   ├── client_test.go
│   └── server.go
└── register
    ├── options.go
    ├── register.go
    └── register_test.go

仿微信 auth2 授权登陆 DDD(领域设计驱动)+ 六边形架构

OAuth 2.0-授权码模式(authorization code)仿微信设计(战略篇)

OAuth 2.0-授权码模式(authorization code)仿微信设计(战术篇)

AUTH2 代码地址

Golang DDD 的项目分层结构(六边形架构)

DDD (DDD 项目分层结构)

├── cmd 存放 main.go 等
├── adapter
│   ├── grpc
│   └── http
│   └── facade  引用其他微服务(接口防腐层)
├── application 
│   ├── assembler   负责将内部领域模型转化为可对外的DTO
│   └── cqe Command、Query和Event --  入参
│   └── dto Application层的所有接口返回值为DTO -- 出参
│   └── service 负责业务流程的编排,但本身不负责任何业务逻辑
├── domain
│   ├── aggregate 聚合
│   ├── entity 实体
│   ├── event 事件
│   │   ├── publish
│   │   └── subsctibe
│   ├── repo 接口
│   │   └── specification 统一封装查询
│   ├── service 领域服务
│   └── vo 值对象
└── infrastructure
│   ├── config 配置文件
│   ├── pkg 常用工具类封装(DB,log,tool等)
│   └── repository
│   ├── converter domain内对象转化 do {互转}
│   └── do 数据库映射对象
└── types 封装自定义的参数类型,例如 phone 自校验参数        

封装 zap 日志注入 trace 信息 Trace Id(内含 gin 例子)

hlog (源码地址)

  • 实现自动切割文件 (基于 lumberjack 实现)
  • 实现可传递 trace 信息 (基于 Context 实现)
{"level":"info","ts":1639453661.4718382,"caller":"example/main.go:36","msg":"hconf example success"}
{"level":"info","ts":1639453664.7402327,"caller":"example/main.go:19","msg":"AddTraceId success","traceId":"68867b89-c949-45a4-b325-86866c9f869a"}
{"level":"info","ts":1639453664.7402515,"caller":"example/main.go:32","msg":"test","traceId":"68867b89-c949-45a4-b325-86866c9f869a"}
{"level":"debug","ts":1639453664.7402549,"caller":"example/main.go:33","msg":"test","traceId":"68867b89-c949-45a4-b325-86866c9f869a"}

hconfig 插拔式配置读取工具可动态加载

  • 支持 etcd
  • 支持 kubernetes
  • 支持 apollo

使用文档

hconfig 配置不同的源

//etcd
cli, err := clientv3.New(clientv3.Config{
	Endpoints: []string{"127.0.0.1:2379"},})
	
c, err := etcd.NewEtcdConfig(cli,
	etcd.WithRoot("/hconf"),
	etcd.WithPaths("app", "mysql"))

//kubernetes
cli, err := kubernetes.NewK8sClientset(
     kubernetes.KubeConfigPath("/home/app/conf/kube_config/local_kube.yaml"))
     
c, err := kubernetes.NewKubernetesConfig(cli, 
	kubernetes.WithNamespace("im"),
	kubernetes.WithPaths("im-test-conf", "im-test-conf2"))
	
//apollo
c, err := apollo.NewApolloConfig(
    apollo.WithAppid("test"),
    apollo.WithNamespace("test.yaml"),
    apollo.WithAddr("http://127.0.0.1:32001"),
    apollo.WithCluster("dev"),
    )

hconfig 使用

conf, err := NewHConfig(
	WithDataSource(c),//c 不同的源
)

// 加载配置
conf.Load() 

//读取配置
val, err := conf.Get("test.yaml")
t.Logf("val %+v\n", val.String())

//监听配置变化
conf.Watch(func(path string, v HVal) {
	t.Logf("path %s val %+v\n", path, v.String())
})

go_push 一个实用的消息推送服务

go_push (推送服务)

```base
├── gateway // 长连接网关服务器
│   ├── push_job.go    // 分发任务
│   ├── room.go        // 房间,可作为某一类型的推送管理中心
│   ├── room_manage.go // 房间管理
│   ├── ws_conn.go     // 简单封装的websocket方法
│   ├── ws_handle.go   // 处理websocket协议方法
│   └── ws_server.go   // websocket服务
├── logic  //逻辑服务器    
│   ├── http_handle.go // 推送,房间相关
│   └── http_server.go // http服务
└── main.go
```

HConf (基于etcd与viper的高可用配置中心)

  • 可使用远程与本地模式
  • 本地有的配置远程没有会自动把本地配置传到远程(基于key)
  • 远程有的配置本地没有也会写一份到本地(退出程序会把远程配置写一份到本地)
  • 远程模式配置可以动态加载
  • 如远程连接不上会使用本地配置启动作为兜底
var conf = Conf{}
r, err := NewHConf(
	SetWatchRootName([]string{"/gs/conf"}),
)
if err != nil {
	t.Error(err)
	return
}
t.Log(r.ConfByKey("/gs/conf/net", &conf.Net))
t.Log(r.ConfByKey("/gs/conf/net2222", &conf.Net2))
t.Log(r.ConfByKey("/gs/conf/net3333", &conf.Net3))
if err := r.Run(); err != nil {
	t.Error(err)
	return
}
t.Log(conf)
t.Log(r.Close())

HEvent (基于channel )

1: 基于channel的简单事件订阅发布

设计模式

1: 并发设计模式之Active Object
2: Go 实现的责任链模式

micro_agent (micro微服务)

1: base 基础方法
2: conf 配置文件
3:handler 对外处理方法
4:model 数据格式
5:proto protobuf 文件

all_packaged_library 里面封装了一些常用的库,有详细的介绍,持续更新

1: base 里面封装mysql,redis,mgo,minio文件储存库S3协议,雪花算法,退出程序方法,redis全局锁,日志库等(插件形式可单独引用)
2: logtool uber_zap日志库封装,可自动切分日志文件,压缩文件
3: perf ppoof小插件
4: push 集成苹果推送,google推送,华为推送
5: quit 优雅的退出程序
6: registrySelector 基于etcd实现的服务注册,发现,负载均衡

docker (为你的服务插上docker_compose翅膀)

 1: docker 为你的服务插上docker_compose翅膀   

kafka (分布式消息发布订阅系统)

1: main 消息队列

NATS_streaming (分布式消息发布订阅系统--是由NATS驱动的数据流系统)

1: main 消息队列

nsq (分布式实时消息平台)

1: main 消息队列

grpc (grpc学习)

1: bidirectional_streaming_rpc 双向流grpc
2: server_side_streaming_rpc 服务端流grpc,也可以写成客户端流grpc
3: simple_rpc 简单grpc

rpc (rpc学习)

1: main rpc学习

prometheus (监控报警系统)

1: server Prometheus监控报警系统

jaeger (jaeger分布式链路追踪)

1: main jaeger分布式链路追踪

service_load_balancing (负载均衡)

1: fisher_yates_test  添加fisher-yates算法 负载均衡节点

hystrix (熔断)

1: hystrix 学习并使用熔断(Hystrix)

req_limit (限流)

1: main 使用带缓存的channel实现限流
2: uber_ratelimit 使用uber_ratelimit实现限流       

ini (配置文件库)

1: main 配置文件ini的读取,以及自动匹配到结构体里面

minio (对象存储服务)

1: minio 对象存储服务使用

mysql (mysql服务器)

1: main 简单的mysql使用

redis (redis相关)

1: bloom_filter redis 实现BloomFilter过滤器
2: lock redis实现全局锁
3: pipeline redis事务
4: subscription redis发布订阅    

mongodb (mongodb服务器)

1: mgo.v2  mgo.v2库的基础使用学习
2: mongo-go-driver  官方库的demo,以及事务提交(不能是单节点)

gin (web框架gin学习)

1: mvc 模式,swagger文档 可作为基础学习gin

jwt (JSON WEB TOKEN)

1: jwt 学习使用   

snow_flake (雪花算法)

1: main 雪花算法    

encryption_algorithm (双棘轮算法, KDF链,迪菲-赫尔曼棘轮,x3dh)

1: aes ase-(cfb,cbc,ecb)-(128,192,256)加解密方法
2: curve25519 椭圆曲线算法
3: 3curve25519 双棘轮算法,KDF链

LRU (缓存淘汰算法)

1: list lru 缓存淘汰算法 

tcp (tcp协议实现)

1: 实现网络库,封包,解包 len+tag+data 模式

websocket (websocket协议实现)

1: 实现网络库

binary_conversion (进制转换)

1: 10to36 10进制转36进制
2: 10to62 10进制转62进制
3: 10to76 10进制转76进制
4: binary 用一个int64来描述开关(用户设置很多建议使用)       

job_worker_mode (job_worker模式)

1: worker job_worker模式,可提高系统吞吐量

filewatch (监控文件变化)

1: main 监控文件变化 可实现自动构建

prometheus (普罗米修斯)

1: main 普罗米修斯    

goquery (网页解析工具)

1: main 可以作为爬虫解析网页使用

active_object (并发设计模式)

1: active_object Go并发设计模式之Active Object

heap (优先级队列)

1: heap 利用heap创建一个优先级队列

cli (go命令行交互)

1: main go命令行交互

context (context包学习)

1: main context包学习 

err (error 相关)

1: main golang 1.13 error 相关

interface (interface包学习)

1: main interface包学习
2: middleware Golang 基于interface 实现中间件

syncPool (syncPool包学习)

1: main syncPool包学习

reflect (reflect包学习)

1: main reflect包学习
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/asd2015/learning_tools.git
git@gitee.com:asd2015/learning_tools.git
asd2015
learning_tools
learning_tools
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891