Skip to content

Commit

Permalink
v0.0.3 - 优化参数解析和增加日志记录参数
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jul 2, 2024
1 parent 9a00acf commit 8168988
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
TAG="v0.0.2-$(date +'%Y%m%d%H%M%S')"
TAG="v0.0.3-$(date +'%Y%m%d%H%M%S')"
git tag $TAG
git push origin $TAG
env:
Expand Down
22 changes: 15 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net/http"
"os"
"strings"

"github.com/oneclickvirt/nt3/model"
Expand All @@ -15,14 +16,21 @@ func main() {
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fnt3&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false")
}()
fmt.Println("项目地址:", "https://github.com/oneclickvirt/nt3")
var showVersion bool
var showVersion, help bool
var language, checkType, location string
flag.BoolVar(&showVersion, "v", false, "Show version information")
flag.StringVar(&language, "l", "zh", "Specify language parameter (en or zh)")
flag.StringVar(&checkType, "c", "ipv4", "Specify check type (both, ipv4, or ipv6)")
flag.StringVar(&location, "loc", "GZ", "Specify location (supports GZ, BJ, SH, CD; corresponding to Guangzhou, Beijing, Shanghai, Chengdu)")
// flag.BoolVar(&model.EnableLoger, "log", false, "Enable logging")
flag.Parse()
nt3Flag := flag.NewFlagSet("nt3", flag.ContinueOnError)
nt3Flag.BoolVar(&help, "h", false, "Show help information")
nt3Flag.BoolVar(&showVersion, "v", false, "Show version information")
nt3Flag.StringVar(&language, "l", "zh", "Specify language parameter (en or zh)")
nt3Flag.StringVar(&checkType, "c", "ipv4", "Specify check type (both, ipv4, or ipv6)")
nt3Flag.StringVar(&location, "loc", "GZ", "Specify location (supports GZ, BJ, SH, CD; corresponding to Guangzhou, Beijing, Shanghai, Chengdu)")
nt3Flag.BoolVar(&model.EnableLoger, "log", false, "Enable logging")
nt3Flag.Parse(os.Args[1:])
if help {
fmt.Printf("Usage: %s [options]\n", os.Args[0])
nt3Flag.PrintDefaults()
return
}
if showVersion {
fmt.Println(model.NextTraceVersion)
return
Expand Down
5 changes: 3 additions & 2 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type ParamsFastTrace struct {
DontFragment bool
}

// var EnableLoger bool
var NextTraceVersion = "v0.0.2"
var NextTraceVersion = "v0.0.3"

var EnableLoger = false

var (
GuangZhouCT = fastTrace.ISPCollection{
Expand Down
12 changes: 8 additions & 4 deletions nt/nt.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ func tracert(f fastTrace.FastTracer, ispCollection fastTrace.ISPCollection) {
//conf.RealtimePrinter = printer.RealtimePrinter
//conf.RealtimePrinter = tracelog.RealtimePrinter
_, err = trace.Traceroute(f.TracerouteMethod, conf)
if err != nil {
log.Fatal(err)
if err != nil && model.EnableLoger {
InitLogger()
defer Logger.Sync()
Logger.Info("trace failed: " + err.Error())
}
}

Expand Down Expand Up @@ -182,8 +184,10 @@ func tracert_v6(f fastTrace.FastTracer, ispCollection fastTrace.ISPCollection) {
//conf.RealtimePrinter = printer.RealtimePrinter
//conf.RealtimePrinter = tracelog.RealtimePrinter
_, err = trace.Traceroute(f.TracerouteMethod, conf)
if err != nil {
log.Fatal(err)
if err != nil && model.EnableLoger {
InitLogger()
defer Logger.Sync()
Logger.Info("trace failed: " + err.Error())
}
}

Expand Down

0 comments on commit 8168988

Please sign in to comment.