Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 1f5a38f

Browse files
authored
Merge pull request #8 from dextercai/dev
feat: flag与conf文件并行、CICD、更新文档
2 parents 055aa53 + bd647c1 commit 1f5a38f

File tree

13 files changed

+412
-121
lines changed

13 files changed

+412
-121
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Get latest go version
8+
id: version
9+
run: |
10+
echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
11+
12+
- name: Setup Go
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: ${{ steps.version.outputs.go_version }}
16+
17+
- name: Check out code into the Go module directory
18+
uses: actions/checkout@v3
19+
20+
- name: Cache go module
21+
uses: actions/cache@v2
22+
with:
23+
path: ~/go/pkg/mod
24+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
25+
restore-keys: |
26+
${{ runner.os }}-go-
27+
28+
#- name: Get dependencies, run test
29+
# run: |
30+
# go test ./...
31+
32+
- name: Build
33+
if: startsWith(github.ref, 'refs/tags/')
34+
env:
35+
NAME: feeyo-adsb-golang
36+
BINDIR: bin
37+
run: make -j releases
38+
39+
- name: Upload Release
40+
uses: softprops/action-gh-release@v1
41+
if: startsWith(github.ref, 'refs/tags/')
42+
with:
43+
files: bin/*
44+
draft: true

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
## 使用说明
88

9-
本项目已更新,修改为Golang 1.11起支持的Go modules。
10-
主分支去除了UUID生成器的代码,但依旧保留二进制版本,请自定义UUID时确保不与其他人冲突。
11-
129
由于本项目不包括Dump1090,也不限制SBS服务是否运行在本机,因此你可能需要首先安装Dump1090,具体细节可自行搜索,当然你也可以在本项目提一个Issue,我将很乐意为你解答。
1310

14-
你需要编辑conf.ini文件
11+
如果你不具备编译条件,可以直接前往[本项目发布页](https://github.com/dextercai/feeyo-adsb-golang/releases)下载使用。
12+
13+
具有两种配置方式
14+
15+
### 一般文件模式(默认)
16+
17+
你需要在程序**同目录**创建conf.ini文件,内容如下。
1518

1619
```
1720
[config]
@@ -23,7 +26,31 @@ url=http://adsb.feeyo.com/adsb/ReceiveCompressADSB.php
2326

2427
以上展现的是dump1090运行在本机的情况,你也可以按照实际情况进行填写。
2528

26-
如果你不具备编译条件,可以直接前往[本项目发布页](https://github.com/dextercai/feeyo-adsb-golang/releases)下载使用。
29+
### 命令行模式(进阶)
30+
31+
若对终端操作较为熟悉,可使用该方式。
32+
33+
```
34+
Usage of ./adsb:
35+
-conf string
36+
conf文件位置 (default "./conf.ini")
37+
-feeyo-url string
38+
飞常准接口地址 (default "https://adsb.feeyo.com/adsb/ReceiveCompressADSB.php")
39+
-ip string
40+
dump1090服务IP (default "127.0.0.1")
41+
-port string
42+
dump1090服务端口 (default "30003")
43+
-use-file
44+
是否使用conf文件作为配置来源 (default true)
45+
-uuid string
46+
UUID 16位
47+
```
48+
49+
## TODO
50+
- 统计、集成地图
51+
- 集成部分dump1090功能
52+
- webhook
53+
2754

2855
## 其他
2956

adsb.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"compress/zlib"
6+
"dextercai.com/feeyo-adsb-golang/conf"
7+
"dextercai.com/feeyo-adsb-golang/constant"
8+
"dextercai.com/feeyo-adsb-golang/log"
9+
"encoding/base64"
10+
"fmt"
11+
"io/ioutil"
12+
"net"
13+
"net/http"
14+
"net/url"
15+
"strings"
16+
"time"
17+
)
18+
19+
var err error
20+
21+
const eachPackage = 8192
22+
const thisLogFlag = "main"
23+
24+
func main() {
25+
fmt.Println("项目地址: https://github.com/dextercai/feeyo-adsb-golang 基于GPL3.0协议进行开源")
26+
fmt.Printf("当前版本:%s,编译时间:%s", constant.Version, constant.BuildTime)
27+
fmt.Println("")
28+
fmt.Println("敬告: 请不要尝试将相关电波数据传送至FR24, RadarBox, FA等境外平台, 这将严重违反无线电管理条例以及国家安全法!")
29+
fmt.Println("=============================================================================================")
30+
conf.ParseConf()
31+
if conf.GlobalConfig.UUID == "" ||
32+
len(conf.GlobalConfig.UUID) != 16 ||
33+
conf.GlobalConfig.IpDump1090 == "" ||
34+
conf.GlobalConfig.PortDump1090 == "" ||
35+
conf.GlobalConfig.FeeyoUrl == "" {
36+
37+
log.Logger.Fatalf("配置中存在错误")
38+
}
39+
for {
40+
dump1090Conn, err := net.Dial("tcp", conf.GlobalConfig.IpDump1090+":"+conf.GlobalConfig.PortDump1090)
41+
if err != nil {
42+
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "连接到Dump1090失败", err.Error())
43+
log.Logger.Printf("[%s]:%s", thisLogFlag, "15秒后重试")
44+
time.Sleep(15 * time.Second)
45+
continue
46+
} else {
47+
log.Logger.Printf("[%s]:%s", thisLogFlag, "连接到Dump1090成功")
48+
}
49+
var buf [eachPackage]byte
50+
for {
51+
read, err := dump1090Conn.Read(buf[0:])
52+
if err != nil {
53+
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "读取数据错误", err.Error())
54+
_ = dump1090Conn.Close()
55+
log.Logger.Printf("[%s]:%s", thisLogFlag, "已断开连接,正尝试重连")
56+
break
57+
} else {
58+
if buf[read-1] == 10 {
59+
sendMessage(buf[0:read])
60+
}
61+
}
62+
}
63+
}
64+
65+
}
66+
67+
func sendMessage(line []byte) {
68+
sourceData := base64.StdEncoding.EncodeToString(DoZlibCompress(line))
69+
postValue := url.Values{}
70+
postValue.Set("from", conf.GlobalConfig.UUID)
71+
postValue.Set("code", sourceData)
72+
resp, err := http.Post(conf.GlobalConfig.FeeyoUrl, "application/x-www-form-urlencoded", strings.NewReader(postValue.Encode()))
73+
if err != nil {
74+
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传错误", err.Error())
75+
return
76+
}
77+
defer resp.Body.Close()
78+
body, err := ioutil.ReadAll(resp.Body)
79+
if err != nil {
80+
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传错误", err.Error())
81+
} else {
82+
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传成功", string(body))
83+
}
84+
}
85+
86+
func DoZlibCompress(src []byte) []byte {
87+
var in bytes.Buffer
88+
w := zlib.NewWriter(&in)
89+
_, _ = w.Write(src)
90+
_ = w.Close()
91+
return in.Bytes()
92+
}
93+
94+
/*
95+
func DoZlibUnCompress(compressSrc []byte) []byte {
96+
b := bytes.NewReader(compressSrc)
97+
var out bytes.Buffer
98+
r, _ := zlib.NewReader(b)
99+
_, _ = io.Copy(&out, r)
100+
return out.Bytes()
101+
}
102+
103+
*/

