Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持自动生成配置文件, 添加更多可配置项, 优化了一轮代码并且更新了 readme.md #7

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
name: Go
on: [push]
on: [push, workflow_dispatch]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build with xgo
uses: crazy-max/ghaction-xgo@v2
with:
dest: dist
targets: windows/386,windows/amd64,darwin/arm64,darwin/amd64,linux/386,linux/amd64,linux/arm64,linux/mips64,linux/mips64le
v: true
x: false
ldflags: -s -w

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build with xgo
uses: crazy-max/ghaction-xgo@v1
with:
dest: build
targets: windows/386,windows/amd64,linux/386,linux/amd64,darwin/386,darwin/amd64,linux/arm64,linux/mips64,linux/mips64le
v: true
x: false
ldflags: -s -w
- name: Archive artifacts
uses: actions/upload-artifact@v1
with:
name: build
path: build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: DDatHome-go
path: dist
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Build
dist/

# Configs
config.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13-alpine AS builder
FROM golang:1.16-alpine AS builder
WORKDIR /builder
COPY . /builder
RUN apk add upx && \
Expand Down
102 changes: 75 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,107 @@
# DDatHome-go

DD@Home in golang

## 如何直接使用
#### 首先下载发布成品
https://github.com/dd-center/DDatHome-go/releases

### 首先下载发布成品

* [Releases 版](https://github.com/dd-center/DDatHome-go/releases)
* [Ci 版](https://github.com/dd-center/DDatHome-go/actions/workflows/go.yml)

#### 直接运行相应操作系统版本
举例
```

* Windows: 双击 exe 文件直接运行

* Linux:

```sh
# 请先确认可执行文件的路径
# 此处默认你的可执行文件在当前位置且文件名为 DDatHome-go-linux-amd64

# 在 Linux 环境下你可能需要先为其添加可执行权限
chmod +x DDatHome-go-linux-amd64

# 执行以启动 DDatHome-go
./DDatHome-go-linux-amd64
```
来在64位linux下运行

windows你可以直接双击exe开始运行
#### 作为系统服务安装

支持Windows和Linux,需要管理员权限,服务名:DDatHome
```

```sh
./DDatHome-go-linux-amd64 install
```

卸载服务
```

```sh
./DDatHome-go-linux-amd64 uninstall
```

#### 创建并且配置文件 "config.json"
配置文件需要和主程序放在同一个目录下
```
{
"nickname":"DD", //这里是昵称
"interval":500 //这里是任务处理间隔(单位: ms)
}
```
#### Docker

## Docker版DDatHome-go
Pull下载
```

```sh
sudo docker pull imlonghao/ddathome-go
```

测试运行
```

```sh
sudo docker run imlonghao/ddathome-go
```

长期后台运行
```

```sh
sudo docker run -d imlonghao/ddathome-go
```
## 如何从头编译
1. 去[官网下载](https://go.dev/dl/)并安装符合你操作系统的Go

2. 下载本项目:https://github.com/dd-center/DDatHome-go/archive/refs/heads/master.zip
## 配置文件

3. 解压,在Windows上可以直接双击build.bat来编译,在linux或者Mac上用
```
go build main.go
配置文件 (config.json) 需要和主程序放在同一个目录下

```json
{
"NickName": null, // 昵称
"Interval": 1280, // 任务处理间隔 (单位: ms)
"UUID": null, // UUID, 用于数据追踪
"UpstreamURL": "wss://cluster.vtbs.moe/", // 上游地址
"HidePlatformInfo": false // 隐藏有关本机的相关信息, 包括运行时名称,本程序版本与平台名
}
```

4. 去编译好后的bin文件夹运行你需要的版本,可按照上方使用说明进行操作
## 如何从头编译

1. 去[官网](https://go.dev/dl/)下载并安装符合你操作系统的Go
2. 下载[本项目](https://github.com/dd-center/DDatHome-go/archive/refs/heads/master.zip)
3. 解压下载到的压缩包
4. 使用脚本或使用下方的命令编译
* 脚本

```sh
# 请注意工作目录应为根目录
# Windows cmd
.\tools\build.bat

# Fish Shell
./tools/build.fish
```

* 命令

```sh
go build -ldflags "-s -w"
```

5. 进入存放编译后成品的文件夹 (dist 文件夹) 寻找你需要的版本 (若你在上一步使用的是命令编译则编译结果就在当前位置下), 之后可按照上方使用说明进行操作

## 依赖

|库名称 |版本 |
|-----------------------------------------------|------|
|[go-json](https://github.com/goccy/go-json) |0.9.11|
|[service](https://github.com/kardianos/service)|1.2.1 |
33 changes: 0 additions & 33 deletions build.bat

This file was deleted.

4 changes: 0 additions & 4 deletions config.json

This file was deleted.

10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module DDatHome-go

go 1.14
go 1.16

require (
github.com/kardianos/service v1.0.0
github.com/stretchr/testify v1.5.1 // indirect
github.com/tidwall/gjson v1.6.0
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
github.com/goccy/go-json v0.9.11
github.com/kardianos/service v1.2.1
golang.org/x/net v0.0.0-20220923203811-8be639271d50
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
)
41 changes: 14 additions & 27 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kardianos/service v1.0.0 h1:HgQS3mFfOlyntWX8Oke98JcJLqt1DBcHR4kxShpYef0=
github.com/kardianos/service v1.0.0/go.mod h1:8CzDhVuCuugtsHyZoTvsOBuvonN/UDBvl0kH+BUxvbo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 h1:eDrdRpKgkcCqKZQwyZRyeFZgfqt37SL7Kv3tok06cKE=
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/kardianos/service v1.2.1 h1:AYndMsehS+ywIS6RB9KOlcXzteWUzxgMgBymJD7+BYk=
github.com/kardianos/service v1.2.1/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPVFSffdaU3ZyYlBGFnI=
golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Loading