Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
88011cf20b | |||
027fbf781d | |||
bee336ed5e | |||
621ca23432 | |||
71fe730e5e | |||
ab2631257b | |||
c64ff5c035 | |||
eeebdae492 | |||
424eb06417 |
60
Jenkinsfile
vendored
Normal file
60
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
nodejs 'node-v18.18.2' // 使用全局配置的Node.js工具
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
// 从Git仓库克隆项目
|
||||
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '4a774ecd-6ae3-4e27-a5e6-e6488b93b28a', url: 'https://gitea.1216.top/lxy/z-docs.git']])
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Dependencies') {
|
||||
steps {
|
||||
// 使用配置的Node.js版本安装项目依赖
|
||||
sh '''
|
||||
npm config set registry https://registry.npmmirror.com/
|
||||
npm install
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
// 执行构建步骤,比如打包
|
||||
sh 'npm run build' // 假设你的package.json中有一个名为build的脚本用于打包
|
||||
}
|
||||
}
|
||||
|
||||
stage('deploy') {
|
||||
steps {
|
||||
sshPublisher(publishers: [sshPublisherDesc(
|
||||
configName: 'u-xg', // SSH服务器的配置名称
|
||||
transfers: [sshTransfer(
|
||||
cleanRemote: false,
|
||||
execCommand: '''
|
||||
// 这里可以添加在远程机器上执行的其他命令
|
||||
cd /var/www
|
||||
rm zhub-docs -rf
|
||||
mv z-docs zhub-docs
|
||||
''',
|
||||
execTimeout: 120000,
|
||||
flatten: false, // 是否将源文件扁平化到单个目录中
|
||||
makeEmptyDirs: true, // 是否创建远程目录结构
|
||||
noDefaultExcludes: false,
|
||||
patternSeparator: '[, ]+',
|
||||
remoteDirectory: '/var/www/z-docs', // 远程机器上的目标目录
|
||||
removePrefix: 'dist/', // 如果需要,从源文件名中移除的前缀
|
||||
sourceFiles: 'dist/**' // 要传输的文件模式,这里表示dist目录及其所有内容
|
||||
)],
|
||||
usePromotionTimestamp: false,
|
||||
useWorkspaceInPromotion: false,
|
||||
verbose: true // 设置为true以获取更详细的日志输出
|
||||
)])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"label": "其他常用",
|
||||
"position": 5,
|
||||
"link": {
|
||||
"type": "generated-index"
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"label": "其他组件",
|
||||
"position": 3,
|
||||
"link": {
|
||||
"type": "generated-index"
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# RPC远程调用
|
||||
|
||||
#
|
111
blog/set_version_in_go.md
Normal file
111
blog/set_version_in_go.md
Normal file
@@ -0,0 +1,111 @@
|
||||
---
|
||||
slug: setting-version-in-go
|
||||
title: "在 Go 程序中设置版本号并注入打包"
|
||||
authors: lxy
|
||||
tags: [ Golang, Build, Version, CI/CD ]
|
||||
---
|
||||
|
||||
### 场景
|
||||
在 Go 程序中设置并注入版本号是一种常见的做法,借助 -ldflags 参数,可以在编译时动态传递版本信息,使得生成的可执行文件包含明确的版本标识。这种方法可以帮助开发者轻松管理版本发布,并确保每个构建都带有唯一的版本号,方便后续调试、部署及追踪问题。
|
||||
|
||||
---
|
||||
|
||||
### 1. 在 `main` 包中设置版本号
|
||||
|
||||
#### 示例代码
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var version string // 定义版本变量
|
||||
|
||||
func main() {
|
||||
// 定义命令行参数
|
||||
versionFlag := flag.Bool("version", false, "显示版本号")
|
||||
vFlag := flag.Bool("v", false, "显示版本号")
|
||||
|
||||
// 解析命令行参数
|
||||
flag.Parse()
|
||||
|
||||
// 检查版本参数并输出
|
||||
if *versionFlag || *vFlag {
|
||||
fmt.Printf("版本号: %s\n", version)
|
||||
os.Exit(0) // 输出后退出
|
||||
}
|
||||
|
||||
// 主程序逻辑
|
||||
fmt.Println("运行主程序...")
|
||||
}
|
||||
```
|
||||
|
||||
#### 打包命令
|
||||
在打包时使用以下命令注入版本号:
|
||||
```bash
|
||||
go build -ldflags "-X 'main.version=$(date +%Y.%m.%d-%H.%M.%S)'" -o your_program_name.exe
|
||||
```
|
||||
|
||||
#### 查看版本号
|
||||
```bash
|
||||
your_program_name.exe -version // 显示版本号
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2. 在模块中设置版本号
|
||||
|
||||
#### `monitor` 包
|
||||
|
||||
```go
|
||||
package monitor
|
||||
|
||||
var Version string // 定义版本变量
|
||||
```
|
||||
|
||||
#### 修改 `main.go`
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"your_project/monitor" // 修改为实际路径
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 定义命令行参数
|
||||
versionFlag := flag.Bool("version", false, "显示版本号")
|
||||
vFlag := flag.Bool("v", false, "显示版本号")
|
||||
|
||||
// 解析命令行参数
|
||||
flag.Parse()
|
||||
|
||||
// 检查版本参数并输出
|
||||
if *versionFlag || *vFlag {
|
||||
fmt.Printf("监控版本: %s\n", monitor.Version)
|
||||
os.Exit(0) // 输出后退出
|
||||
}
|
||||
|
||||
// 主程序逻辑
|
||||
fmt.Println("运行主程序...")
|
||||
}
|
||||
```
|
||||
|
||||
#### 打包命令
|
||||
在打包时使用以下命令注入版本号:
|
||||
```bash
|
||||
go build -ldflags "-X 'your_project/monitor.Version=$(date +%Y.%m.%d-%H.%M.%S)'" -o your_program_name.exe
|
||||
```
|
||||
|
||||
---
|
||||
### 总结
|
||||
以上示例展示了如何在 `main` 包和模块中设置并注入版本号,以便在打包时动态注入版本号;
|
||||
|
||||
同样的也可以按照上面方法注入其他需要在打包时动态注入的其他变量。
|
8
docs/oth/_category_.json
Normal file
8
docs/oth/_category_.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"label": "其他常用",
|
||||
"position": 5,
|
||||
"link": {
|
||||
"type": "generated-index",
|
||||
"description": "这里存放了各种常用的工具。"
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
sidebar_position: 9
|
||||
---
|
||||
|
||||
# 一些命令
|
29
docs/oth/type-token.md
Normal file
29
docs/oth/type-token.md
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# IType
|
||||
|
||||
> IType 中实现的 TypeToken
|
||||
|
||||
```java
|
||||
package dev.zhub;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IType {
|
||||
TypeToken<String> STRING = new TypeToken<String>() {};
|
||||
TypeToken<Short> SHORT = new TypeToken<Short>() {};
|
||||
TypeToken<Integer> INT = new TypeToken<Integer>() {};
|
||||
TypeToken<Long> LONG = new TypeToken<Long>() {};
|
||||
TypeToken<Double> DOUBLE = new TypeToken<Double>() {};
|
||||
TypeToken<Map<String, String>> MAP = new TypeToken<Map<String, String>>() {};
|
||||
TypeToken<List<Map<String, String>>> LMAP = new TypeToken<List<Map<String, String>>>() {};
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
```
|
14
docs/oth/微服务.md
Normal file
14
docs/oth/微服务.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
# ZHub 与微服务
|
||||
|
||||
- 服务注册与发现:
|
||||
> 在分布式系统中,服务注册与发现是确保系统能够找到并调用正确服务的关键机制。ZHub 作为一个服务注册中心或服务发现机制的一部分,它负责维护服务列表(service-topic),使得其他服务能够通过它找到并调用所需的服务。
|
||||
- 负载均衡:
|
||||
> 在分布式系统中,负载均衡是确保请求均匀分布到各个服务实例上的关键机制。ZHub 是一个负载均衡器,它可负责将请求分发到不同的服务实例上,以提高系统的可用性和性能。
|
||||
- 消息队列:
|
||||
> 在微服务架构中,消息队列可以用于异步处理请求和解耦服务之间的通信。ZHub 是一个消息队列服务,它可负责接收、存储和分发消息,使得服务可以在需要时处理这些消息。
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
sidebar_position: 2
|
||||
title: 广播消息
|
||||
description: 发送、接收广播消息
|
||||
---
|
||||
@@ -29,4 +29,4 @@ description: 发送、接收广播消息
|
||||
zhub.broadcast("topic-a", value);
|
||||
return "send ok!";
|
||||
}
|
||||
```
|
||||
```
|
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
sidebar_position: 3
|
||||
title: 延时消息
|
||||
description: zhub 的延时消息使用
|
||||
---
|
||||
@@ -32,4 +32,4 @@ description: zhub 的延时消息使用
|
||||
zhub.delay("topic-delay-a", "delay-value", 1000);
|
||||
return "send ok!";
|
||||
}
|
||||
```
|
||||
```
|
@@ -1,6 +1,6 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
title: 订阅&发布
|
||||
title: 发布&订阅
|
||||
description: zhub 创建客户端连接、订阅主题、发送主题消息
|
||||
---
|
||||
|
36
docs/tutorial-basics/rpc.md
Normal file
36
docs/tutorial-basics/rpc.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
title: 远程调用 RPC
|
||||
description: RPC 远程调用,Remote Procedure Call,RPC
|
||||
---
|
||||
|
||||
# RPC远程调用
|
||||
|
||||
:::tip
|
||||
|
||||
RPC 是一种通过网络将远程过程调用(Remote Procedure Call,RPC)封装成消息,并传送到远程服务器上的过程。
|
||||
|
||||
:::
|
||||

|
||||
|
||||
## 使用场景
|
||||
> 在分布式环境下,通过 RPC 可以在两个应用之间进行消息传递,实现远程调用。
|
||||
|
||||
## rpc的订阅-调用基础示例
|
||||
### 被调用端
|
||||
```java
|
||||
// 订阅 rpc-b 事件, 参数类型为 String
|
||||
zhub.rpcSubscribe("rpc-b", IType.STRING, r -> {
|
||||
String str = r.getValue();
|
||||
System.out.println("接收到 b 事件:" + str);
|
||||
return r.render("接收到 b 事件:" + str);
|
||||
});
|
||||
```
|
||||
### 调用端
|
||||
```java
|
||||
// 调用 rpc-b 事件, 参数类型为 String,返回类型为 String
|
||||
RpcResult<String> rpcResult = zhub.rpc("rpc-b", "hello rpc", IType.STRING);
|
||||
String result = rpcResult.getResult();
|
||||
System.out.println("rpc result:" + result);
|
||||
```
|
||||
|
8
docs/tutorial-extras/_category_.json
Normal file
8
docs/tutorial-extras/_category_.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"label": "其他组件",
|
||||
"position": 3,
|
||||
"link": {
|
||||
"type": "generated-index",
|
||||
"description": "分布式系统常用组件"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
@@ -11,7 +11,7 @@ const config = {
|
||||
favicon: 'img/favicon.ico',
|
||||
|
||||
// Set the production url of your site here
|
||||
url: 'https://zhub.1216.top',
|
||||
url: 'https://zhub.dev',
|
||||
// Set the /<baseUrl>/ pathname under which your site is served
|
||||
// For GitHub pages deployment, it is often '/<projectName>/'
|
||||
baseUrl: '/',
|
||||
@@ -74,18 +74,10 @@ const config = {
|
||||
src: 'img/logo.svg',
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'docSidebar',
|
||||
sidebarId: 'tutorialSidebar',
|
||||
position: 'left',
|
||||
label: '文档',
|
||||
},
|
||||
{type: 'docSidebar', sidebarId: 'tutorialSidebar', position: 'left', label: '文档',},
|
||||
{href: 'https://zhub.dev/release/latest', label: '下载', position: 'left',},
|
||||
{ to: '/blog', label: 'Blog', position: 'left' },
|
||||
{
|
||||
href: 'https://gitee.com/tc608/zhub',
|
||||
label: 'Gitee',
|
||||
position: 'right',
|
||||
},
|
||||
{href: 'https://gitee.com/tc608/zhub', label: 'Gitee', position: 'right',},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -95,36 +87,26 @@ const config = {
|
||||
{
|
||||
title: '文档',
|
||||
items: [
|
||||
{
|
||||
label: '快速开始',
|
||||
to: '/docs/intro',
|
||||
},
|
||||
{label: '下载', href: 'https://zhub.dev/release/latest/',},
|
||||
{label: '快速开始', to: '/docs/intro',},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '社区',
|
||||
items: [
|
||||
{
|
||||
label: 'Gitee',
|
||||
href: 'https://gitee.com/tc608',
|
||||
},
|
||||
{label: 'Gitee', href: 'https://gitee.com/tc608',},
|
||||
{label: '微信:zhub_dev', to: '/'},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '更多',
|
||||
items: [
|
||||
{
|
||||
label: '博客',
|
||||
to: '/blog',
|
||||
},
|
||||
{
|
||||
label: 'GitHub',
|
||||
href: 'https://github.com/facebook/docusaurus',
|
||||
},
|
||||
{label: '博客', to: '/blog',},
|
||||
{label: '反馈', href: 'https://gitee.com/tc608/zhub/issues?state=all',},
|
||||
],
|
||||
},
|
||||
],
|
||||
copyright: `Copyright © ${new Date().getFullYear()} ZHub, Inc. Built with Docusaurus.`,
|
||||
copyright: `Copyright © ${new Date().getFullYear()} ZHub`,
|
||||
},
|
||||
prism: {
|
||||
theme: lightCodeTheme,
|
||||
|
@@ -19,8 +19,8 @@
|
||||
"@mdx-js/react": "^1.6.22",
|
||||
"clsx": "^1.2.1",
|
||||
"prism-react-renderer": "^1.3.5",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0"
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "2.4.1",
|
||||
|
@@ -4,29 +4,29 @@ import styles from './styles.module.css';
|
||||
|
||||
const FeatureList = [
|
||||
{
|
||||
title: '易于使用',
|
||||
title: '轻松易用',
|
||||
Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default,
|
||||
description: (
|
||||
<>
|
||||
ZHub 从新设计,易于安装和用于快速启动运行您的项目。
|
||||
全新设计,易于使用,轻松安装,助你快速启动项目运行。
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '专注于重要的事情',
|
||||
title: '专注要事',
|
||||
Svg: require('@site/static/img/undraw_docusaurus_tree.svg').default,
|
||||
description: (
|
||||
<>
|
||||
ZHub 让你专注于你的业务,我们专注于消息收发、数据传递,让你多个工程进行之间通讯变得如此的简单。
|
||||
专注消息收发与数据传递,极简API,让你专注业务,使多工程间通讯变得简单。
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Powered by ZHUB',
|
||||
title: '由 ZHub 助力',
|
||||
Svg: require('@site/static/img/undraw_docusaurus_react.svg').default,
|
||||
description: (
|
||||
<>
|
||||
通过 Golang 编写通讯组件,自定义消息协议,专注提升服务性能。
|
||||
由 Golang 编写的通讯组件,以 ZHub 之力专注提升服务性能,提供稳定可靠的支持。
|
||||
</>
|
||||
),
|
||||
},
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
/* You can override the default Infima variables here. */
|
||||
:root {
|
||||
--ifm-color-primary: #852e79;
|
||||
--ifm-color-primary: #2e4785;
|
||||
--ifm-color-primary-dark: #29784c;
|
||||
--ifm-color-primary-darker: #277148;
|
||||
--ifm-color-primary-darkest: #205d3b;
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
/* For readability concerns, you should choose a lighter palette in dark mode. */
|
||||
[data-theme='dark'] {
|
||||
--ifm-color-primary: #852e79;
|
||||
--ifm-color-primary: #475c98;
|
||||
--ifm-color-primary-dark: #21af90;
|
||||
--ifm-color-primary-darker: #1fa588;
|
||||
--ifm-color-primary-darkest: #1a8870;
|
||||
|
Reference in New Issue
Block a user