初始化项目
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -20,7 +20,7 @@ bin-release/
|
||||
/.idea/vcs.xml
|
||||
/.idea/UniappTool.xml
|
||||
/.idea/modules.xml
|
||||
/.idea/cidservice.iml
|
||||
/.idea/cid.iml
|
||||
/.idea/.gitignore
|
||||
/.idea/go.imports.xml/
|
||||
/model/dto/dto规范.md
|
||||
@@ -28,4 +28,5 @@ bin-release/
|
||||
/controller/controller规范.md
|
||||
/service/service规范.md
|
||||
dao/dao规范.md
|
||||
api接口文档.md
|
||||
api接口文档.md
|
||||
/.idea/cidservice.iml
|
||||
|
||||
@@ -39,7 +39,7 @@ RUN ln -sf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime \
|
||||
COPY go.mod go.sum ./
|
||||
# RUN chown -R golang:golang $WORKDIR
|
||||
RUN go mod download && go mod verify
|
||||
COPY ../../cidService $WORKDIR
|
||||
COPY ../../cid $WORKDIR
|
||||
RUN chown -R golang:golang $WORKDIR
|
||||
# Remove SetUID, SetGID
|
||||
RUN chmod 0755 /usr/local/bin/app/api \
|
||||
@@ -54,4 +54,4 @@ RUN chmod 0755 /usr/local/bin/app/api \
|
||||
USER golang
|
||||
RUN go build -v -o /usr/local/bin/app ./...
|
||||
EXPOSE 3002
|
||||
CMD ./cidService
|
||||
CMD ./cid
|
||||
@@ -75,7 +75,7 @@ CID服务商项目是一个为企业提供CID(Click ID)服务的完整解决
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
cidservice/
|
||||
cid/
|
||||
├── controller/ # 控制器层
|
||||
│ ├── cid_controller.go
|
||||
│ ├── ad_source_controller.go
|
||||
|
||||
16
config.yml
16
config.yml
@@ -1,18 +1,9 @@
|
||||
server:
|
||||
address : ":3001"
|
||||
name: "cidService"
|
||||
jwt:
|
||||
secret: "abcdefghijklmnopqrstuvwxyz"
|
||||
name: "cid"
|
||||
rate:
|
||||
limit: 200
|
||||
burst: 300
|
||||
|
||||
# 租户限流配置
|
||||
tenantRateLimit:
|
||||
enabled: true # 是否启用租户限流
|
||||
requestsPerHour: 3600 # 每小时最大请求数
|
||||
window: 3600 # 时间窗口(秒)
|
||||
burst: 100 # 突发请求数
|
||||
mongo:
|
||||
logger:
|
||||
level: "all"
|
||||
@@ -33,10 +24,5 @@ redis:
|
||||
consul:
|
||||
address: 192.168.3.200:8500
|
||||
# pass: jiahui8888
|
||||
rabbitMQ:
|
||||
host: 192.168.3.200
|
||||
port: 5672
|
||||
username: guest # 默认用户名
|
||||
password: guest # 默认密码
|
||||
jaeger: #链路追踪
|
||||
addr: 192.168.3.200:4318
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
type adStatistics struct{}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
var Application = new(application)
|
||||
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
var RateLimit = new(rateLimit)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
var StatReport = new(statReport)
|
||||
|
||||
@@ -3,8 +3,8 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
|
||||
@@ -3,7 +3,7 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -3,7 +3,7 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -3,7 +3,7 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
4
main.go
4
main.go
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cidservice/controller"
|
||||
"cidservice/service"
|
||||
"cid/controller"
|
||||
"cid/service"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"cidservice/model/entity"
|
||||
"cid/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
)
|
||||
|
||||
var AdStatistics = new(adStatistics)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
)
|
||||
|
||||
var Advertiser = new(advertiser)
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cidservice/model/types"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"cid/model/types"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
CID = cidService{}
|
||||
CID = cid{}
|
||||
)
|
||||
|
||||
type cidService struct{}
|
||||
type cid struct{}
|
||||
|
||||
// AdMatchingStrategy 广告匹配策略
|
||||
type AdMatchingStrategy struct {
|
||||
@@ -34,7 +34,7 @@ type AdMatchingStrategy struct {
|
||||
}
|
||||
|
||||
// getMatchingStrategy 获取匹配策略
|
||||
func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
|
||||
func (s *cid) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
|
||||
// 从数据库获取策略
|
||||
strategyEntity, err := Strategy.GetStrategyByTenantLevel(ctx, tenantLevel)
|
||||
if err != nil {
|
||||
@@ -72,7 +72,7 @@ func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string
|
||||
}
|
||||
|
||||
// GenerateCID 生成CID广告
|
||||
func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||
func (s *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||
// 获取当前用户信息
|
||||
userInfo, err := utils.GetUserInfo(ctx)
|
||||
if err != nil {
|
||||
@@ -123,7 +123,7 @@ func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (
|
||||
}
|
||||
|
||||
// getTenantByUser 根据用户获取租户信息
|
||||
func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
|
||||
func (s *cid) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
|
||||
// 通过common模块获取用户信息,包含租户ID
|
||||
userInfo, err := utils.GetUserInfo(ctx)
|
||||
if err != nil {
|
||||
@@ -164,7 +164,7 @@ func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.
|
||||
}
|
||||
|
||||
// matchAds 根据策略匹配广告
|
||||
func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
|
||||
func (s *cid) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
|
||||
var matchedAds []*dto.AdInfo
|
||||
|
||||
// 根据策略权重从不同源获取广告
|
||||
@@ -202,7 +202,7 @@ func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, stra
|
||||
}
|
||||
|
||||
// getAdsFromSource 从指定广告源获取广告
|
||||
func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
|
||||
func (s *cid) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
|
||||
switch source {
|
||||
case "self":
|
||||
return s.getSelfServiceAds(ctx, req, weight)
|
||||
@@ -216,7 +216,7 @@ func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *d
|
||||
}
|
||||
|
||||
// getSelfServiceAds 获取自营广告
|
||||
func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
func (s *cid) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
// 这里应该从数据库查询自营广告
|
||||
// 暂时返回模拟数据
|
||||
ads := make([]*dto.AdInfo, 0)
|
||||
@@ -236,7 +236,7 @@ func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCID
|
||||
}
|
||||
|
||||
// getGoogleAds 获取Google广告
|
||||
func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
func (s *cid) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
// 这里应该调用Google Ads API
|
||||
// 暂时返回模拟数据
|
||||
ads := make([]*dto.AdInfo, 0)
|
||||
@@ -256,7 +256,7 @@ func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq,
|
||||
}
|
||||
|
||||
// getFacebookAds 获取Facebook广告
|
||||
func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
func (s *cid) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||
// 这里应该调用Facebook Ads API
|
||||
// 暂时返回模拟数据
|
||||
ads := make([]*dto.AdInfo, 0)
|
||||
@@ -276,14 +276,14 @@ func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq
|
||||
}
|
||||
|
||||
// generateUniqueCID 生成唯一CID
|
||||
func (s *cidService) generateUniqueCID() string {
|
||||
func (s *cid) generateUniqueCID() string {
|
||||
timestamp := time.Now().Unix()
|
||||
random := rand.Intn(8999) + 1000
|
||||
return fmt.Sprintf("CID_%d_%d", timestamp, random)
|
||||
}
|
||||
|
||||
// recordCIDRequest 记录CID请求
|
||||
func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
|
||||
func (s *cid) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
|
||||
// 转换dto.AdInfo到entity.Ad
|
||||
var entityAds []entity.Ad
|
||||
for _, ad := range ads {
|
||||
@@ -312,7 +312,7 @@ func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDR
|
||||
}
|
||||
|
||||
// GetCIDHistory 获取CID请求历史
|
||||
func (s *cidService) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
|
||||
func (s *cid) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
|
||||
history, total, err := dao.CIDRequest.GetHistory(ctx, userId, page, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"cidservice/consts"
|
||||
"cid/consts"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"cidservice/dao"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"cidservice/dao"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"cid/dao"
|
||||
"cid/model/dto"
|
||||
"cid/model/entity"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
Reference in New Issue
Block a user