Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 15 additions & 2 deletions .github/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "2"

run:
timeout: 5m
timeout: 10m
skip-dirs:
- kitex_gen
- loop_gen
Expand All @@ -15,6 +15,11 @@ linters: # https://golangci-lint.run/usage/linters/
- staticcheck
- unused
- unconvert
exclusions:
rules:
- path: "coze/loop/apis/middleware.go"
linters:
- unused

formatters:
enable:
Expand All @@ -27,4 +32,12 @@ linters-settings:
gofumpt:
# Choose whether to use the extra rules.
extra-rules: true
goimports:
goimports:

severity:
default: error
rules:
- linters:
- unconvert
- unused
severity: warning
5 changes: 2 additions & 3 deletions backend/api/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/api/handler/coze/loop/apis/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func NewPromptHandler(
manageApp manage.PromptManageService,
debugApp debug.PromptDebugService,
executeApp execute.PromptExecuteService,
openAPIApp openapi.PromptOpenAPIService) *PromptHandler {
openAPIApp openapi.PromptOpenAPIService,
) *PromptHandler {
h := &PromptHandler{
PromptManageService: manageApp,
PromptDebugService: debugApp,
Expand Down Expand Up @@ -216,7 +217,6 @@ func invokeAndRender[T, K any](
ctx context.Context, c *app.RequestContext,
callable func(ctx context.Context, req T, callOptions ...callopt.Option) (K, error),
) {

render := func(c *app.RequestContext, fn func() (any, error)) {
resp, err := fn()
if err == nil {
Expand Down
3 changes: 2 additions & 1 deletion backend/api/router/coze/loop/apis/middleware/pat_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"context"
"strings"

"github.com/cloudwego/hertz/pkg/app"

"github.com/coze-dev/cozeloop/backend/api/handler/coze/loop/apis"
"github.com/coze-dev/cozeloop/backend/kitex_gen/coze/loop/foundation/authn"
"github.com/coze-dev/cozeloop/backend/pkg/errorx"
"github.com/cloudwego/hertz/pkg/app"
)

func PatTokenVerifyMW(handler *apis.APIHandler) app.HandlerFunc {
Expand Down
1 change: 0 additions & 1 deletion backend/api/router_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

// register registers all routers.
func register(r *server.Hertz, handler *apis.APIHandler) {

router.GeneratedRegister(r, handler)

customizedRegister(r)
Expand Down
6 changes: 2 additions & 4 deletions backend/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: Apache-2.0

// Code generated by hertz generator.

package main

import (
Expand Down Expand Up @@ -129,8 +127,8 @@ type component struct {

func initTracer(handler *apis.APIHandler) error {
rpc.SetLoopTracerHandler(
lofile.NewLocalFileService(handler.FoundationHandler.FileService),
lotrace.NewLocalTraceService(handler.ObservabilityHandler.ITraceApplication),
lofile.NewLocalFileService(handler.FileService),
lotrace.NewLocalTraceService(handler.ITraceApplication),
)

client, err := cozeloop.NewClient(
Expand Down
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/ClickHouse/clickhouse-go/v2 v2.34.0
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/RealAlexandreAI/json-repair v0.0.14
github.com/alicebob/miniredis/v2 v2.34.0
github.com/alitto/pond/v2 v2.3.4
github.com/apache/rocketmq-client-go/v2 v2.1.2
Expand Down Expand Up @@ -55,6 +54,7 @@ require (
github.com/jarcoal/httpmock v1.4.0
github.com/jinzhu/copier v0.4.0
github.com/json-iterator/go v1.1.12
github.com/kaptinlin/jsonrepair v0.1.1
github.com/mitchellh/mapstructure v1.5.0
github.com/modern-go/reflect2 v1.0.2
github.com/ollama/ollama v0.5.12
Expand Down
4 changes: 2 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/RealAlexandreAI/json-repair v0.0.14 h1:4kTqotVonDVTio5n2yweRUELVcNe2x518wl0bCsw0t0=
github.com/RealAlexandreAI/json-repair v0.0.14/go.mod h1:GKJi5borR78O8c7HCVbgqjhoiVibZ6hJldxbc6dGrAI=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/sarama v1.30.1/go.mod h1:hGgx05L/DiW8XYBXeJdKIN6V2QUy2H6JqME5VT1NLRw=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
Expand Down Expand Up @@ -588,6 +586,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kaptinlin/jsonrepair v0.1.1 h1:Ddn1sN1cZXuXeKA9vpaHAtBETnGSFBZFaaYfoN2Uo8c=
github.com/kaptinlin/jsonrepair v0.1.1/go.mod h1:SivjE7np/GsSrk7UX/9mibH6VF8cVpD2aUmg7vceg2k=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
2 changes: 1 addition & 1 deletion backend/infra/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Test_backoff(t *testing.T) {
start := time.Now()
assert.NotNil(t, RetryWithElapsedTime(cc, time.Second, fn))
assert.Equal(t, 1, cnt)
assert.True(t, time.Now().Sub(start) < time.Second)
assert.True(t, time.Since(start) < time.Second)
})
}

Expand Down
4 changes: 0 additions & 4 deletions backend/infra/ck/ck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type Provider interface {
NewSession(ctx context.Context) *gorm.DB
}

type option struct {
tx *gorm.DB
}

type provider struct {
db *gorm.DB
}
Expand Down
6 changes: 4 additions & 2 deletions backend/infra/ck/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package ck

import "time"

type CompressionMethod string
type Protocol string
type (
CompressionMethod string
Protocol string
)

const (
CompressionMethodLZ4 CompressionMethod = "lz4"
Expand Down
2 changes: 1 addition & 1 deletion backend/infra/db/in_mem_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newInMemServer(cfg *Config) (*server.Server, error) {

// Build engine.
db := memory.NewDatabase(cfg.DBName)
db.BaseDatabase.EnablePrimaryKeyIndexes()
db.EnablePrimaryKeyIndexes()
provider := memory.NewDBProvider(db)
engine := sqle.NewDefault(provider)

Expand Down
6 changes: 4 additions & 2 deletions backend/infra/fileserver/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ type S3Client struct {
cfg *S3Config
}

var _ ObjectStorage = (*S3Client)(nil)
var _ BatchObjectStorage = (*S3Client)(nil)
var (
_ ObjectStorage = (*S3Client)(nil)
_ BatchObjectStorage = (*S3Client)(nil)
)

func NewS3Client(cfg *S3Config) (*S3Client, error) {
if err := cfg.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion backend/infra/fileserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (o *ObjectInfo) Size() int64 {
}

func (o *ObjectInfo) Mode() fs.FileMode {
return 0644
return 0o644
}

func (o *ObjectInfo) ModTime() time.Time {
Expand Down
5 changes: 2 additions & 3 deletions backend/infra/looptracer/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const (
XttEnv = "x_tt_env"
)

type MultiSpaceSpanExporter struct {
}
type MultiSpaceSpanExporter struct{}

func (e *MultiSpaceSpanExporter) ExportSpans(ctx context.Context, spans []*entity.UploadSpan) error {
finalSpans := make([]*span.InputSpan, 0, len(spans))
Expand Down Expand Up @@ -70,7 +69,7 @@ func (e *MultiSpaceSpanExporter) ExportSpans(ctx context.Context, spans []*entit
}

if env := os.Getenv(XttEnv); env != "" {
ctx = context.WithValue(ctx, CtxKeyEnv, env)
ctx = context.WithValue(ctx, CtxKeyEnv, env) //nolint:staticcheck,SA1029
}
resp, err := rpc.GetLoopTracerHandler().LocalTraceService.IngestTracesInner(ctx, req)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions backend/infra/looptracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ func (s SpanImpl) SetCallType(callType string) {

var _ Span = (*noopSpan)(nil)

type noopSpan struct {
}
type noopSpan struct{}

func (n noopSpan) GetSpanID() string {
return ""
Expand Down
5 changes: 1 addition & 4 deletions backend/infra/looptracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ func (d *noopTracer) GetSpanFromContext(ctx context.Context) Span {
return &noopSpan{}
}

func (d *noopTracer) Flush(ctx context.Context) {
return
}
func (d *noopTracer) Flush(ctx context.Context) {}

func (d *noopTracer) Inject(ctx context.Context) context.Context {
return ctx
}

func (d *noopTracer) SetCallType(callType string) {

}
6 changes: 3 additions & 3 deletions backend/infra/middleware/localrpc/localrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/cloudwego/kitex/pkg/endpoint"
)

const (
localCallFlagCtxKey = "cozeloop_local_call"
)
type localCallFlagCtxKeyType struct{}

var localCallFlagCtxKey = localCallFlagCtxKeyType{}

func LocalCallFlagMiddleware(next endpoint.Endpoint) endpoint.Endpoint {
return func(ctx context.Context, req, resp any) (err error) {
Expand Down
9 changes: 5 additions & 4 deletions backend/infra/middleware/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/coze-dev/cozeloop/backend/pkg/logs"
)

const SessionKey = "session_key"
const SessionExpires = 7 * 24 * time.Hour
const (
SessionKey = "session_key"
SessionExpires = 7 * 24 * time.Hour
)

// 用于签名的密钥(在实际应用中应从配置中读取或使用环境变量)
var hmacSecret = []byte("openloop-session-hmac-key")
Expand All @@ -35,8 +37,7 @@ type ISessionService interface {
GenerateSessionKey(ctx context.Context, session *Session) (string, error)
}

type sessionServiceImpl struct {
}
type sessionServiceImpl struct{}

func NewSessionService() ISessionService {
return &sessionServiceImpl{}
Expand Down
5 changes: 4 additions & 1 deletion backend/infra/middleware/session/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ type User struct {
Email string `json:"email,omitempty"`
}

var userKey struct{}
// userKeyType 定义自定义类型作为context键,避免键冲突
type userKeyType struct{}

var userKey = userKeyType{}

// UserIDInCtx returns the user ID from the context.
// Notice: NewSessionMD must be used in your service, or else this function always returns false.
Expand Down
4 changes: 2 additions & 2 deletions backend/infra/mq/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type ConsumerConfig struct {
type CompressionCodec int

const (
//CompressionNone no compression
// CompressionNone no compression
CompressionNone CompressionCodec = iota
//CompressionZSTD compression using ZSTD
// CompressionZSTD compression using ZSTD
CompressionZSTD
)
3 changes: 2 additions & 1 deletion backend/infra/mq/rocketmq/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"fmt"
"net"

"github.com/coze-dev/cozeloop/backend/infra/mq"
"github.com/apache/rocketmq-client-go/v2"
"github.com/apache/rocketmq-client-go/v2/consumer"
"github.com/apache/rocketmq-client-go/v2/primitive"
"github.com/apache/rocketmq-client-go/v2/producer"

"github.com/coze-dev/cozeloop/backend/infra/mq"
)

type Factory struct{}
Expand Down
3 changes: 2 additions & 1 deletion backend/infra/mq/rocketmq/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"context"
"time"

"github.com/coze-dev/cozeloop/backend/infra/mq"
"github.com/apache/rocketmq-client-go/v2"
"github.com/apache/rocketmq-client-go/v2/primitive"

"github.com/coze-dev/cozeloop/backend/infra/mq"
)

type Producer struct {
Expand Down
1 change: 0 additions & 1 deletion backend/infra/platestwrite/latest_write_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func (t *LatestWriteTracker) setWriteFlag(ctx context.Context, resource *resourc
// 写入失败不影响主流程
logs.CtxWarn(ctx, "set latest write flag failed, key=%s", key)
}
return
}

// CheckWriteFlagByID 如果 writeFlag 存在,则说明当前资源最近有写入记录,需要读主
Expand Down
1 change: 0 additions & 1 deletion backend/modules/data/application/convertor/dataset/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package dataset

import (
"github.com/bytedance/gg/gptr"

"github.com/bytedance/gg/gslice"

"github.com/coze-dev/cozeloop/backend/kitex_gen/coze/loop/data/domain/dataset"
Expand Down
2 changes: 1 addition & 1 deletion backend/modules/data/application/convertor/dataset/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package dataset

import (
"github.com/bytedance/gg/gptr"

"github.com/bytedance/gg/gslice"

"github.com/coze-dev/cozeloop/backend/kitex_gen/coze/loop/data/domain/dataset"
Expand Down Expand Up @@ -95,6 +94,7 @@ func DatasetIOFileDO2DTO(dto *entity.DatasetIOFile) *dataset_job.DatasetIOFile {
Files: dto.Files,
}
}

func DatasetIODatasetDO2DTO(dto *entity.DatasetIODataset) *dataset_job.DatasetIODataset {
if dto == nil {
return nil
Expand Down
Loading
Loading