-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ac3db6
Showing
14 changed files
with
5,903 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
project_name: go_emqx_exhook | ||
|
||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
snapshot: | ||
name_template: "{{ incpatch .Version }}" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
env_files: | ||
github_token: ../../github_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM alpine:3.18.2 | ||
MAINTAINER Wang Chen Chen<[email protected]> | ||
ENV VERSION 1.0 | ||
# 在容器根目录 创建一个 apps 目录 | ||
WORKDIR /apps | ||
# 拷贝当前目录下 go_docker_demo1 可以执行文件 | ||
COPY dist/go_emqx_exhook_linux_amd64_v1/go_emqx_exhook /apps/golang_app | ||
# 拷贝配置文件到容器中 | ||
COPY config.yaml /apps/config.yaml | ||
# 设置时区为上海 | ||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
RUN echo 'Asia/Shanghai' >/etc/timezone | ||
# 设置编码 | ||
ENV LANG C.UTF-8 | ||
# 暴露端口 | ||
EXPOSE 16565 | ||
# 运行golang程序的命令 | ||
ENTRYPOINT ["/apps/golang_app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
### proto 生成 go 代码 | ||
```shell | ||
|
||
protoc --go_out=. --go-grpc_out=. proto/*.proto | ||
|
||
protoc -I=proto --go_out=. --go-grpc_out=. proto/*.proto | ||
|
||
``` | ||
|
||
### golang 编译 | ||
```shell | ||
## 打包可执行文件 | ||
goreleaser build --single-target | ||
|
||
|
||
``` | ||
|
||
### 下载 Linux 可执行文件。 | ||
|
||
vim Dockerfile | ||
```shell | ||
FROM alpine:3.18.2 | ||
MAINTAINER Wang Chen Chen<[email protected]> | ||
ENV VERSION 1.0 | ||
# 在容器根目录 创建一个 apps 目录 | ||
WORKDIR /apps | ||
# 拷贝当前目录下 go_docker_demo1 可以执行文件 | ||
COPY go_emqx_exhook /apps/golang_app | ||
# 拷贝配置文件到容器中 | ||
COPY config.yaml /apps/config.yaml | ||
# 设置时区为上海 | ||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
RUN echo 'Asia/Shanghai' >/etc/timezone | ||
# 设置编码 | ||
ENV LANG C.UTF-8 | ||
# 暴露端口 | ||
EXPOSE 16565 | ||
# 运行golang程序的命令 | ||
ENTRYPOINT ["/apps/golang_app"] | ||
``` | ||
|
||
vim config.yaml | ||
```yaml | ||
appName: go_emqx_exhook | ||
port: 16565 | ||
|
||
bridgeRule: | ||
sourceTopics: | ||
- "/#" | ||
targetTopic: emqx_msg_bridge | ||
targetTag: emqx | ||
|
||
rocketmqConfig: | ||
nameServer: | ||
- 127.0.0.1:9876 | ||
``` | ||
### docker build | ||
```shell | ||
docker build -t go_emqx_exhook:1.1 ./ | ||
``` | ||
|
||
## docker 运行 | ||
```shell | ||
docker run -d --name go_emqx_exhook -p 16565:16565 --restart=always go_emqx_exhook:1.1 | ||
|
||
## 指定配置文件 | ||
docker run -d --name go_emqx_exhook -p 16565:16565 -v /etc/config.yaml:/apps/config.yaml --restart=always go_emqx_exhook:1.1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package conf | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
"log" | ||
) | ||
|
||
// Config 全局配置配置文件 | ||
var Config *ServerConfig | ||
|
||
func init() { | ||
viper.SetDefault("appName", "go_emqx_exhook") | ||
viper.SetDefault("port", 16565) | ||
viper.SetDefault( | ||
"bridgeRule", | ||
BridgeRule{ | ||
SourceTopics: []string{ | ||
"/#", | ||
}, | ||
TargetTopic: "emqx_msg_bridge", | ||
TargetTag: "emqx", | ||
}, | ||
) | ||
viper.SetDefault( | ||
"rocketmqConfig", | ||
RocketmqConfig{ | ||
NameServer: []string{ | ||
"127.0.0.1:9876", | ||
}, | ||
}, | ||
) | ||
viper.SetConfigName("config") // name of config file (without extension) | ||
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name | ||
viper.AddConfigPath("/etc/appname/") // 查找配置文件所在路径 | ||
viper.AddConfigPath("$HOME/.appname") // 多次调用AddConfigPath,可以添加多个搜索路径 | ||
viper.AddConfigPath(".") // optionally look for config in the working directory | ||
viper.AddConfigPath("../") // optionally look for config in the working directory | ||
viper.AddConfigPath("./conf/") // 还可以在工作目录中搜索配置文件 | ||
if err := viper.ReadInConfig(); err != nil { // Handle errors reading the config file | ||
log.Panicf("Fatal error config file: %v \n", err) | ||
} | ||
if err := viper.Unmarshal(&Config); err != nil { | ||
log.Panicf("Fatal error config file: %v \n", err) | ||
} | ||
} | ||
|
||
type ServerConfig struct { | ||
// 服务名称 | ||
AppName string `yaml:"appName" json:"appName"` | ||
|
||
// 服务端口 | ||
Port int `yaml:"port" json:"port"` | ||
|
||
// 桥接规则 | ||
BridgeRule BridgeRule `yaml:"bridgeRule" json:"bridgeRule"` | ||
|
||
// Rocketmq 配置 | ||
RocketmqConfig RocketmqConfig `yaml:"rocketmqConfig" json:"rocketmqConfig"` | ||
} | ||
|
||
// RocketmqConfig 桥接到 Rocketmq 的配置 | ||
type RocketmqConfig struct { | ||
|
||
// Rocketmq NameServer | ||
NameServer []string `yaml:"nameServer" json:"nameServer"` | ||
} | ||
|
||
// BridgeRule 桥接规则 | ||
type BridgeRule struct { | ||
// Emqx 的主题 | ||
SourceTopics []string `yaml:"sourceTopics" json:"sourceTopics"` | ||
|
||
// Rocketmq 的主题 | ||
TargetTopic string `yaml:"targetTopic" json:"targetTopic"` | ||
|
||
// Rocketmq 的 Tag | ||
TargetTag string `yaml:"targetTag" json:"targetTag"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
appName: go_emqx_exhook | ||
port: 16565 | ||
|
||
bridgeRule: | ||
sourceTopics: | ||
- "/#" | ||
targetTopic: emqx_msg_bridge | ||
targetTag: emqx | ||
|
||
rocketmqConfig: | ||
nameServer: | ||
- 192.168.0.196:9876 |
Oops, something went wrong.