Skip to content

Commit

Permalink
Merge pull request #8 from dextercai/dev
Browse files Browse the repository at this point in the history
feat: flag与conf文件并行、CICD、更新文档
  • Loading branch information
dextercai authored May 7, 2022
2 parents 055aa53 + bd647c1 commit 1f5a38f
Show file tree
Hide file tree
Showing 13 changed files with 412 additions and 121 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get latest go version
id: version
run: |
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')
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ steps.version.outputs.go_version }}

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Cache go module
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
#- name: Get dependencies, run test
# run: |
# go test ./...

- name: Build
if: startsWith(github.ref, 'refs/tags/')
env:
NAME: feeyo-adsb-golang
BINDIR: bin
run: make -j releases

- name: Upload Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: bin/*
draft: true
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

## 使用说明

本项目已更新,修改为Golang 1.11起支持的Go modules。
主分支去除了UUID生成器的代码,但依旧保留二进制版本,请自定义UUID时确保不与其他人冲突。

由于本项目不包括Dump1090,也不限制SBS服务是否运行在本机,因此你可能需要首先安装Dump1090,具体细节可自行搜索,当然你也可以在本项目提一个Issue,我将很乐意为你解答。

你需要编辑conf.ini文件
如果你不具备编译条件,可以直接前往[本项目发布页](https://github.com/dextercai/feeyo-adsb-golang/releases)下载使用。

具有两种配置方式

### 一般文件模式(默认)

你需要在程序**同目录**创建conf.ini文件,内容如下。

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

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

如果你不具备编译条件,可以直接前往[本项目发布页](https://github.com/dextercai/feeyo-adsb-golang/releases)下载使用。
### 命令行模式(进阶)

若对终端操作较为熟悉,可使用该方式。

```
Usage of ./adsb:
-conf string
conf文件位置 (default "./conf.ini")
-feeyo-url string
飞常准接口地址 (default "https://adsb.feeyo.com/adsb/ReceiveCompressADSB.php")
-ip string
dump1090服务IP (default "127.0.0.1")
-port string
dump1090服务端口 (default "30003")
-use-file
是否使用conf文件作为配置来源 (default true)
-uuid string
UUID 16位
```

## TODO
- 统计、集成地图
- 集成部分dump1090功能
- webhook


## 其他

Expand Down
103 changes: 103 additions & 0 deletions adsb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"bytes"
"compress/zlib"
"dextercai.com/feeyo-adsb-golang/conf"
"dextercai.com/feeyo-adsb-golang/constant"
"dextercai.com/feeyo-adsb-golang/log"
"encoding/base64"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
)

var err error

const eachPackage = 8192
const thisLogFlag = "main"

func main() {
fmt.Println("项目地址: https://github.com/dextercai/feeyo-adsb-golang 基于GPL3.0协议进行开源")
fmt.Printf("当前版本:%s,编译时间:%s", constant.Version, constant.BuildTime)
fmt.Println("")
fmt.Println("敬告: 请不要尝试将相关电波数据传送至FR24, RadarBox, FA等境外平台, 这将严重违反无线电管理条例以及国家安全法!")
fmt.Println("=============================================================================================")
conf.ParseConf()
if conf.GlobalConfig.UUID == "" ||
len(conf.GlobalConfig.UUID) != 16 ||
conf.GlobalConfig.IpDump1090 == "" ||
conf.GlobalConfig.PortDump1090 == "" ||
conf.GlobalConfig.FeeyoUrl == "" {

log.Logger.Fatalf("配置中存在错误")
}
for {
dump1090Conn, err := net.Dial("tcp", conf.GlobalConfig.IpDump1090+":"+conf.GlobalConfig.PortDump1090)
if err != nil {
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "连接到Dump1090失败", err.Error())
log.Logger.Printf("[%s]:%s", thisLogFlag, "15秒后重试")
time.Sleep(15 * time.Second)
continue
} else {
log.Logger.Printf("[%s]:%s", thisLogFlag, "连接到Dump1090成功")
}
var buf [eachPackage]byte
for {
read, err := dump1090Conn.Read(buf[0:])
if err != nil {
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "读取数据错误", err.Error())
_ = dump1090Conn.Close()
log.Logger.Printf("[%s]:%s", thisLogFlag, "已断开连接,正尝试重连")
break
} else {
if buf[read-1] == 10 {
sendMessage(buf[0:read])
}
}
}
}

}

func sendMessage(line []byte) {
sourceData := base64.StdEncoding.EncodeToString(DoZlibCompress(line))
postValue := url.Values{}
postValue.Set("from", conf.GlobalConfig.UUID)
postValue.Set("code", sourceData)
resp, err := http.Post(conf.GlobalConfig.FeeyoUrl, "application/x-www-form-urlencoded", strings.NewReader(postValue.Encode()))
if err != nil {
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传错误", err.Error())
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传错误", err.Error())
} else {
log.Logger.Printf("[%s]:%s\t%s", thisLogFlag, "上传成功", string(body))
}
}

func DoZlibCompress(src []byte) []byte {
var in bytes.Buffer
w := zlib.NewWriter(&in)
_, _ = w.Write(src)
_ = w.Close()
return in.Bytes()
}

/*
func DoZlibUnCompress(compressSrc []byte) []byte {
b := bytes.NewReader(compressSrc)
var out bytes.Buffer
r, _ := zlib.NewReader(b)
_, _ = io.Copy(&out, r)
return out.Bytes()
}
*/
32 changes: 32 additions & 0 deletions conf/fileProvider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package conf

