Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
5e8c3bd70a | |
|
aa3d4a1615 | |
|
18b81a4a32 | |
|
1dd6c3c7b8 |
|
@ -1,4 +1,4 @@
|
||||||
# 0.1.5
|
# 0.1.6
|
||||||
|
|
||||||
## Feature
|
## Feature
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ COPY . .
|
||||||
RUN VERSION=$(git describe --tags) BUILD=$(git rev-parse --short HEAD) && \
|
RUN VERSION=$(git describe --tags) BUILD=$(git rev-parse --short HEAD) && \
|
||||||
GOOS=linux GOARCH=amd64 \
|
GOOS=linux GOARCH=amd64 \
|
||||||
go build -ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" \
|
go build -ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" \
|
||||||
-o /go/bin/myip main.go
|
-o /go/bin/myip cmd/myip/main.go
|
||||||
|
|
||||||
FROM alpine:3.14
|
FROM alpine:3.14
|
||||||
|
|
||||||
|
|
34
Makefile
34
Makefile
|
@ -10,6 +10,9 @@ LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"
|
||||||
PLATFORMS=darwin linux
|
PLATFORMS=darwin linux
|
||||||
ARCHITECTURES=amd64
|
ARCHITECTURES=amd64
|
||||||
|
|
||||||
|
|
||||||
|
APPS=myip myip-basic
|
||||||
|
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
@ -21,25 +24,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), $(foreach APP, $(APPS),\
|
||||||
$(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/$(APP) cmd/$(APP)/main.go) \
|
||||||
|
$(shell cd dist; tar -czf ${APP}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${APP}) \
|
||||||
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
$(shell rm dist/${APP}) \
|
||||||
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ)-basic basic/main.go)))
|
)))
|
||||||
|
|
||||||
build-win:
|
build-win:
|
||||||
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/$(PROJ).exe)
|
$(foreach APP, $(APPS), \
|
||||||
$(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/${APP}.exe cmd/$(APP)/main.go) \
|
||||||
|
$(shell cd dist; tar -czf ${APP}_$(VERSION)_windows_amd64.tar.gz ${APP}.exe) \
|
||||||
|
$(shell rm dist/${APP}.exe) \
|
||||||
|
)
|
||||||
|
|
||||||
build-mac-m1:
|
build-mac-m1:
|
||||||
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/$(PROJ))
|
$(foreach APP, $(APPS),\
|
||||||
$(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/$(APP) cmd/$(APP)/main.go) \
|
||||||
|
$(shell cd dist; tar -czf ${APP}_$(VERSION)_darwin_arm64.tar.gz ${APP}) \
|
||||||
|
$(shell rm dist/${APP}) \
|
||||||
|
)
|
||||||
|
|
||||||
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
|
||||||
|
@ -61,6 +70,7 @@ docker-save:
|
||||||
docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz
|
docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz
|
||||||
|
|
||||||
|
|
||||||
release: clean binary build-zip docker docker-save docker-push
|
release: clean binary docker docker-save
|
||||||
|
|
||||||
|
|
||||||
.PHONY: build docker release clean all binary install
|
.PHONY: build docker release clean all binary install
|
|
@ -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
|
||||||
|
@ -71,7 +78,7 @@ docker run --name myip -d --restart=always hub.kumoly.io/tools/myip myip --cron
|
||||||
## Cron
|
## Cron
|
||||||
|
|
||||||
```
|
```
|
||||||
ield name | Mandatory? | Allowed values | Allowed special characters
|
field name | Mandatory? | Allowed values | Allowed special characters
|
||||||
---------- | ---------- | -------------- | --------------------------
|
---------- | ---------- | -------------- | --------------------------
|
||||||
Seconds | Yes | 0-59 | * / , -
|
Seconds | Yes | 0-59 | * / , -
|
||||||
Minutes | Yes | 0-59 | * / , -
|
Minutes | Yes | 0-59 | * / , -
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -70,7 +71,9 @@ func StartServer() error {
|
||||||
func GetIP(r *http.Request) string {
|
func GetIP(r *http.Request) string {
|
||||||
ip := r.Header.Get("X-Real-Ip")
|
ip := r.Header.Get("X-Real-Ip")
|
||||||
if ip == "" {
|
if ip == "" {
|
||||||
ip = r.Header.Get("X-Forwarded-For")
|
ips := r.Header.Get("X-Forwarded-For")
|
||||||
|
ipArr := strings.Split(ips, ",")
|
||||||
|
ip = strings.Trim(ipArr[len(ipArr)-1], " ")
|
||||||
}
|
}
|
||||||
if ip == "" {
|
if ip == "" {
|
||||||
var err error
|
var err error
|
Loading…
Reference in New Issue