Major rewrite of the Go backend to support:
- Three API format imports: openai, anthropic, compatible
- Three protocol conversions: Chat Completions, Responses, Messages
- Hub-and-spoke architecture with Chat as intermediate format
Deleted:
- opencat.go (old entry)
- store/, team/, pkg/team/, pkg/store/ (old data layer)
- internal/model/, internal/consts/ (old types)
- internal/service/team/, internal/controller/team/ (old handlers)
- llm/ (removed LLM client library, pure proxy mode)
- dist/, assets/ (old build artifacts)
Added:
- internal/store/ — 9 GORM models + multi-DB support
- internal/pkg/ — crypto (AES-GCM), apikey, jwt, ratelimit, resp, tokenizer
- internal/channel/ — channel selection, weighted LB, health checks
- internal/proxy/convert/ — 6 protocol conversion functions + SSE streaming
- internal/proxy/ — gateway with request dispatch and upstream selection
- internal/usage/ — async usage recorder with batch writes
- internal/api/ — management API (auth, users, keys, channels, models)
- Makefile for build/test/deploy
Fixed API to match frontend expectations:
- Login response wraps token in { data: { token } }
- GET /api/profile route added
- Profile response wraps user in { code, data }
- Role returned as number (10=admin, 1=user)
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"opencatd-open/internal/dao"
|
|
"opencatd-open/internal/store"
|
|
"opencatd-open/pkg/config"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type UserServiceImpl struct {
|
|
cfg *config.Config
|
|
db *gorm.DB
|
|
userRepo *dao.UserDAO
|
|
}
|
|
|
|
func NewUserService(cfg *config.Config, db *gorm.DB, userRepo *dao.UserDAO) *UserServiceImpl {
|
|
return &UserServiceImpl{
|
|
cfg: cfg,
|
|
db: db,
|
|
userRepo: userRepo,
|
|
}
|
|
}
|
|
|
|
func (s *UserServiceImpl) GetByID(ctx context.Context, id uint64) (*store.User, error) {
|
|
return s.userRepo.GetByID(id)
|
|
}
|
|
|
|
func (s *UserServiceImpl) GetByUsername(ctx context.Context, username string) (*store.User, error) {
|
|
return s.userRepo.GetByUsername(username)
|
|
}
|
|
|
|
func (s *UserServiceImpl) List(ctx context.Context, limit, offset int) ([]*store.User, int64, error) {
|
|
return s.userRepo.List(limit, offset)
|
|
}
|
|
|
|
func (s *UserServiceImpl) Create(ctx context.Context, user *store.User) error {
|
|
return s.userRepo.Create(user)
|
|
}
|
|
|
|
func (s *UserServiceImpl) Update(ctx context.Context, user *store.User) error {
|
|
return s.userRepo.Update(user)
|
|
}
|
|
|
|
func (s *UserServiceImpl) Delete(ctx context.Context, id uint64) error {
|
|
return s.userRepo.Delete(id)
|
|
}
|