refactor: change structure
parent
1dd6c3c7b8
commit
18b81a4a32
29
Makefile
29
Makefile
|
@ -10,6 +10,13 @@ LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"
|
||||||
PLATFORMS=darwin linux
|
PLATFORMS=darwin linux
|
||||||
ARCHITECTURES=amd64
|
ARCHITECTURES=amd64
|
||||||
|
|
||||||
|
BASIC_PATH=cmd/basic/main.go
|
||||||
|
BASIC=myip-basic
|
||||||
|
FULL_PATH=cmd/myip/main.go
|
||||||
|
FULL=myip
|
||||||
|
GUI_PATH=cmd/myip/main.go
|
||||||
|
GUI=cmd/myip/main.go
|
||||||
|
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
@ -21,25 +28,31 @@ clean:
|
||||||
|
|
||||||
.PHONY: basic
|
.PHONY: basic
|
||||||
basic:
|
basic:
|
||||||
go build ${LDFLAGS} -o dist/myip-basic basic/main.go
|
go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build ${LDFLAGS} -o dist/myip
|
go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}
|
||||||
|
|
||||||
build-unix:
|
build-unix:
|
||||||
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
||||||
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ))))
|
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}) \
|
||||||
|
$(shell cd dist; tar -czf ${FULL}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${FULL}) \
|
||||||
|
))
|
||||||
|
rm dist/${FULL}
|
||||||
|
|
||||||
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
||||||
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ)-basic basic/main.go)))
|
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}) \
|
||||||
|
$(shell cd dist; tar -czf ${BASIC}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${BASIC}) \
|
||||||
|
))
|
||||||
|
rm dist/${BASIC}
|
||||||
|
|
||||||
build-win:
|
build-win:
|
||||||
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/$(PROJ).exe)
|
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/${FULL}.exe ${FULL_PATH})
|
||||||
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/$(PROJ)-basic.exe basic/main.go)
|
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/${BASIC}.exe ${BASIC_PATH})
|
||||||
|
|
||||||
build-mac-m1:
|
build-mac-m1:
|
||||||
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/$(PROJ))
|
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/${FULL} ${FULL_PATH})
|
||||||
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/$(PROJ)-basic basic/main.go)
|
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/${BASIC} ${BASIC_PATH})
|
||||||
|
|
||||||
build-zip:
|
build-zip:
|
||||||
cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done
|
cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done
|
||||||
|
|
|
@ -36,6 +36,13 @@ Use "myip [command] --help" for more information about a command.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo rm -f /usr/local/bin/myip
|
||||||
|
sudo sh -c "curl -fsSL https://release.kumoly.io/tools/myip/0.1.6/linux/amd64 | tar -C /usr/local/bin/ -xz"
|
||||||
|
```
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package myip
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -75,6 +75,9 @@ func init() {
|
||||||
|
|
||||||
ClientCmd.Flags().BoolVar(&cronMode, "cron", false, "run as cron service")
|
ClientCmd.Flags().BoolVar(&cronMode, "cron", false, "run as cron service")
|
||||||
ClientCmd.Flags().StringVarP(&cronSpec, "spec", "s", "0 */5 * * * *", "hostname to connect")
|
ClientCmd.Flags().StringVarP(&cronSpec, "spec", "s", "0 */5 * * * *", "hostname to connect")
|
||||||
|
|
||||||
|
ClientCmd.AddCommand(ServerCmd)
|
||||||
|
ClientCmd.AddCommand(LocalIPCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Scan() error {
|
func Scan() error {
|
|
@ -29,7 +29,7 @@ func init() {
|
||||||
name, _ = os.Hostname()
|
name, _ = os.Hostname()
|
||||||
flag.BoolVar(&showVer, "v", false, "show version")
|
flag.BoolVar(&showVer, "v", false, "show version")
|
||||||
flag.StringVar(&host, "u", "kumoly.io", "hostname to ask for")
|
flag.StringVar(&host, "u", "kumoly.io", "hostname to ask for")
|
||||||
flag.StringVar(&port, "p", "5080", "port to listen|connect")
|
flag.StringVar(&port, "p", "5080", "port to connect")
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: myip-basic [options]\n")
|
fmt.Fprintf(os.Stderr, "Usage: myip-basic [options]\n")
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"kumoly.io/tools/myip/cmd"
|
"kumoly.io/tools/myip"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.1.0"
|
var Version = "v0.1.0"
|
||||||
|
@ -24,14 +24,12 @@ var versionCmd = &cobra.Command{
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
cmd.ClientCmd.Version = Version + "-" + Build
|
myip.ClientCmd.Version = Version + "-" + Build
|
||||||
cmd.ClientCmd.AddCommand(versionCmd)
|
myip.ClientCmd.AddCommand(versionCmd)
|
||||||
cmd.ClientCmd.AddCommand(cmd.ServerCmd)
|
|
||||||
cmd.ClientCmd.AddCommand(cmd.LocalIPCmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.ClientCmd.Execute(); err != nil {
|
if err := myip.ClientCmd.Execute(); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package myip
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package myip
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue