Skip to content

Commit 8e484c3

Browse files
committed
feat: Support SQLite without CGO
1 parent f123788 commit 8e484c3

8 files changed

Lines changed: 112 additions & 49 deletions

File tree

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ WORKDIR /build
44

55
COPY go.mod go.sum ./
66

7-
RUN apk add --no-cache gcc musl-dev
8-
97
RUN go mod download
108

119
COPY . .
1210

13-
RUN CGO_ENABLED=1 GOOS=linux go build -o main .
11+
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
1412

1513
FROM alpine:latest
1614

README-zh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Channel Monitor 是一个用于监控OneAPI/NewAPI渠道的工具,它直接读
2727
### 二进制
2828

2929
[Releases](https://github.com/DullJZ/ChannelMonitor/releases)页面下载最新版本的二进制文件,在同一目录下配置`config.json``config.yaml`后运行即可。建议使用`screen``nohup`等工具后台运行。
30-
注意⚠️:如果你需要使用SQLite数据库,请使用docker方案或自行启用CGO编译。
3130

3231
```bash
3332
mkdir ChannelMonitor && cd ChannelMonitor

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Channel Monitor is a tool designed for monitoring OneAPI/NewAPI channels. It dir
2626
### Binary
2727

2828
Download the latest version of the binary file from the [Releases](https://github.com/DullJZ/ChannelMonitor/releases) page. After configuring `config.json` or `config.yaml` in the same directory, you can run it. It is recommended to use tools like `screen` or `nohup` to run it in the background.
29-
Note ⚠️: If you need to use an SQLite database, please use the Docker solution or compile yourself after enabling CGO.
3029

3130
```bash
3231
mkdir ChannelMonitor && cd ChannelMonitor

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.5.1
1+
v0.5.2

build.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ build() {
3333
fi
3434

3535
echo "Building for ${GOOS}/${GOARCH}..."
36-
if [ "$GOARCH" = "amd64" ] && [ "$GOOS" = "linux" ]; then
37-
CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags "${LDFLAGS}" -o "${OUTPUT}" .
38-
else
39-
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags "${LDFLAGS}" -o "${OUTPUT}" .
40-
fi
36+
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags "${LDFLAGS}" -o "${OUTPUT}" .
4137

4238
if [ $? -eq 0 ]; then
4339
echo "✅ Finished building for ${GOOS}/${GOARCH}"

db.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package main
22

33
import (
44
"fmt"
5+
56
"gorm.io/driver/mysql"
67
"gorm.io/driver/postgres"
78
"gorm.io/driver/sqlite"
89
"gorm.io/driver/sqlserver"
910
"gorm.io/gorm"
11+
_ "modernc.org/sqlite" // Pure Go SQLite driver
1012
)
1113

1214
func NewDB(config Config) (*gorm.DB, error) {

go.mod

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
11
module github.com/DullJZ/ChannelMonitor
22

3-
go 1.23
3+
go 1.23.0
44

55
toolchain go1.23.6
66

7-
require github.com/go-sql-driver/mysql v1.8.1 // indirect
7+
require (
8+
github.com/dustin/go-humanize v1.0.1 // indirect
9+
github.com/go-sql-driver/mysql v1.9.0 // indirect
10+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
11+
github.com/mattn/go-isatty v0.0.20 // indirect
12+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
13+
github.com/ncruces/go-strftime v0.1.9 // indirect
14+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
15+
golang.org/x/tools v0.26.0 // indirect
16+
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
17+
modernc.org/libc v1.55.3 // indirect
18+
modernc.org/mathutil v1.6.0 // indirect
19+
modernc.org/memory v1.8.0 // indirect
20+
modernc.org/strutil v1.2.0 // indirect
21+
modernc.org/token v1.1.0 // indirect
22+
)
823

924
require golang.org/x/time v0.10.0
1025

1126
require (
1227
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
1328
github.com/golang-sql/sqlexp v0.1.0 // indirect
29+
github.com/google/uuid v1.6.0 // indirect
1430
github.com/jackc/pgpassfile v1.0.0 // indirect
15-
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
16-
github.com/jackc/pgx/v5 v5.5.5 // indirect
17-
github.com/jackc/puddle/v2 v2.2.1 // indirect
31+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
32+
github.com/jackc/pgx/v5 v5.7.2 // indirect
33+
github.com/jackc/puddle/v2 v2.2.2 // indirect
1834
github.com/jinzhu/inflection v1.0.0 // indirect
1935
github.com/jinzhu/now v1.1.5 // indirect
2036
github.com/kr/text v0.2.0 // indirect
21-
github.com/mattn/go-sqlite3 v1.14.22 // indirect
22-
github.com/microsoft/go-mssqldb v1.7.2 // indirect
37+
github.com/microsoft/go-mssqldb v1.8.0 // indirect
2338
github.com/rogpeppe/go-internal v1.14.1 // indirect
24-
golang.org/x/crypto v0.18.0 // indirect
25-
golang.org/x/sync v0.1.0 // indirect
26-
golang.org/x/sys v0.26.0 // indirect
27-
golang.org/x/text v0.14.0 // indirect
39+
golang.org/x/crypto v0.35.0 // indirect
40+
golang.org/x/sync v0.11.0 // indirect
41+
golang.org/x/sys v0.30.0 // indirect
42+
golang.org/x/text v0.22.0 // indirect
2843
)
2944

3045
require (
3146
filippo.io/edwards25519 v1.1.0 // indirect
3247
gopkg.in/yaml.v3 v3.0.1
3348
gorm.io/driver/mysql v1.5.7
34-
gorm.io/driver/postgres v1.5.9
35-
gorm.io/driver/sqlite v1.5.6
49+
gorm.io/driver/postgres v1.5.11
50+
gorm.io/driver/sqlite v1.5.7
3651
gorm.io/driver/sqlserver v1.5.4
3752
gorm.io/gorm v1.25.12
53+
modernc.org/sqlite v1.34.4
3854
)

0 commit comments

Comments
 (0)