conf/fileProvider.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package conf
2+
3+
import (
4+
"dextercai.com/feeyo-adsb-golang/log"
5+
"github.com/Unknwon/goconfig"
6+
)
7+
8+
type TConf struct {
9+
IpDump1090 string
10+
PortDump1090 string
11+
FeeyoUrl string
12+
UUID string
13+
}
14+
15+
var GlobalConfig TConf
16+
var Config *goconfig.ConfigFile
17+
18+
func reloadConfig(confLoc string) {
19+
var err error
20+
Config, err = goconfig.LoadConfigFile(confLoc)
21+
if err != nil {
22+
log.Logger.Fatalf("[Fatal]:conf.ini配置文件不存在,请检查.")
23+
}
24+
GlobalConfig.UUID, err = Config.GetValue("config", "UUID")
25+
GlobalConfig.IpDump1090, err = Config.GetValue("config", "ip")
26+
GlobalConfig.PortDump1090, err = Config.GetValue("config", "port")
27+
GlobalConfig.FeeyoUrl, err = Config.GetValue("config", "url")
28+
29+
if err != nil {
30+
log.Logger.Fatalf("[Fatal]:解析配置时出现错误")
31+
}
32+
}

conf/flagProvider.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package conf
2+
3+
import (
4+
"dextercai.com/feeyo-adsb-golang/log"
5+
"flag"
6+
)
7+
8+
var useFile bool
9+
var confFile string
10+
11+
func ParseConf() {
12+
flag.StringVar(&GlobalConfig.UUID, "uuid", "", "UUID 16位")
13+
flag.StringVar(&GlobalConfig.IpDump1090, "ip", "127.0.0.1", "dump1090服务IP")
14+
flag.StringVar(&GlobalConfig.PortDump1090, "port", "30003", "dump1090服务端口")
15+
flag.StringVar(&GlobalConfig.FeeyoUrl, "feeyo-url", "https://adsb.feeyo.com/adsb/ReceiveCompressADSB.php", "飞常准接口地址")
16+
flag.BoolVar(&useFile, "use-file", true, "是否使用conf文件作为配置来源")
17+
flag.StringVar(&confFile, "conf", "./conf.ini", "conf文件位置")
18+
19+
flag.Parse()
20+
21+
if useFile {
22+
reloadConfig(confFile)
23+
log.Logger.Printf("[%s]:%s%s", "CONF", "使用文件载入配置,文件位置:", confFile)
24+
} else {
25+
log.Logger.Printf("[%s]:%s", "CONF", "使用命令行参数载入配置")
26+
}
27+
}

constant/version.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package constant
2+
3+
var (
4+
Version = "unknown version"
5+
BuildTime = "unknown time"
6+
)

src/go.mod renamed to go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ module dextercai.com/feeyo-adsb-golang
33
go 1.13
44

55
// require github.com/Unknwon/goconfig v0.0.0-20200908083735-df7de6a44db8
6+
7+
require (
8+
github.com/Unknwon/goconfig v1.0.0
9+
github.com/smartystreets/goconvey v1.7.2 // indirect
10+
)

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
github.com/Unknwon/goconfig v1.0.0 h1:9IAu/BYbSLQi8puFjUQApZTxIHqSwrj5d8vpP8vTq4A=
2+
github.com/Unknwon/goconfig v1.0.0/go.mod h1:wngxua9XCNjvHjDiTiV26DaKDT+0c63QR6H5hjVUUxw=
3+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
4+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
5+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
6+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
7+
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
8+
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
9+
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
10+
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
11+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
12+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
13+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
14+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
15+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

log/log.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package log
2+
3+
import (
4+
"log"
5+
"os"
6+
)
7+
8+
var Logger *log.Logger
9+
10+
func init() {
11+
Logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
12+
}

0 commit comments

Comments
 (0)