Skip to content

Commit

Permalink
feat: update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2022 committed May 20, 2023
1 parent 3f80150 commit a5dec9f
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 38 deletions.
29 changes: 18 additions & 11 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ builds:
- binary: lt
ldflags:
- -s -w
- -X main.Version=v0.2.2
- -X main.Date={{ .Date }}
tags:
- netgo
- urfave_cli_no_docs
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- freebsd
- dragonfly
- netbsd
- openbsd
- solaris

goarch:
- 386
- "386"
- amd64
- arm
- arm64
Expand All @@ -29,20 +36,20 @@ builds:
- mips64
- mips64le

# goarm:
# - 6
# goamd64:
# - v2
goarm:
- "7"

goamd64:
- v2
# - v3

gomips:
- hardfloat
- softfloat

ignore:
- goos: darwin
goarch: 386 riscv64
- goos: linux
goarch: arm
goarm: 7
- goarm: mips64
- gomips: hardfloat
- goos: windows
Expand All @@ -66,12 +73,12 @@ archives:
- README.md

checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export PATH := $(GOPATH)/bin:$(PATH)
export GO111MODULE=on
LDFLAGS := -s -w
LDFLAGS := -s -w -X main.Version="v0.2.2" -X main.Date=$(shell date +"%Y-%m-%d")
TARGET := bin/lt

.PHONY: fmt build vet clean

Expand All @@ -15,9 +16,9 @@ fmt:
go mod tidy
gofumpt -l -w .

build:
env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/lt
build: clean fmt vet
env CGO_ENABLED=0 go build -tags urfave_cli_no_docs,netgo -trimpath -ldflags "$(LDFLAGS)" -o "$(TARGET)"

build_linux:
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/lt
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o "$(TARGET)"

22 changes: 20 additions & 2 deletions cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
"fmt"
"time"

"github.com/urfave/cli/v2"
"golang.org/x/exp/slog"
)

const (
Expand All @@ -19,16 +21,32 @@ type (
func newApp(local, server action) *cli.App {
app := cli.NewApp()
app.Name = "lt"
app.Usage = "export local port to remote"
app.Usage = "export local port to public server"

app.Compiled = time.Now()

ver := fmt.Sprintf("%s. build at %s", Version, Date)
app.Version = ver

app.Authors = []*cli.Author{
{
Name: "wei.xuan",
Email: "adamweixuan@gmail.com",
},
}

app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "verbos",
Value: false,
Usage: "verbos log",
Action: func(ctx *cli.Context, b bool) error {
UpdateLogger(slog.LevelDebug)
return nil
},
},
}

app.Commands = []*cli.Command{
newCliCmd(local),
newServCmd(server),
Expand All @@ -49,7 +67,7 @@ func newCliCmd(action func(*cli.Context) error) *cli.Command {
Required: true,
},
&cli.StringFlag{
Name: "secret,s",
Name: "secret",
Aliases: []string{"s"},
Usage: "secret",
EnvVars: []string{envKey},
Expand Down
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func NewClient(localPort, mappingPort int, secret, tunnelAddr string) *Client {
}

return client

}

func (c *Client) Start() error {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/adamweixuan/lt
module github.com/0x1042/localtunnel

go 1.20

Expand All @@ -7,7 +7,7 @@ require (
github.com/lmittmann/tint v0.3.3
github.com/urfave/cli/v2 v2.25.3
golang.org/x/crypto v0.9.0
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4=
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19 changes: 13 additions & 6 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io"
"os"
"time"

Expand All @@ -9,12 +10,18 @@ import (
)

func init() {
level := slog.LevelInfo
if os.Getenv("verbos") == "1" {
level = slog.LevelDebug
}
slog.SetDefault(slog.New(tint.NewHandler(os.Stderr, &tint.Options{
logger := NewLevelHandler(slog.LevelInfo, os.Stderr)
slog.SetDefault(logger)
}

func UpdateLogger(level slog.Level) {
logger := NewLevelHandler(level, os.Stderr)
slog.SetDefault(logger)
}

func NewLevelHandler(level slog.Level, writer io.Writer) *slog.Logger {
return slog.New(tint.NewHandler(writer, &tint.Options{
Level: level,
TimeFormat: time.RFC3339,
})))
}))
}
4 changes: 0 additions & 4 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ func parseChallengePacket(conn net.Conn) (uuid.UUID, error) {
return emptyUUID, err
}

// if ttype != challenge {
// return emptyUUID, errors.New("invalid message type ")
// }

id := make([]byte, 16)
if err := binary.Read(conn, binary.BigEndian, &id); err != nil {
return emptyUUID, err
Expand Down
16 changes: 10 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ func (svr *Server) Start() error {
slog.Error("accept fail.", slog.Any("err", err))
break
}
slog.Debug("incoming connection.", slog.String("remote", stream.RemoteAddr().String()))

remote := stream.RemoteAddr().String()
slog.Info("incoming connection.", slog.String("remote", remote))
Go("handle", func() {
defer func() {
if stream != nil {
_ = stream.Close()
}
slog.Info("client exit", slog.String("remote", remote))
}()
svr.handle(stream)
if stream != nil {
_ = stream.Close()
}
slog.Info("client exit")
})
}

Expand Down Expand Up @@ -148,7 +152,7 @@ func (svr *Server) handleHello(stream *net.TCPConn) error {

realPort := ln.Addr().(*net.TCPAddr).Port
packet := helloPacket(uint16(realPort))
slog.Debug("mapping port.", slog.Any("port", realPort))
slog.Info("mapping port.", slog.Any("port", realPort))
if _, err := stream.Write(packet); err != nil {
slog.Error("write hello message error", slog.Any("err", err))
return err
Expand Down
6 changes: 6 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

var (
Version string = "dev"
Date string = "unknown"
)

0 comments on commit a5dec9f

Please sign in to comment.