Compare commits
	
		
			1 Commits
		
	
	
		
			Release-nf
			...
			Release-nf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					d72d2a8302 | 
							
								
								
									
										32
									
								
								.github/workflows/nfctl.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										32
									
								
								.github/workflows/nfctl.yml
									
									
									
									
										vendored
									
									
								
							@@ -5,7 +5,7 @@ on:
 | 
			
		||||
      - 'master'
 | 
			
		||||
 | 
			
		||||
env:
 | 
			
		||||
  RELEASE_VERSION: v24.07.14-r3
 | 
			
		||||
  RELEASE_VERSION: v24.07.13-r1
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  build-job:
 | 
			
		||||
@@ -25,38 +25,36 @@ jobs:
 | 
			
		||||
          go-version: '1.20'
 | 
			
		||||
 | 
			
		||||
      - name: build linux amd64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -ldflags='-s -w' -o "dist/nfctl-linux_amd64-${{ env.RELEASE_VERSION }}" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -ldflags='-s -w' -o dist/nfctl-linux_amd64-$RELEASE_VERSION nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: build linux arm64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=linux GOARCH=arm64 go build -ldflags='-s -w' -o "dist/nfctl-linux_arm64-${{ env.RELEASE_VERSION }}" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=linux GOARCH=arm64 go build -ldflags='-s -w' -o dist/nfctl-linux_arm64-$RELEASE_VERSION nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: build windows amd64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -ldflags='-s -w' -o "dist/nfctl-win_amd64-${{ env.RELEASE_VERSION }}.exe" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -ldflags='-s -w' -o dist/nfctl-win_amd64-$RELEASE_VERSION.exe nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: build windows arm64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=windows GOARCH=arm64 go build -ldflags='-s -w' -o "dist/nfctl-win_arm64-${{ env.RELEASE_VERSION }}.exe" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=windows GOARCH=arm64 go build -ldflags='-s -w' -o dist/nfctl-win_arm64-$RELEASE_VERSION.exe nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: build darwin amd64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=darwin GOARCH=amd64 go build -ldflags='-s -w' -o "dist/nfctl-darwin_amd64-${{ env.RELEASE_VERSION }}" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=darwin GOARCH=amd64 go build -ldflags='-s -w' -o dist/nfctl-darwin_arm64-$RELEASE_VERSION nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: build darwin arm64
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=darwin GOARCH=arm64 go build -ldflags='-s -w' -o "dist/nfctl-darwin_arm64-${{ env.RELEASE_VERSION }}" nft/nfctl/main.go
 | 
			
		||||
        run: CGO_ENABLE=0 GOOS=darwin GOARCH=arm64 go build -ldflags='-s -w' -o dist/nfctl-darwin_arm64-$RELEASE_VERSION nft/nfctl/main.go
 | 
			
		||||
 | 
			
		||||
      - name: show all builds
 | 
			
		||||
        run: ls -lash dist
 | 
			
		||||
 | 
			
		||||
      - name: create releases
 | 
			
		||||
        id: create_releases
 | 
			
		||||
        uses: "marvinpinto/action-automatic-releases@latest"
 | 
			
		||||
        with:
 | 
			
		||||
          automatic_release_tag: "Release-nfctl-${{ env.RELEASE_VERSION }}"
 | 
			
		||||
          automatic_release_tag: "Release-nfctl-$RELEASE_VERSION"
 | 
			
		||||
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
 | 
			
		||||
          title: "Release_${{ env.RELEASE_VERSION }}"
 | 
			
		||||
          title: "Release_$RELEASE_VERSION"
 | 
			
		||||
          prerelease: false
 | 
			
		||||
          files: |
 | 
			
		||||
            dist/nfctl-linux_amd64-${{ env.RELEASE_VERSION }}
 | 
			
		||||
            dist/nfctl-linux_arm64-${{ env.RELEASE_VERSION }}
 | 
			
		||||
            dist/nfctl-win_amd64-${{ env.RELEASE_VERSION }}.exe
 | 
			
		||||
            dist/nfctl-win_arm64-${{ env.RELEASE_VERSION }}.exe
 | 
			
		||||
            dist/nfctl-darwin_amd64-${{ env.RELEASE_VERSION }}
 | 
			
		||||
            dist/nfctl-darwin_arm64-${{ env.RELEASE_VERSION }}
 | 
			
		||||
            dist/nfctl-linux_amd64-$RELEASE_VERSION
 | 
			
		||||
            dist/nfctl-linux_arm64-$RELEASE_VERSION
 | 
			
		||||
            dist/nfctl-win_amd64-$RELEASE_VERSION.exe
 | 
			
		||||
            dist/nfctl-win_arm64-$RELEASE_VERSION.exe
 | 
			
		||||
            dist/nfctl-darwin_arm64-$RELEASE_VERSION
 | 
			
		||||
            dist/nfctl-darwin_arm64-$RELEASE_VERSION
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								ctx.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								ctx.go
									
									
									
									
									
								
							@@ -2,11 +2,9 @@ package nf
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/google/uuid"
 | 
			
		||||
	"github.com/loveuer/nf/internal/sse"
 | 
			
		||||
	"io"
 | 
			
		||||
	"mime/multipart"
 | 
			
		||||
@@ -40,18 +38,8 @@ type Ctx struct {
 | 
			
		||||
 | 
			
		||||
func newContext(app *App, writer http.ResponseWriter, request *http.Request) *Ctx {
 | 
			
		||||
 | 
			
		||||
	var (
 | 
			
		||||
		traceId      string
 | 
			
		||||
		skippedNodes = make([]skippedNode, 0, app.maxSections)
 | 
			
		||||
		v            = make(Params, 0, app.maxParams)
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if traceId = request.Header.Get(TraceKey); traceId == "" {
 | 
			
		||||
		traceId = uuid.Must(uuid.NewV7()).String()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	c := context.WithValue(request.Context(), TraceKey, traceId)
 | 
			
		||||
	request.WithContext(c)
 | 
			
		||||
	skippedNodes := make([]skippedNode, 0, app.maxSections)
 | 
			
		||||
	v := make(Params, 0, app.maxParams)
 | 
			
		||||
 | 
			
		||||
	ctx := &Ctx{
 | 
			
		||||
		lock:       sync.Mutex{},
 | 
			
		||||
@@ -124,10 +112,6 @@ func (c *Ctx) Cookies(key string, defaultValue ...string) string {
 | 
			
		||||
	return cookie.Value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Ctx) Context() context.Context {
 | 
			
		||||
	return c.Request.Context()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Ctx) Next() error {
 | 
			
		||||
	c.index++
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,9 +4,9 @@ go 1.20
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/fatih/color v1.17.0
 | 
			
		||||
	github.com/go-git/go-billy/v5 v5.5.0
 | 
			
		||||
	github.com/go-git/go-git/v5 v5.12.0
 | 
			
		||||
	github.com/google/uuid v1.6.0
 | 
			
		||||
	github.com/savioxavier/termlink v1.3.0
 | 
			
		||||
	github.com/spf13/cobra v1.8.1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +18,6 @@ require (
 | 
			
		||||
	github.com/cyphar/filepath-securejoin v0.2.4 // indirect
 | 
			
		||||
	github.com/emirpasic/gods v1.18.1 // indirect
 | 
			
		||||
	github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
 | 
			
		||||
	github.com/go-git/go-billy/v5 v5.5.0 // indirect
 | 
			
		||||
	github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
 | 
			
		||||
	github.com/inconshreveable/mousetrap v1.1.0 // indirect
 | 
			
		||||
	github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
 | 
			
		||||
@@ -26,14 +25,15 @@ require (
 | 
			
		||||
	github.com/mattn/go-colorable v0.1.13 // indirect
 | 
			
		||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
			
		||||
	github.com/pjbgf/sha1cd v0.3.0 // indirect
 | 
			
		||||
	github.com/savioxavier/termlink v1.3.0 // indirect
 | 
			
		||||
	github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
 | 
			
		||||
	github.com/skeema/knownhosts v1.2.2 // indirect
 | 
			
		||||
	github.com/spf13/pflag v1.0.5 // indirect
 | 
			
		||||
	github.com/xanzy/ssh-agent v0.3.3 // indirect
 | 
			
		||||
	golang.org/x/crypto v0.23.0 // indirect
 | 
			
		||||
	golang.org/x/crypto v0.21.0 // indirect
 | 
			
		||||
	golang.org/x/mod v0.12.0 // indirect
 | 
			
		||||
	golang.org/x/net v0.25.0 // indirect
 | 
			
		||||
	golang.org/x/sys v0.20.0 // indirect
 | 
			
		||||
	golang.org/x/net v0.22.0 // indirect
 | 
			
		||||
	golang.org/x/sys v0.18.0 // indirect
 | 
			
		||||
	golang.org/x/tools v0.13.0 // indirect
 | 
			
		||||
	gopkg.in/warnings.v0 v0.1.2 // indirect
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								go.sum
									
									
									
									
									
								
							@@ -83,8 +83,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
 | 
			
		||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
			
		||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
 | 
			
		||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
 | 
			
		||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
 | 
			
		||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
 | 
			
		||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
 | 
			
		||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
 | 
			
		||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 | 
			
		||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 | 
			
		||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
 | 
			
		||||
@@ -96,8 +96,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
 | 
			
		||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
 | 
			
		||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 | 
			
		||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
 | 
			
		||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
 | 
			
		||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
 | 
			
		||||
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
 | 
			
		||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 | 
			
		||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
@@ -116,14 +116,14 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
 | 
			
		||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
 | 
			
		||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
			
		||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 | 
			
		||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
 | 
			
		||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
 | 
			
		||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
 | 
			
		||||
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
 | 
			
		||||
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
 | 
			
		||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
			
		||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
			
		||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
			
		||||
@@ -131,7 +131,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 | 
			
		||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 | 
			
		||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 | 
			
		||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 | 
			
		||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
			
		||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 | 
			
		||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								nf.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								nf.go
									
									
									
									
									
								
							@@ -5,7 +5,6 @@ const (
 | 
			
		||||
	_404   = "<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1\"><meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"><title>Not Found</title><style>body{background:#333;margin:0;color:#ccc;display:flex;align-items:center;max-height:100vh;height:100vh;justify-content:center}textarea{min-height:5rem;min-width:20rem;text-align:center;border:none;background:0 0;color:#ccc;resize:none;user-input:none;user-select:none;cursor:default;-webkit-user-select:none;-webkit-touch-callout:none;-moz-user-select:none;-ms-user-select:none;outline:0}</style></head><body><textarea id=\"banner\" readonly=\"readonly\"></textarea><script type=\"text/javascript\">let htmlCodes = [\n    ' _  _     _     ___                 _ ',\n    '| \\\\| |___| |_  | __|__ _  _ _ _  __| |',\n    '| .` / _ \\\\  _| | _/ _ \\\\ || | \\' \\\\/ _` |',\n    '|_|\\\\_\\\\___/\\\\__| |_|\\\\___/\\\\_,_|_||_\\\\__,_|'\n].join('\\n');\ndocument.querySelector('#banner').value = htmlCodes</script></body></html>"
 | 
			
		||||
	_405   = `405 Method Not Allowed`
 | 
			
		||||
	_500   = `500 Internal Server Error`
 | 
			
		||||
	TraceKey = "X-Trace-Id"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Map map[string]interface{}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +0,0 @@
 | 
			
		||||
package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/version"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	checkCmd = &cobra.Command{
 | 
			
		||||
		Use:   "check",
 | 
			
		||||
		Short: "nfctl new version check",
 | 
			
		||||
		Run: func(cmd *cobra.Command, args []string) {
 | 
			
		||||
			version.Check(true, true, 30)
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
@@ -1,30 +1,19 @@
 | 
			
		||||
package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/loveuer/nf/nft/log"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/opt"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
import "github.com/spf13/cobra"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	Root = &cobra.Command{
 | 
			
		||||
		Use:   "nfctl",
 | 
			
		||||
		Short: "nfctl: easy start your nf backend work",
 | 
			
		||||
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
 | 
			
		||||
			if opt.Debug == true {
 | 
			
		||||
				log.SetLogLevel(log.LogLevelDebug)
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	initNew()
 | 
			
		||||
	Root.PersistentFlags().BoolVar(&opt.Debug, "debug", false, "debug mode")
 | 
			
		||||
 | 
			
		||||
	Root.AddCommand(
 | 
			
		||||
		versionCmd,
 | 
			
		||||
		checkCmd,
 | 
			
		||||
		cmdNew,
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@ import (
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/clone"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/opt"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/tp"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/version"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"os"
 | 
			
		||||
@@ -34,11 +33,14 @@ nfctl new {project} --template http://username:token@my.gitlab.com/my-zone/my-re
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func initNew() {
 | 
			
		||||
	cmdNew.Flags().BoolVar(&opt.Debug, "debug", false, "debug mode")
 | 
			
		||||
	cmdNew.Flags().StringVarP(&template, "template", "t", "", "template name/url[example:ultone, https://github.com/xxx/yyy.git]")
 | 
			
		||||
	cmdNew.Flags().BoolVar(&disableInit, "without-init", false, "don't run template init script")
 | 
			
		||||
 | 
			
		||||
	cmdNew.RunE = func(cmd *cobra.Command, args []string) error {
 | 
			
		||||
		version.Check(true, false, 5)
 | 
			
		||||
		if opt.Debug {
 | 
			
		||||
			log.SetLogLevel(log.LogLevelDebug)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var (
 | 
			
		||||
			err        error
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/fatih/color"
 | 
			
		||||
	"github.com/loveuer/nf/nft/log"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/version"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
@@ -11,8 +11,7 @@ var (
 | 
			
		||||
		Use:   "version",
 | 
			
		||||
		Short: "print nfctl version and exit",
 | 
			
		||||
		Run: func(cmd *cobra.Command, args []string) {
 | 
			
		||||
			color.Cyan("nfctl - version: %s", version.Version)
 | 
			
		||||
			version.Check(true, false, 5)
 | 
			
		||||
			log.Info("version: %s", version.Version)
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -3,17 +3,24 @@ package main
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/cmd"
 | 
			
		||||
	"github.com/loveuer/nf/nft/nfctl/version"
 | 
			
		||||
	"os/signal"
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	//if !(len(os.Args) >= 2 && os.Args[1] == "version") {
 | 
			
		||||
	//	version.Check(5)
 | 
			
		||||
	//}
 | 
			
		||||
	version.Check()
 | 
			
		||||
	defer version.Fn()
 | 
			
		||||
 | 
			
		||||
	_ = cmd.Root.ExecuteContext(ctx)
 | 
			
		||||
 | 
			
		||||
	select {
 | 
			
		||||
	case <-time.After(3 * time.Second):
 | 
			
		||||
	case <-ctx.Done():
 | 
			
		||||
	case <-version.OkCh:
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
package version
 | 
			
		||||
 | 
			
		||||
const Version = "v24.07.14-r3"
 | 
			
		||||
@@ -1,95 +1,68 @@
 | 
			
		||||
package version
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/tls"
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/fatih/color"
 | 
			
		||||
	"github.com/loveuer/nf/nft/log"
 | 
			
		||||
	"github.com/savioxavier/termlink"
 | 
			
		||||
	"io"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const Version = "v24.07.13-r1"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	uri    = "https://raw.gitcode.com/loveuer/nf/raw/master/nft/nfctl/version/var.go"
 | 
			
		||||
	prefix = "const Version = "
 | 
			
		||||
	lk      = &sync.Mutex{}
 | 
			
		||||
	empty   = func() {}
 | 
			
		||||
	upgrade = func(v string) func() {
 | 
			
		||||
		return func() {
 | 
			
		||||
			color.Green("\n🎉 🎉 🎉 [nfctl] New Version Found: %s", v)
 | 
			
		||||
			color.Cyan("Upgrade it with: [go install github.com/loveuer/nf/nft/nfctl@master]")
 | 
			
		||||
			fmt.Print("Or Download by: ")
 | 
			
		||||
			color.Cyan(termlink.Link("Releases", "https://github.com/loveuer/nf/releases"))
 | 
			
		||||
			fmt.Println()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	Fn   = empty
 | 
			
		||||
	OkCh = make(chan struct{}, 1)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func UpgradePrint(newVersion string) {
 | 
			
		||||
	fmt.Printf(`+----------------------------------------------------------------------+
 | 
			
		||||
|          🎉 🎉 🎉 %s 🎉 🎉 🎉          |
 | 
			
		||||
| %s |
 | 
			
		||||
| Or Download by:                                                      |
 | 
			
		||||
| %s                    |
 | 
			
		||||
| %s                   |
 | 
			
		||||
+----------------------------------------------------------------------+
 | 
			
		||||
`,
 | 
			
		||||
		color.GreenString("New Version Found: %s", newVersion),
 | 
			
		||||
		color.CyanString("Upgrade it with: [go install github.com/loveuer/nf/nft/nfctl@master]"),
 | 
			
		||||
		color.CyanString(termlink.Link("Releases", "https://github.com/loveuer/nf/releases")),
 | 
			
		||||
		color.CyanString(termlink.Link("Releases", "https://gitcode.com/loveuer/nf/releases")),
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Check(printUpgradable bool, printNoNeedUpgrade bool, timeouts ...int) string {
 | 
			
		||||
	var (
 | 
			
		||||
		v string
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if printUpgradable {
 | 
			
		||||
			if v > Version {
 | 
			
		||||
				UpgradePrint(v)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if printNoNeedUpgrade {
 | 
			
		||||
			if v == Version {
 | 
			
		||||
				color.Cyan("Your Version: %s is Newest", Version)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	timeout := time.Duration(30) * time.Second
 | 
			
		||||
	if len(timeouts) > 0 && timeouts[0] > 0 {
 | 
			
		||||
		timeout = time.Duration(timeouts[0]) * time.Second
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, _ := http.NewRequest(http.MethodGet, uri, nil)
 | 
			
		||||
	resp, err := (&http.Client{
 | 
			
		||||
		Timeout: timeout,
 | 
			
		||||
		Transport: &http.Transport{
 | 
			
		||||
			TLSClientConfig: &tls.Config{
 | 
			
		||||
				InsecureSkipVerify: true,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}).Do(req)
 | 
			
		||||
func Check() {
 | 
			
		||||
	ready := make(chan struct{})
 | 
			
		||||
	go func() {
 | 
			
		||||
		ready <- struct{}{}
 | 
			
		||||
		uri := "https://raw.gitcode.com/loveuer/nf/raw/master/nft/nfctl/version/version.go"
 | 
			
		||||
		prefix := "const Version = "
 | 
			
		||||
		resp, err := http.Get(uri)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Debug("[Check] http get[%s] err: %v", uri, err.Error())
 | 
			
		||||
		return ""
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		defer resp.Body.Close()
 | 
			
		||||
 | 
			
		||||
	content, err := io.ReadAll(resp.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Debug("[Check] http read all body err: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
		scanner := bufio.NewScanner(resp.Body)
 | 
			
		||||
		scanner.Buffer(make([]byte, 16*1024), 1024*1024)
 | 
			
		||||
 | 
			
		||||
	log.Debug("[Check] http get[%s] body:\n%s", uri, string(content))
 | 
			
		||||
 | 
			
		||||
	for _, line := range strings.Split(string(content), "\n") {
 | 
			
		||||
		for scanner.Scan() {
 | 
			
		||||
			line := scanner.Text()
 | 
			
		||||
			log.Debug("[Check] version.go line: %s", line)
 | 
			
		||||
			if strings.HasPrefix(line, prefix) {
 | 
			
		||||
			may := strings.TrimPrefix(line, prefix)
 | 
			
		||||
			if len(may) > 2 {
 | 
			
		||||
				v = may[1 : len(may)-1]
 | 
			
		||||
				v := strings.TrimPrefix(line, prefix)
 | 
			
		||||
				if len(v) > 2 {
 | 
			
		||||
					v = v[1 : len(v)-1]
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			return v
 | 
			
		||||
				if v != "" && v > Version {
 | 
			
		||||
					lk.Lock()
 | 
			
		||||
					Fn = upgrade(v)
 | 
			
		||||
					lk.Unlock()
 | 
			
		||||
					OkCh <- struct{}{}
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
	return ""
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
	<-ready
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +0,0 @@
 | 
			
		||||
package version
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/loveuer/nf/nft/log"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestUpgradePrint(t *testing.T) {
 | 
			
		||||
	log.SetLogLevel(log.LogLevelDebug)
 | 
			
		||||
	UpgradePrint("v24.07.14-r5")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestCheck(t *testing.T) {
 | 
			
		||||
	log.SetLogLevel(log.LogLevelDebug)
 | 
			
		||||
	v := Check(true, true, 1)
 | 
			
		||||
	t.Logf("got version: %s", v)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user