Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/ooclab/es/ecrypt"
"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

func testEcho(conn Conn) error {
Expand Down
81 changes: 81 additions & 0 deletions docs/zh_CN/Go环境与多平台编译指南.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Go 环境与多平台编译指南

本文档用于在本地用较新的 Go 版本重新构建 `ooclab/es`,并给出与 `ooclab/otunnel` 联调时的建议流程。

## 1. 安装 Go(建议)

建议使用 **Go 1.25+**(本仓库已使用模块化管理)。

### macOS (Homebrew)

```bash
brew update
brew install go
```

### Ubuntu/Debian

```bash
sudo apt-get update
sudo apt-get install -y golang-go
```

### 验证

```bash
go version
go env GOPATH GOMOD
```

## 2. 获取并构建 es

```bash
git clone https://github.com/ooclab/es.git
cd es
go mod tidy
go test ./...
```

> 当前仓库已内置 `github.com/ooclab/es/logger` 日志适配包,不依赖外部日志模块。

## 3. 多平台编译(es)

仓库提供了脚本:

```bash
./scripts/build_multi_platform.sh
```

脚本会对以下目标执行 `go build ./...`:

- linux/amd64
- linux/arm64
- darwin/amd64
- darwin/arm64
- windows/amd64

## 4. 与 otunnel 联调(本地依赖 es)

当 `otunnel` 依赖本地修改版 `es` 时,在 `otunnel/go.mod` 中增加:

```go
replace github.com/ooclab/es => /path/to/your/es
```

然后在 `otunnel` 仓库执行:

```bash
go mod tidy
go test ./...
GOOS=linux GOARCH=amd64 go build ./...
GOOS=linux GOARCH=arm64 go build ./...
GOOS=darwin GOARCH=amd64 go build ./...
GOOS=darwin GOARCH=arm64 go build ./...
GOOS=windows GOARCH=amd64 go build ./...
```

## 5. 依赖升级建议

- 先在网络可访问环境中执行:`go get -u ./... && go mod tidy`
- 对核心依赖逐项验证行为兼容性(尤其是日志、网络与加解密链路)
- 升级后执行全量测试与多平台构建再发布
2 changes: 1 addition & 1 deletion example/tcp/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"

"github.com/ooclab/es"
"github.com/ooclab/es/link"
Expand Down
2 changes: 1 addition & 1 deletion example/tcp/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/ooclab/es"
"github.com/ooclab/es/link"
"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion example/udp/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
"time"

logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/proto/udp"
"github.com/sirupsen/logrus"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion example/udp/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net"
"os"

logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/proto/udp"
"github.com/sirupsen/logrus"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion link/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package link
import (
"encoding/json"

logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/session"
"github.com/ooclab/es/tunnel"
"github.com/sirupsen/logrus"
)

type requestHandler struct {
Expand Down
2 changes: 1 addition & 1 deletion link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"time"

"github.com/ooclab/es"
logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/session"
"github.com/ooclab/es/tunnel"
"github.com/sirupsen/logrus"
)

// Define error
Expand Down
2 changes: 1 addition & 1 deletion link/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"errors"

logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/session"
"github.com/ooclab/es/tunnel"
"github.com/sirupsen/logrus"
)