import (
"dextercai.com/feeyo-adsb-golang/log"
"github.com/Unknwon/goconfig"
)

type TConf struct {
IpDump1090 string
PortDump1090 string
FeeyoUrl string
UUID string
}

var GlobalConfig TConf
var Config *goconfig.ConfigFile

func reloadConfig(confLoc string) {
var err error
Config, err = goconfig.LoadConfigFile(confLoc)
if err != nil {
log.Logger.Fatalf("[Fatal]:conf.ini配置文件不存在,请检查.")
}
GlobalConfig.UUID, err = Config.GetValue("config", "UUID")
GlobalConfig.IpDump1090, err = Config.GetValue("config", "ip")
GlobalConfig.PortDump1090, err = Config.GetValue("config", "port")
GlobalConfig.FeeyoUrl, err = Config.GetValue("config", "url")

if err != nil {
log.Logger.Fatalf("[Fatal]:解析配置时出现错误")
}
}
27 changes: 27 additions & 0 deletions conf/flagProvider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package conf

import (
"dextercai.com/feeyo-adsb-golang/log"
"flag"
)

var useFile bool
var confFile string

func ParseConf() {
flag.StringVar(&GlobalConfig.UUID, "uuid", "", "UUID 16位")
flag.StringVar(&GlobalConfig.IpDump1090, "ip", "127.0.0.1", "dump1090服务IP")
flag.StringVar(&GlobalConfig.PortDump1090, "port", "30003", "dump1090服务端口")
flag.StringVar(&GlobalConfig.FeeyoUrl, "feeyo-url", "https://adsb.feeyo.com/adsb/ReceiveCompressADSB.php", "飞常准接口地址")
flag.BoolVar(&useFile, "use-file", true, "是否使用conf文件作为配置来源")
flag.StringVar(&confFile, "conf", "./conf.ini", "conf文件位置")

flag.Parse()

if useFile {
reloadConfig(confFile)
log.Logger.Printf("[%s]:%s%s", "CONF", "使用文件载入配置,文件位置:", confFile)
} else {
log.Logger.Printf("[%s]:%s", "CONF", "使用命令行参数载入配置")
}
}
6 changes: 6 additions & 0 deletions constant/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package constant

var (
Version = "unknown version"
BuildTime = "unknown time"
)
5 changes: 5 additions & 0 deletions src/go.mod → go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ module dextercai.com/feeyo-adsb-golang
go 1.13

// require github.com/Unknwon/goconfig v0.0.0-20200908083735-df7de6a44db8

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

import (
"log"
"os"
)

var Logger *log.Logger

func init() {
Logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
}
Loading

0 comments on commit 1f5a38f

Please sign in to comment.