Skip to content

Commit

Permalink
跟随上游更新到v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fcwys committed Oct 3, 2023
1 parent 5e87a9f commit cfc6274
Show file tree
Hide file tree
Showing 38 changed files with 985 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '^1.19'
go-version: '^1.21'

- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
26 changes: 13 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM golang:alpine as builder

RUN apk add --no-cache make git
WORKDIR /nali-src
COPY . /nali-src
RUN go mod download && \
make docker && \
mv ./bin/nali-docker /nali

FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /nali /
FROM golang:alpine as builder

RUN apk add --no-cache make git
WORKDIR /nali-src
COPY . /nali-src
RUN go mod download && \
make docker && \
mv ./bin/nali-docker /nali

FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /nali /
ENTRYPOINT ["/nali"]
31 changes: 31 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"fmt"

"github.com/zu1k/nali/internal/constant"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// infoCmd represents the info command
var infoCmd = &cobra.Command{
Use: "info",
Short: "get the necessary information of nali",
Long: `get the necessary information of nali`,
Example: "nali info",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Nali Version: ", constant.Version)
fmt.Println("Config Dir Path: ", constant.ConfigDirPath)
fmt.Println("DB Data Dir Path: ", constant.DataDirPath)

fmt.Println("Selected IPv4 DB: ", viper.GetString("selected.ipv4"))
fmt.Println("Selected IPv6 DB: ", viper.GetString("selected.ipv6"))
fmt.Println("Selected CDN DB: ", viper.GetString("selected.cdn"))
},
}

func init() {
rootCmd.AddCommand(infoCmd)
}
16 changes: 14 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Find document on: https://github.com/zu1k/nali
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
gbk, _ := cmd.Flags().GetBool("gbk")
isJson, _ := cmd.Flags().GetBool("json")

if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
Expand All @@ -73,10 +74,20 @@ Find document on: https://github.com/zu1k/nali
if line := strings.TrimSpace(line); line == "quit" || line == "exit" {
return
}
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).ColorString())
if isJson {
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).Json())
} else {
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).ColorString())
}
}
} else {
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).ColorString())
if isJson {
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(strings.Join(args, " ")).Json())
} else {
for _, line := range args {
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString())
}
}
}
},
}
Expand All @@ -90,4 +101,5 @@ func Execute() {

func init() {
rootCmd.Flags().Bool("gbk", false, "Use GBK decoder")
rootCmd.Flags().BoolP("json", "j", false, "Output in JSON format")
}
8 changes: 4 additions & 4 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ var serverCmd = &cobra.Command{
} else {
//判断是否有CDN信息返回
if cname != "" && res[2].Info != "" {
cname = strings.Replace(res[2].Info, "\t", " ", -1)
cname = strings.Replace(res[2].InfoText, "\t", " ", -1)
}
reinfo := &Ipinfo{
Code: 1,
Ip: res[0].Text,
Addr: strings.Replace(res[0].Info, "\t", " ", -1),
Addr: strings.Replace(res[0].InfoText, "\t", " ", -1),
Cdn: cname,
}
c.JSON(200, reinfo)
Expand Down Expand Up @@ -167,12 +167,12 @@ var serverCmd = &cobra.Command{
} else {
//判断是否有CDN信息返回
if cname != "" && res[2].Info != "" {
cname = strings.Replace(res[2].Info, "\t", " ", -1)
cname = strings.Replace(res[2].InfoText, "\t", " ", -1)
}
reinfo := &Ipinfo{
Code: 1,
Ip: res[0].Text,
Addr: strings.Replace(res[0].Info, "\t", " ", -1),
Addr: strings.Replace(res[0].InfoText, "\t", " ", -1),
Cdn: cname,
}
c.JSON(200, reinfo)
Expand Down
21 changes: 16 additions & 5 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package cmd

import (
"log"
"strings"

"github.com/zu1k/nali/internal/db"
"github.com/zu1k/nali/internal/repo"

"github.com/spf13/cobra"
)

// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update",
Short: "update qqwry, zxipv6wry, ip2region ip database and cdn",
Long: `update qqwry, zxipv6wry, ip2region ip database and cdn. Use commas to separate`,
Example: "nali update --db qqwry,cdn",
Use: "update [--db dbs -v]",
Short: "update qqwry, zxipv6wry, ip2region ip database and cdn, update nali to latest version if -v",
Long: `update qqwry, zxipv6wry, ip2region ip database and cdn. Use commas to separate. update nali to latest version if -v`,
Example: "nali update --db qqwry,cdn -v",
Run: func(cmd *cobra.Command, args []string) {
DBs, _ := cmd.Flags().GetString("db")

version, _ := cmd.Flags().GetBool("v")
if version {
if err := repo.UpdateRepo(); err != nil {
log.Printf("update nali to latest version failed: %v \n", err)
}
}

var DBNameArray []string
if DBs != "" {
DBNameArray = strings.Split(DBs, ",")
Expand All @@ -25,6 +35,7 @@ var updateCmd = &cobra.Command{
}

func init() {
updateCmd.PersistentFlags().String("db", "", "choose db you want to update")
updateCmd.PersistentFlags().Bool("v", false, "decide whether to update the nali version")
rootCmd.AddCommand(updateCmd)
rootCmd.PersistentFlags().String("db", "", "choose db you want to update")
}
83 changes: 45 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
module github.com/zu1k/nali

go 1.18
go 1.19

require (
github.com/adrg/xdg v0.4.0
github.com/fatih/color v1.13.0
github.com/gin-gonic/gin v1.7.7
github.com/fatih/color v1.15.0
github.com/google/go-github/v55 v55.0.0
github.com/google/martian v2.1.0+incompatible
github.com/ip2location/ip2location-go/v9 v9.2.0
github.com/ipipdotnet/ipdb-go v1.3.1
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20221017063954-c5c24655eb63
github.com/oschwald/geoip2-golang v1.7.0
github.com/ip2location/ip2location-go/v9 v9.6.0
github.com/ipipdotnet/ipdb-go v1.3.3
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230731060429-6ed8bf011875
github.com/oschwald/geoip2-golang v1.9.0
github.com/saracen/go7z v0.0.0-20191010121135-9c09b6bd7fda
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
golang.org/x/text v0.3.7
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
golang.org/x/text v0.12.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oschwald/maxminddb-golang v1.9.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/oschwald/maxminddb-golang v1.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/saracen/go7z-fixtures v0.0.0-20190623165746-aa6b8fba1d2f // indirect
github.com/saracen/solidblock v0.0.0-20190426153529-45df20abab6f // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/tools v0.1.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
)
Loading

0 comments on commit cfc6274

Please sign in to comment.