-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dextercai/dev
feat: flag与conf文件并行、CICD、更新文档
- Loading branch information
Showing
13 changed files
with
412 additions
and
121 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,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 |
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
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,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() | ||
} | ||
*/ |
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,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]:解析配置时出现错误") | ||
} | ||
} |
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,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", "使用命令行参数载入配置") | ||
} | ||
} |
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,6 @@ | ||
package constant | ||
|
||
var ( | ||
Version = "unknown version" | ||
BuildTime = "unknown time" | ||
) |
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
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,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= |
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 @@ | ||
package log | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
var Logger *log.Logger | ||
|
||
func init() { | ||
Logger = log.New(os.Stdout, "", log.Ldate|log.Ltime) | ||
} |
Oops, something went wrong.