Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Evan Chen | 5e8c3bd70a | |
Evan Chen | aa3d4a1615 | |
Evan Chen | 18b81a4a32 | |
Evan Chen | 1dd6c3c7b8 |
|
@ -1,4 +1,4 @@
|
|||
# 0.1.5
|
||||
# 0.1.6
|
||||
|
||||
## Feature
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ COPY . .
|
|||
RUN VERSION=$(git describe --tags) BUILD=$(git rev-parse --short HEAD) && \
|
||||
GOOS=linux GOARCH=amd64 \
|
||||
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
|
||||
|
||||
|
|
34
Makefile
34
Makefile
|
@ -10,6 +10,9 @@ LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"
|
|||
PLATFORMS=darwin linux
|
||||
ARCHITECTURES=amd64
|
||||
|
||||
|
||||
APPS=myip myip-basic
|
||||
|
||||
default: build
|
||||
|
||||
install:
|
||||
|
@ -21,25 +24,31 @@ clean:
|
|||
|
||||
.PHONY: basic
|
||||
basic:
|
||||
go build ${LDFLAGS} -o dist/myip-basic basic/main.go
|
||||
go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}
|
||||
|
||||
build:
|
||||
go build ${LDFLAGS} -o dist/myip
|
||||
go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}
|
||||
|
||||
build-unix:
|
||||
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
|
||||
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ))))
|
||||
|
||||
$(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)))
|
||||
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), $(foreach APP, $(APPS),\
|
||||
$(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}) \
|
||||
$(shell rm dist/${APP}) \
|
||||
)))
|
||||
|
||||
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)-basic_$(VERSION)_windows_amd64/$(PROJ)-basic.exe basic/main.go)
|
||||
$(foreach APP, $(APPS), \
|
||||
$(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:
|
||||
$(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)-basic_$(VERSION)_darwin_arm64/$(PROJ)-basic basic/main.go)
|
||||
$(foreach APP, $(APPS),\
|
||||
$(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:
|
||||
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
|
||||
|
||||
|
||||
release: clean binary build-zip docker docker-save docker-push
|
||||
release: clean binary docker docker-save
|
||||
|
||||
|
||||
.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
|
||||
|
||||
### Server
|
||||
|
@ -71,7 +78,7 @@ docker run --name myip -d --restart=always hub.kumoly.io/tools/myip myip --cron
|
|||
## Cron
|
||||
|
||||
```
|
||||
ield name | Mandatory? | Allowed values | Allowed special characters
|
||||
field name | Mandatory? | Allowed values | Allowed special characters
|
||||
---------- | ---------- | -------------- | --------------------------
|
||||
Seconds | Yes | 0-59 | * / , -
|
||||
Minutes | Yes | 0-59 | * / , -
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package myip
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -75,6 +75,9 @@ func init() {
|
|||
|
||||
ClientCmd.Flags().BoolVar(&cronMode, "cron", false, "run as cron service")
|
||||
ClientCmd.Flags().StringVarP(&cronSpec, "spec", "s", "0 */5 * * * *", "hostname to connect")
|
||||
|
||||
ClientCmd.AddCommand(ServerCmd)
|
||||
ClientCmd.AddCommand(LocalIPCmd)
|
||||
}
|
||||
|
||||
func Scan() error {
|
|
@ -29,7 +29,7 @@ func init() {
|
|||
name, _ = os.Hostname()
|
||||
flag.BoolVar(&showVer, "v", false, "show version")
|
||||
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() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: myip-basic [options]\n")
|
|
@ -6,7 +6,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"kumoly.io/tools/myip/cmd"
|
||||
"kumoly.io/tools/myip"
|
||||
)
|
||||
|
||||
var Version = "v0.1.0"
|
||||
|
@ -24,14 +24,12 @@ var versionCmd = &cobra.Command{
|
|||
func init() {
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(os.Stdout)
|
||||
cmd.ClientCmd.Version = Version + "-" + Build
|
||||
cmd.ClientCmd.AddCommand(versionCmd)
|
||||
cmd.ClientCmd.AddCommand(cmd.ServerCmd)
|
||||
cmd.ClientCmd.AddCommand(cmd.LocalIPCmd)
|
||||
myip.ClientCmd.Version = Version + "-" + Build
|
||||
myip.ClientCmd.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := cmd.ClientCmd.Execute(); err != nil {
|
||||
if err := myip.ClientCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package myip
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package myip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -70,7 +71,9 @@ func StartServer() error {
|
|||
func GetIP(r *http.Request) string {
|
||||
ip := r.Header.Get("X-Real-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 == "" {
|
||||
var err error
|
Loading…
Reference in New Issue