func defaultOpenTunnel(sessionManager *session.Manager, tunnelManager *tunnel.Manager) OpenTunnelFunc {
Expand Down
115 changes: 115 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package logger

import (
"fmt"
"log"
"os"
"sort"
"strings"
)

// Fields is a set of key/value pairs attached to a log message.
type Fields map[string]interface{}

// Entry is a logger with bound fields.
type Entry struct {
fields Fields
}

var std = log.New(os.Stderr, "", log.LstdFlags)

// Level keeps compatibility with existing SetLevel call sites.
type Level uint32

const (
DebugLevel Level = iota
)

func SetLevel(_ Level) {}

func Debug(args ...interface{}) { std.Print(args...) }
func Debugf(format string, args ...interface{}) { std.Printf(format, args...) }
func Infof(format string, args ...interface{}) { std.Printf(format, args...) }
func Warn(args ...interface{}) { std.Print(args...) }
func Warnf(format string, args ...interface{}) { std.Printf(format, args...) }
func Error(args ...interface{}) { std.Print(args...) }
func Errorf(format string, args ...interface{}) { std.Printf(format, args...) }
func Fatalln(args ...interface{}) { std.Fatalln(args...) }

func WithField(key string, value interface{}) *Entry {
return &Entry{fields: Fields{key: value}}
}

func WithFields(fields Fields) *Entry {
cp := make(Fields, len(fields))
for k, v := range fields {
cp[k] = v
}
return &Entry{fields: cp}
}

func (e *Entry) WithField(key string, value interface{}) *Entry {
fields := e.copyFields()
fields[key] = value
return &Entry{fields: fields}
}

func (e *Entry) WithFields(extra Fields) *Entry {
fields := e.copyFields()
for k, v := range extra {
fields[k] = v
}
return &Entry{fields: fields}
}

func (e *Entry) Debug(args ...interface{}) {
std.Print(e.prefix() + fmt.Sprint(args...))
}

func (e *Entry) Debugf(format string, args ...interface{}) {
std.Print(e.prefix() + fmt.Sprintf(format, args...))
}

func (e *Entry) Warn(args ...interface{}) {
std.Print(e.prefix() + fmt.Sprint(args...))
}

func (e *Entry) Error(args ...interface{}) {
std.Print(e.prefix() + fmt.Sprint(args...))
}

func (e *Entry) Errorf(format string, args ...interface{}) {
std.Print(e.prefix() + fmt.Sprintf(format, args...))
}

func (e *Entry) Warnf(format string, args ...interface{}) {
std.Print(e.prefix() + fmt.Sprintf(format, args...))
}

func (e *Entry) Infof(format string, args ...interface{}) {
std.Print(e.prefix() + fmt.Sprintf(format, args...))
}

func (e *Entry) copyFields() Fields {
cp := make(Fields, len(e.fields))
for k, v := range e.fields {
cp[k] = v
}
return cp
}

func (e *Entry) prefix() string {
if len(e.fields) == 0 {
return ""
}
keys := make([]string, 0, len(e.fields))
for k := range e.fields {
keys = append(keys, k)
}
sort.Strings(keys)
parts := make([]string, 0, len(keys))
for _, k := range keys {
parts = append(parts, fmt.Sprintf("%s=%v", k, e.fields[k]))
}
return "[" + strings.Join(parts, " ") + "] "
}
2 changes: 1 addition & 1 deletion proto/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"time"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion proto/udp/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

func init() {
Expand Down
18 changes: 18 additions & 0 deletions scripts/build_multi_platform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail

TARGETS=(
"linux amd64"
"linux arm64"
"darwin amd64"
"darwin arm64"
"windows amd64"
)

for target in "${TARGETS[@]}"; do
IFS=' ' read -r GOOS GOARCH <<<"$target"
echo "==> building packages for ${GOOS}/${GOARCH}"
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" go build ./...
done

echo "all targets built successfully"
2 changes: 1 addition & 1 deletion session/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"

"github.com/ooclab/es"
"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

type Manager struct {
Expand Down
2 changes: 1 addition & 1 deletion test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/ooclab/es"
"github.com/ooclab/es/link"
"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

// For test
Expand Down
2 changes: 1 addition & 1 deletion test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/rand"
"testing"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"

"github.com/ooclab/es/session"
)
Expand Down
2 changes: 1 addition & 1 deletion test/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import (
"testing"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion tunnel/channel/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sync/atomic"

"github.com/ooclab/es"
logrus "github.com/ooclab/es/logger"
"github.com/ooclab/es/util"
"github.com/sirupsen/logrus"

tcommon "github.com/ooclab/es/tunnel/common"
)
Expand Down
2 changes: 1 addition & 1 deletion tunnel/channel/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/ooclab/es"
"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"

tcommon "github.com/ooclab/es/tunnel/common"
)
Expand Down
2 changes: 1 addition & 1 deletion tunnel/channel/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package channel
import (
"net"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

func closeConn(conn net.Conn) {
Expand Down
2 changes: 1 addition & 1 deletion tunnel/listen_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net"
"sync"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"
)

type listenTarget struct {
Expand Down
2 changes: 1 addition & 1 deletion tunnel/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tunnel
import (
"errors"

"github.com/sirupsen/logrus"
logrus "github.com/ooclab/es/logger"

"github.com/ooclab/es/session"
tcommon "github.com/ooclab/es/tunnel/common"
Expand Down
Loading
Loading