Merge branch 'develop' into feature/mhw-v1.01
This commit is contained in:
commit
30fd11bb37
|
@ -17,9 +17,8 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
c.Timeout = int64(time.Second * 15)
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
|
@ -18,9 +18,8 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
c.Timeout = int64(time.Second * 15)
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import {{.authImport}}
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
rest.RestConf
|
|
||||||
SourceMysql string
|
|
||||||
Auth types.Auth
|
|
||||||
{{.auth}}
|
|
||||||
{{.jwtTrans}}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
{{.configImport}}
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fusenapi/initalize"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"github.com/golang-jwt/jwt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ServiceContext struct {
|
|
||||||
Config {{.config}}
|
|
||||||
{{.middleware}}
|
|
||||||
MysqlConn *gorm.DB
|
|
||||||
AllModels *gmodel.AllModelsGen
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServiceContext(c {{.config}}) *ServiceContext {
|
|
||||||
|
|
||||||
return &ServiceContext{
|
|
||||||
Config: c,
|
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
|
||||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
|
||||||
{{.middlewareAssignment}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
|
||||||
AuthKey := r.Header.Get("Authorization")
|
|
||||||
|
|
||||||
if len(AuthKey) <= 50 {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
|
||||||
}
|
|
||||||
|
|
||||||
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
|
||||||
// 检查签名方法是否为 HS256
|
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
|
||||||
}
|
|
||||||
// 返回用于验证签名的密钥
|
|
||||||
return []byte(svcCtx.Config.Auth.AccessSecret), nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证成功返回
|
|
||||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
|
||||||
return claims, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
Name: {{.serviceName}}
|
|
||||||
Host: {{.host}}
|
|
||||||
Port: {{.port}}
|
|
||||||
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
|
|
||||||
Auth:
|
|
||||||
AccessSecret: fusen2023
|
|
||||||
AccessExpire: 2592000
|
|
||||||
RefreshAfter: 1592000
|
|
|
@ -1,32 +0,0 @@
|
||||||
package {{.PkgName}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
{{.ImportPackages}}
|
|
||||||
)
|
|
||||||
|
|
||||||
func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
{{if .HasRequest}}var req types.{{.RequestType}}
|
|
||||||
userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
{{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package {{.pkgName}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
{{.imports}}
|
|
||||||
)
|
|
||||||
|
|
||||||
type {{.logic}} struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} {
|
|
||||||
return &{{.logic}}{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *{{.logic}}) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
{{.returnString}} resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/fsconfig"
|
|
||||||
|
|
||||||
{{.importPackages}}
|
|
||||||
)
|
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
|
|
||||||
var c config.Config
|
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
|
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
|
||||||
}))
|
|
||||||
|
|
||||||
defer server.Stop()
|
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
|
||||||
handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
||||||
server.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var testConfigFile = flag.String("f", "../etc/{{.serviceName}}.yaml", "the config file")
|
|
||||||
// var cnf config.Config
|
|
||||||
|
|
||||||
// func GetTestServer() *rest.Server {
|
|
||||||
// flag.Parse()
|
|
||||||
|
|
||||||
// conf.MustLoad(*testConfigFile, &cnf)
|
|
||||||
|
|
||||||
// server := rest.MustNewServer(cnf.RestConf)
|
|
||||||
// defer server.Stop()
|
|
||||||
|
|
||||||
// ctx := svc.NewServiceContext(cnf)
|
|
||||||
// handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
// fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
|
||||||
// return server
|
|
||||||
// }
|
|
|
@ -1,19 +0,0 @@
|
||||||
package middleware
|
|
||||||
|
|
||||||
import "net/http"
|
|
||||||
|
|
||||||
type {{.name}} struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func New{{.name}}() *{{.name}} {
|
|
||||||
return &{{.name}}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *{{.name}})Handle(next http.HandlerFunc) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// TODO generate middleware implement function, delete after code implementation
|
|
||||||
|
|
||||||
// Passthrough to next handler if need
|
|
||||||
next(w, r)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
server.AddRoutes(
|
|
||||||
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}} {{.timeout}} {{.maxBytes}}
|
|
||||||
)
|
|
|
@ -1,13 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"{{if .hasTimeout}}
|
|
||||||
"time"{{end}}
|
|
||||||
|
|
||||||
{{.importPackages}}
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|
||||||
{{.routesAdditions}}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
syntax = "v1"
|
|
||||||
|
|
||||||
info (
|
|
||||||
title: // TODO: add title
|
|
||||||
desc: // TODO: add description
|
|
||||||
author: "{{.gitUser}}"
|
|
||||||
email: "{{.gitEmail}}"
|
|
||||||
)
|
|
||||||
|
|
||||||
type request {
|
|
||||||
// TODO: add members here and delete this comment
|
|
||||||
}
|
|
||||||
|
|
||||||
type response {
|
|
||||||
// TODO: add members here and delete this comment
|
|
||||||
}
|
|
||||||
|
|
||||||
service {{.serviceName}} {
|
|
||||||
@handler GetUser // TODO: set handler name and delete this comment
|
|
||||||
get /users/id/:userId(request) returns(response)
|
|
||||||
|
|
||||||
@handler CreateUser // TODO: set handler name and delete this comment
|
|
||||||
post /users/create(request)
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package types
|
|
||||||
import (
|
|
||||||
{{if .containsTime}}"time"{{end}}
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
)
|
|
||||||
{{.types}}
|
|
||||||
|
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
|
||||||
func (resp *Response) Set(Code int, Message string) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set 设置整个Response
|
|
||||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
Data: Data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
Message: msg,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
FROM golang:{{.Version}}alpine AS builder
|
|
||||||
|
|
||||||
LABEL stage=gobuilder
|
|
||||||
|
|
||||||
ENV CGO_ENABLED 0
|
|
||||||
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct
|
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|
||||||
{{end}}{{if .HasTimezone}}
|
|
||||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
|
||||||
{{end}}
|
|
||||||
WORKDIR /build
|
|
||||||
|
|
||||||
ADD go.mod .
|
|
||||||
ADD go.sum .
|
|
||||||
RUN go mod download
|
|
||||||
COPY . .
|
|
||||||
{{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc
|
|
||||||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoMainFrom}}
|
|
||||||
|
|
||||||
|
|
||||||
FROM {{.BaseImage}}
|
|
||||||
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
{{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}}
|
|
||||||
ENV TZ {{.Timezone}}
|
|
||||||
{{end}}
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}}
|
|
||||||
COPY --from=builder /app/etc /app/etc{{end}}
|
|
||||||
{{if .HasPort}}
|
|
||||||
EXPOSE {{.Port}}
|
|
||||||
{{end}}
|
|
||||||
CMD ["./{{.ExeFile}}"{{.Argument}}]
|
|
|
@ -1,18 +0,0 @@
|
||||||
Name: gateway-example # gateway name
|
|
||||||
Host: localhost # gateway host
|
|
||||||
Port: 8888 # gateway port
|
|
||||||
Upstreams: # upstreams
|
|
||||||
- Grpc: # grpc upstream
|
|
||||||
Target: 0.0.0.0:8080 # grpc target,the direct grpc server address,for only one node
|
|
||||||
# Endpoints: [0.0.0.0:8080,192.168.120.1:8080] # grpc endpoints, the grpc server address list, for multiple nodes
|
|
||||||
# Etcd: # etcd config, if you want to use etcd to discover the grpc server address
|
|
||||||
# Hosts: [127.0.0.1:2378,127.0.0.1:2379] # etcd hosts
|
|
||||||
# Key: greet.grpc # the discovery key
|
|
||||||
# protoset mode
|
|
||||||
ProtoSets:
|
|
||||||
- hello.pb
|
|
||||||
# Mappings can also be written in proto options
|
|
||||||
# Mappings: # routes mapping
|
|
||||||
# - Method: get
|
|
||||||
# Path: /ping
|
|
||||||
# RpcPath: hello.Hello/Ping
|
|
|
@ -1,21 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/gateway"
|
|
||||||
)
|
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/gateway.yaml", "config file")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
var c gateway.GatewayConf
|
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
|
||||||
gw := gateway.MustNewServer(c)
|
|
||||||
defer gw.Stop()
|
|
||||||
gw.Start()
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: {{.Name}}
|
|
||||||
namespace: {{.Namespace}}
|
|
||||||
labels:
|
|
||||||
app: {{.Name}}
|
|
||||||
spec:
|
|
||||||
replicas: {{.Replicas}}
|
|
||||||
revisionHistoryLimit: {{.Revisions}}
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: {{.Name}}
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: {{.Name}}
|
|
||||||
spec:{{if .ServiceAccount}}
|
|
||||||
serviceAccountName: {{.ServiceAccount}}{{end}}
|
|
||||||
containers:
|
|
||||||
- name: {{.Name}}
|
|
||||||
image: {{.Image}}
|
|
||||||
{{if .ImagePullPolicy}}imagePullPolicy: {{.ImagePullPolicy}}
|
|
||||||
{{end}}ports:
|
|
||||||
- containerPort: {{.Port}}
|
|
||||||
readinessProbe:
|
|
||||||
tcpSocket:
|
|
||||||
port: {{.Port}}
|
|
||||||
initialDelaySeconds: 5
|
|
||||||
periodSeconds: 10
|
|
||||||
livenessProbe:
|
|
||||||
tcpSocket:
|
|
||||||
port: {{.Port}}
|
|
||||||
initialDelaySeconds: 15
|
|
||||||
periodSeconds: 20
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: {{.RequestCpu}}m
|
|
||||||
memory: {{.RequestMem}}Mi
|
|
||||||
limits:
|
|
||||||
cpu: {{.LimitCpu}}m
|
|
||||||
memory: {{.LimitMem}}Mi
|
|
||||||
volumeMounts:
|
|
||||||
- name: timezone
|
|
||||||
mountPath: /etc/localtime
|
|
||||||
{{if .Secret}}imagePullSecrets:
|
|
||||||
- name: {{.Secret}}
|
|
||||||
{{end}}volumes:
|
|
||||||
- name: timezone
|
|
||||||
hostPath:
|
|
||||||
path: /usr/share/zoneinfo/Asia/Shanghai
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: {{.Name}}-svc
|
|
||||||
namespace: {{.Namespace}}
|
|
||||||
spec:
|
|
||||||
ports:
|
|
||||||
{{if .UseNodePort}}- nodePort: {{.NodePort}}
|
|
||||||
port: {{.Port}}
|
|
||||||
protocol: TCP
|
|
||||||
targetPort: {{.TargetPort}}
|
|
||||||
type: NodePort{{else}}- port: {{.Port}}
|
|
||||||
targetPort: {{.TargetPort}}{{end}}
|
|
||||||
selector:
|
|
||||||
app: {{.Name}}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: autoscaling/v2beta2
|
|
||||||
kind: HorizontalPodAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: {{.Name}}-hpa-c
|
|
||||||
namespace: {{.Namespace}}
|
|
||||||
labels:
|
|
||||||
app: {{.Name}}-hpa-c
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
name: {{.Name}}
|
|
||||||
minReplicas: {{.MinReplicas}}
|
|
||||||
maxReplicas: {{.MaxReplicas}}
|
|
||||||
metrics:
|
|
||||||
- type: Resource
|
|
||||||
resource:
|
|
||||||
name: cpu
|
|
||||||
target:
|
|
||||||
type: Utilization
|
|
||||||
averageUtilization: 80
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: autoscaling/v2beta2
|
|
||||||
kind: HorizontalPodAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: {{.Name}}-hpa-m
|
|
||||||
namespace: {{.Namespace}}
|
|
||||||
labels:
|
|
||||||
app: {{.Name}}-hpa-m
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
name: {{.Name}}
|
|
||||||
minReplicas: {{.MinReplicas}}
|
|
||||||
maxReplicas: {{.MaxReplicas}}
|
|
||||||
metrics:
|
|
||||||
- type: Resource
|
|
||||||
resource:
|
|
||||||
name: memory
|
|
||||||
target:
|
|
||||||
type: Utilization
|
|
||||||
averageUtilization: 80
|
|
|
@ -1,37 +0,0 @@
|
||||||
apiVersion: batch/v1
|
|
||||||
kind: CronJob
|
|
||||||
metadata:
|
|
||||||
name: {{.Name}}
|
|
||||||
namespace: {{.Namespace}}
|
|
||||||
spec:
|
|
||||||
successfulJobsHistoryLimit: {{.SuccessfulJobsHistoryLimit}}
|
|
||||||
schedule: "{{.Schedule}}"
|
|
||||||
jobTemplate:
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
spec:{{if .ServiceAccount}}
|
|
||||||
serviceAccountName: {{.ServiceAccount}}{{end}}
|
|
||||||
{{end}}containers:
|
|
||||||
- name: {{.Name}}
|
|
||||||
image: # todo image url
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: {{.RequestCpu}}m
|
|
||||||
memory: {{.RequestMem}}Mi
|
|
||||||
limits:
|
|
||||||
cpu: {{.LimitCpu}}m
|
|
||||||
memory: {{.LimitMem}}Mi
|
|
||||||
command:
|
|
||||||
- ./{{.ServiceName}}
|
|
||||||
- -f
|
|
||||||
- ./{{.Name}}.yaml
|
|
||||||
volumeMounts:
|
|
||||||
- name: timezone
|
|
||||||
mountPath: /etc/localtime
|
|
||||||
imagePullSecrets:
|
|
||||||
- name: # registry secret, if no, remove this
|
|
||||||
restartPolicy: OnFailure
|
|
||||||
volumes:
|
|
||||||
- name: timezone
|
|
||||||
hostPath:
|
|
||||||
path: /usr/share/zoneinfo/Asia/Shanghai
|
|
|
@ -1,14 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
|
|
||||||
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, {{.lowerStartCamelPrimaryKey}})
|
|
||||||
if err!=nil{
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
{{end}} {{.keys}}
|
|
||||||
_, err {{if .containsIndexCache}}={{else}}:={{end}} m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table)
|
|
||||||
return conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}})
|
|
||||||
}, {{.keyValues}}){{else}}query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table)
|
|
||||||
_,err:=m.conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}){{end}}
|
|
||||||
return err
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package {{.pkg}}
|
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
|
|
||||||
var ErrNotFound = sqlx.ErrNotFound
|
|
|
@ -1 +0,0 @@
|
||||||
{{.name}} {{.type}} {{.tag}} {{if .hasComment}}// {{.comment}}{{end}}
|
|
|
@ -1,8 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary any) string {
|
|
||||||
return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryField}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table )
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
|
|
||||||
{{if .withCache}}{{.cacheKey}}
|
|
||||||
var resp {{.upperStartCamelObject}}
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
|
||||||
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.{{.upperStartCamelPrimaryKey}}, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}{{else}}var resp {{.upperStartCamelObject}}
|
|
||||||
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table )
|
|
||||||
err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}{{end}}
|
|
|
@ -1,26 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
|
|
||||||
{{if .withCache}}{{.cacheKey}}
|
|
||||||
var resp {{.upperStartCamelObject}}
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, {{.lowerStartCamelPrimaryKey}})
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}{{else}}query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
|
|
||||||
var resp {{.upperStartCamelObject}}
|
|
||||||
err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelPrimaryKey}})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}{{end}}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
{{if .time}}"time"{{end}}
|
|
||||||
|
|
||||||
{{if .containsPQ}}"github.com/lib/pq"{{end}}
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
|
||||||
)
|
|
|
@ -1,14 +0,0 @@
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
{{if .time}}"time"{{end}}
|
|
||||||
|
|
||||||
{{if .containsPQ}}"github.com/lib/pq"{{end}}
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
|
||||||
)
|
|
|
@ -1,9 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) {
|
|
||||||
{{if .withCache}}{{.keys}}
|
|
||||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
||||||
return conn.ExecCtx(ctx, query, {{.expressionValues}})
|
|
||||||
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
||||||
ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
|
|
||||||
return ret,err
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error
|
|
|
@ -1 +0,0 @@
|
||||||
FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error)
|
|
|
@ -1 +0,0 @@
|
||||||
FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error)
|
|
|
@ -1 +0,0 @@
|
||||||
Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error)
|
|
|
@ -1 +0,0 @@
|
||||||
Update(ctx context.Context, {{if .containsIndexCache}}newData{{else}}data{{end}} *{{.upperStartCamelObject}}) error
|
|
|
@ -1,13 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
|
|
||||||
package {{.pkg}}
|
|
||||||
{{.imports}}
|
|
||||||
{{.vars}}
|
|
||||||
{{.types}}
|
|
||||||
{{.new}}
|
|
||||||
{{.delete}}
|
|
||||||
{{.find}}
|
|
||||||
{{.insert}}
|
|
||||||
{{.update}}
|
|
||||||
{{.extraMethod}}
|
|
||||||
{{.tableName}}
|
|
|
@ -1,6 +0,0 @@
|
||||||
func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf, opts ...cache.Option{{end}}) *default{{.upperStartCamelObject}}Model {
|
|
||||||
return &default{{.upperStartCamelObject}}Model{
|
|
||||||
{{if .withCache}}CachedConn: sqlc.NewConn(conn, c, opts...){{else}}conn:conn{{end}},
|
|
||||||
table: {{.table}},
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package {{.pkg}}
|
|
||||||
{{if .withCache}}
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
{{else}}
|
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
{{end}}
|
|
||||||
var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// {{.upperStartCamelObject}}Model is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in custom{{.upperStartCamelObject}}Model.
|
|
||||||
{{.upperStartCamelObject}}Model interface {
|
|
||||||
{{.lowerStartCamelObject}}Model
|
|
||||||
}
|
|
||||||
|
|
||||||
custom{{.upperStartCamelObject}}Model struct {
|
|
||||||
*default{{.upperStartCamelObject}}Model
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// New{{.upperStartCamelObject}}Model returns a model for the database table.
|
|
||||||
func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf, opts ...cache.Option{{end}}) {{.upperStartCamelObject}}Model {
|
|
||||||
return &custom{{.upperStartCamelObject}}Model{
|
|
||||||
default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c, opts...{{end}}),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
`db:"{{.field}}"`
|
|
|
@ -1,14 +0,0 @@
|
||||||
type (
|
|
||||||
{{.lowerStartCamelObject}}Model interface{
|
|
||||||
{{.method}}
|
|
||||||
}
|
|
||||||
|
|
||||||
default{{.upperStartCamelObject}}Model struct {
|
|
||||||
{{if .withCache}}sqlc.CachedConn{{else}}conn sqlx.SqlConn{{end}}
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
{{.upperStartCamelObject}} struct {
|
|
||||||
{{.fields}}
|
|
||||||
}
|
|
||||||
)
|
|
|
@ -1,14 +0,0 @@
|
||||||
func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, {{if .containsIndexCache}}newData{{else}}data{{end}} *{{.upperStartCamelObject}}) error {
|
|
||||||
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, newData.{{.upperStartCamelPrimaryKey}})
|
|
||||||
if err!=nil{
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
{{end}} {{.keys}}
|
|
||||||
_, {{if .containsIndexCache}}err{{else}}err:{{end}}= m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
|
|
||||||
return conn.ExecCtx(ctx, query, {{.expressionValues}})
|
|
||||||
}, {{.keyValues}}){{else}}query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
|
|
||||||
_,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
|
|
||||||
return err
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
var (
|
|
||||||
{{.lowerStartCamelObject}}FieldNames = builder.RawFieldNames(&{{.upperStartCamelObject}}{}{{if .postgreSql}}, true{{end}})
|
|
||||||
{{.lowerStartCamelObject}}Rows = strings.Join({{.lowerStartCamelObject}}FieldNames, ",")
|
|
||||||
{{.lowerStartCamelObject}}RowsExpectAutoSet = {{if .postgreSql}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}", {{end}} {{.ignoreColumns}}), ","){{else}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}", {{end}} {{.ignoreColumns}}), ","){{end}}
|
|
||||||
{{.lowerStartCamelObject}}RowsWithPlaceHolder = {{if .postgreSql}}builder.PostgreSqlJoin(stringx.Remove({{.lowerStartCamelObject}}FieldNames, "{{.originalPrimaryKey}}", {{.ignoreColumns}})){{else}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, "{{.originalPrimaryKey}}", {{.ignoreColumns}}), "=?,") + "=?"{{end}}
|
|
||||||
|
|
||||||
{{if .withCache}}{{.cacheKeys}}{{end}}
|
|
||||||
)
|
|
|
@ -1,12 +0,0 @@
|
||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/mon"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNotFound = mon.ErrNotFound
|
|
||||||
ErrInvalidObjectId = errors.New("invalid objectId")
|
|
||||||
)
|
|
|
@ -1,78 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
{{if .Cache}}"github.com/zeromicro/go-zero/core/stores/monc"{{else}}"github.com/zeromicro/go-zero/core/stores/mon"{{end}}
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
)
|
|
||||||
|
|
||||||
{{if .Cache}}var prefix{{.Type}}CacheKey = "cache:{{.lowerType}}:"{{end}}
|
|
||||||
|
|
||||||
type {{.lowerType}}Model interface{
|
|
||||||
Insert(ctx context.Context,data *{{.Type}}) error
|
|
||||||
FindOne(ctx context.Context,id string) (*{{.Type}}, error)
|
|
||||||
Update(ctx context.Context,data *{{.Type}}) (*mongo.UpdateResult, error)
|
|
||||||
Delete(ctx context.Context,id string) (int64, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type default{{.Type}}Model struct {
|
|
||||||
conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newDefault{{.Type}}Model(conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}) *default{{.Type}}Model {
|
|
||||||
return &default{{.Type}}Model{conn: conn}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (m *default{{.Type}}Model) Insert(ctx context.Context, data *{{.Type}}) error {
|
|
||||||
if data.ID.IsZero() {
|
|
||||||
data.ID = primitive.NewObjectID()
|
|
||||||
data.CreateAt = time.Now()
|
|
||||||
data.UpdateAt = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
{{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}}
|
|
||||||
_, err := m.conn.InsertOne(ctx, {{if .Cache}}key, {{end}} data)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *default{{.Type}}Model) FindOne(ctx context.Context, id string) (*{{.Type}}, error) {
|
|
||||||
oid, err := primitive.ObjectIDFromHex(id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, ErrInvalidObjectId
|
|
||||||
}
|
|
||||||
|
|
||||||
var data {{.Type}}
|
|
||||||
{{if .Cache}}key := prefix{{.Type}}CacheKey + id{{end}}
|
|
||||||
err = m.conn.FindOne(ctx, {{if .Cache}}key, {{end}}&data, bson.M{"_id": oid})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &data, nil
|
|
||||||
case {{if .Cache}}monc{{else}}mon{{end}}.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *default{{.Type}}Model) Update(ctx context.Context, data *{{.Type}}) (*mongo.UpdateResult, error) {
|
|
||||||
data.UpdateAt = time.Now()
|
|
||||||
{{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}}
|
|
||||||
res, err := m.conn.UpdateOne(ctx, {{if .Cache}}key, {{end}}bson.M{"_id": data.ID}, bson.M{"$set": data})
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *default{{.Type}}Model) Delete(ctx context.Context, id string) (int64, error) {
|
|
||||||
oid, err := primitive.ObjectIDFromHex(id)
|
|
||||||
if err != nil {
|
|
||||||
return 0, ErrInvalidObjectId
|
|
||||||
}
|
|
||||||
{{if .Cache}}key := prefix{{.Type}}CacheKey +id{{end}}
|
|
||||||
res, err := m.conn.DeleteOne(ctx, {{if .Cache}}key, {{end}}bson.M{"_id": oid})
|
|
||||||
return res, err
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package gmodel
|
|
||||||
|
|
||||||
{{if .Cache}}import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/monc"
|
|
||||||
){{else}}import "github.com/zeromicro/go-zero/core/stores/mon"{{end}}
|
|
||||||
|
|
||||||
{{if .Easy}}
|
|
||||||
const {{.Type}}CollectionName = "{{.snakeType}}"
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
var _ {{.Type}}Model = (*custom{{.Type}}Model)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// {{.Type}}Model is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in custom{{.Type}}Model.
|
|
||||||
{{.Type}}Model interface {
|
|
||||||
{{.lowerType}}Model
|
|
||||||
}
|
|
||||||
|
|
||||||
custom{{.Type}}Model struct {
|
|
||||||
*default{{.Type}}Model
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// New{{.Type}}Model returns a model for the mongo.
|
|
||||||
{{if .Easy}}func New{{.Type}}Model(url, db string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
|
|
||||||
conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, {{.Type}}CollectionName{{if .Cache}}, c{{end}})
|
|
||||||
return &custom{{.Type}}Model{
|
|
||||||
default{{.Type}}Model: newDefault{{.Type}}Model(conn),
|
|
||||||
}
|
|
||||||
}{{else}}func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
|
|
||||||
conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, collection{{if .Cache}}, c{{end}})
|
|
||||||
return &custom{{.Type}}Model{
|
|
||||||
default{{.Type}}Model: newDefault{{.Type}}Model(conn),
|
|
||||||
}
|
|
||||||
}{{end}}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
)
|
|
||||||
|
|
||||||
type {{.Type}} struct {
|
|
||||||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
|
|
||||||
// TODO: Fill your own fields
|
|
||||||
UpdateAt time.Time `bson:"updateAt,omitempty" json:"updateAt,omitempty"`
|
|
||||||
CreateAt time.Time `bson:"createAt,omitempty" json:"createAt,omitempty"`
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
type Request {
|
|
||||||
Name string `path:"name,options=you|me"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response {
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
service {{.name}}-api {
|
|
||||||
@handler {{.handler}}Handler
|
|
||||||
get /from/:name(Request) returns (Response)
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
{{.head}}
|
|
||||||
|
|
||||||
package {{.filePackage}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
{{.pbPackage}}
|
|
||||||
{{if ne .pbPackage .protoGoPackage}}{{.protoGoPackage}}{{end}}
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
{{.alias}}
|
|
||||||
|
|
||||||
{{.serviceName}} interface {
|
|
||||||
{{.interface}}
|
|
||||||
}
|
|
||||||
|
|
||||||
default{{.serviceName}} struct {
|
|
||||||
cli zrpc.Client
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func New{{.serviceName}}(cli zrpc.Client) {{.serviceName}} {
|
|
||||||
return &default{{.serviceName}}{
|
|
||||||
cli: cli,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{.functions}}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/zrpc"
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
zrpc.RpcServerConf
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
Name: {{.serviceName}}.rpc
|
|
||||||
ListenOn: 0.0.0.0:8080
|
|
||||||
Etcd:
|
|
||||||
Hosts:
|
|
||||||
- 127.0.0.1:2379
|
|
||||||
Key: {{.serviceName}}.rpc
|
|
|
@ -1,6 +0,0 @@
|
||||||
{{if .hasComment}}{{.comment}}{{end}}
|
|
||||||
func (l *{{.logicName}}) {{.method}} ({{if .hasReq}}in {{.request}}{{if .stream}},stream {{.streamBody}}{{end}}{{else}}stream {{.streamBody}}{{end}}) ({{if .hasReply}}{{.response}},{{end}} error) {
|
|
||||||
// todo: add your logic here and delete this line
|
|
||||||
|
|
||||||
return {{if .hasReply}}&{{.responseType}}{},{{end}} nil
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package {{.packageName}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
{{.imports}}
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type {{.logicName}} struct {
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
logx.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func New{{.logicName}}(ctx context.Context,svcCtx *svc.ServiceContext) *{{.logicName}} {
|
|
||||||
return &{{.logicName}}{
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{.functions}}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
{{.imports}}
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/core/service"
|
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/reflection"
|
|
||||||
)
|
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
|
|
||||||
var c config.Config
|
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
|
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
|
||||||
ctx := svc.NewServiceContext(c)
|
|
||||||
|
|
||||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
|
||||||
{{range .serviceNames}} {{.Pkg}}.Register{{.Service}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx))
|
|
||||||
{{end}}
|
|
||||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
|
||||||
reflection.Register(grpcServer)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
defer s.Stop()
|
|
||||||
|
|
||||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
|
||||||
s.Start()
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
|
|
||||||
{{if .hasComment}}{{.comment}}{{end}}
|
|
||||||
func (s *{{.server}}Server) {{.method}} ({{if .notStream}}ctx context.Context,{{if .hasReq}} in {{.request}}{{end}}{{else}}{{if .hasReq}} in {{.request}},{{end}}stream {{.streamBody}}{{end}}) ({{if .notStream}}{{.response}},{{end}}error) {
|
|
||||||
l := {{.logicPkg}}.New{{.logicName}}({{if .notStream}}ctx,{{else}}stream.Context(),{{end}}s.svcCtx)
|
|
||||||
return l.{{.method}}({{if .hasReq}}in{{if .stream}} ,stream{{end}}{{else}}{{if .stream}}stream{{end}}{{end}})
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{{.head}}
|
|
||||||
|
|
||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
{{if .notStream}}"context"{{end}}
|
|
||||||
|
|
||||||
{{.imports}}
|
|
||||||
)
|
|
||||||
|
|
||||||
type {{.server}}Server struct {
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
{{.unimplementedServer}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func New{{.server}}Server(svcCtx *svc.ServiceContext) *{{.server}}Server {
|
|
||||||
return &{{.server}}Server{
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{.funcs}}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package svc
|
|
||||||
|
|
||||||
import {{.imports}}
|
|
||||||
|
|
||||||
type ServiceContext struct {
|
|
||||||
Config config.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
|
||||||
return &ServiceContext{
|
|
||||||
Config:c,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package {{.package}};
|
|
||||||
option go_package="./{{.package}}";
|
|
||||||
|
|
||||||
message Request {
|
|
||||||
string ping = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Response {
|
|
||||||
string pong = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
service {{.serviceName}} {
|
|
||||||
rpc Ping(Request) returns(Response);
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/utils/fsconfig"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -118,12 +119,14 @@ func main() {
|
||||||
ServerAddress := ":9900"
|
ServerAddress := ":9900"
|
||||||
log.Println("listen on ", ServerAddress)
|
log.Println("listen on ", ServerAddress)
|
||||||
|
|
||||||
keydata, err := os.ReadFile("/opt/server.fusen.3718.cn.key")
|
envcfg := fsconfig.GetEnvCofing()
|
||||||
|
|
||||||
|
keydata, err := os.ReadFile(envcfg.ProxyServer.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pemdata, err := os.ReadFile("/opt/server.fusen.3718.cn.pem")
|
pemdata, err := os.ReadFile(envcfg.ProxyServer.PemFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ run_server() {
|
||||||
# 导航到相应的目录
|
# 导航到相应的目录
|
||||||
cd server/$server_name
|
cd server/$server_name
|
||||||
|
|
||||||
go build
|
go build -race
|
||||||
echo $server_name > .gitignore
|
[ -f .gitignore ] || echo $server_name > .gitignore
|
||||||
# 使用 screen 运行 go run <server_name>.go
|
# 使用 screen 运行 go run <server_name>.go
|
||||||
screen -dmS $server_name -L ./$server_name
|
screen -dmS $server_name -L ./$server_name
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/server/auth/internal/handler"
|
"fusenapi/server/auth/internal/handler"
|
||||||
"fusenapi/server/auth/internal/svc"
|
"fusenapi/server/auth/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,9 +20,8 @@ var configFile = flag.String("f", "etc/auth.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -5,6 +5,5 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(t *testing.T) {
|
func TestMain(t *testing.T) {
|
||||||
|
|
||||||
main()
|
main()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/server/base/internal/handler"
|
"fusenapi/server/base/internal/handler"
|
||||||
"fusenapi/server/base/internal/svc"
|
"fusenapi/server/base/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,9 +20,8 @@ var configFile = flag.String("f", "etc/base.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/canteen.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"fusenapi/server/info/internal/handler"
|
"fusenapi/server/info/internal/handler"
|
||||||
"fusenapi/server/info/internal/svc"
|
"fusenapi/server/info/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,9 +21,8 @@ var configFile = flag.String("f", "etc/info.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
c.Timeout = int64(time.Second * 15)
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/map-library.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/server/pay/internal/handler"
|
"fusenapi/server/pay/internal/handler"
|
||||||
"fusenapi/server/pay/internal/svc"
|
"fusenapi/server/pay/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,9 +20,8 @@ var configFile = flag.String("f", "etc/pay.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/product-model.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,9 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
|
||||||
}
|
}
|
||||||
var mapTemplateTag map[string][][]string
|
var mapMaterialTemplateTag map[string][][]string
|
||||||
b, _ := json.Marshal(metaData["template_tag"])
|
b, _ := json.Marshal(metaData["template_tag"])
|
||||||
if err = json.Unmarshal(b, &mapTemplateTag); err != nil {
|
if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,12 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
||||||
}
|
}
|
||||||
//设置选中
|
//设置选中
|
||||||
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
|
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
|
||||||
if _, ok := mapTemplateTag[key]; ok {
|
if _, ok := mapMaterialTemplateTag[key]; ok {
|
||||||
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
|
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var templateTagNameList []string
|
var templateTagNameList []string
|
||||||
for templateTag, _ := range mapTemplateTag {
|
for templateTag, _ := range mapMaterialTemplateTag {
|
||||||
templateTagNameList = append(templateTagNameList, templateTag)
|
templateTagNameList = append(templateTagNameList, templateTag)
|
||||||
}
|
}
|
||||||
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
|
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
|
||||||
|
@ -127,11 +127,15 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
||||||
colors := make([][]string, 0, 10)
|
colors := make([][]string, 0, 10)
|
||||||
SelectedColorIndex := 0
|
SelectedColorIndex := 0
|
||||||
isDefaultTemplateTag := false
|
isDefaultTemplateTag := false
|
||||||
if colorsSet, ok := mapTemplateTag[*templateInfo.TemplateTag]; ok {
|
//查看用户素材中标签对应的颜色
|
||||||
|
if colorsSet, ok := mapMaterialTemplateTag[*templateInfo.TemplateTag]; ok {
|
||||||
|
//是不是选中的标签
|
||||||
if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok {
|
if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok {
|
||||||
isDefaultTemplateTag = true
|
isDefaultTemplateTag = true
|
||||||
|
//标签中选中的索引
|
||||||
SelectedColorIndex = selectIndex
|
SelectedColorIndex = selectIndex
|
||||||
}
|
}
|
||||||
|
//标签颜色
|
||||||
colors = colorsSet
|
colors = colorsSet
|
||||||
}
|
}
|
||||||
var templateTagGroups []interface{}
|
var templateTagGroups []interface{}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/server/product-template-tag/internal/handler"
|
"fusenapi/server/product-template-tag/internal/handler"
|
||||||
"fusenapi/server/product-template-tag/internal/svc"
|
"fusenapi/server/product-template-tag/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,9 +20,8 @@ var configFile = flag.String("f", "etc/product-template-tag.yaml", "the config f
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/product-template.yaml", "the config file"
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/product.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fusenapi/service/repositories"
|
"fusenapi/service/repositories"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/template_switch_info"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -64,33 +63,41 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
|
||||||
// 否则,使用用户ID和用户键名格式
|
// 否则,使用用户ID和用户键名格式
|
||||||
userId = userinfo.UserId
|
userId = userinfo.UserId
|
||||||
}
|
}
|
||||||
// 获取默认
|
// 没有查到,先根据模版id 查询模版数据 请求算法数据
|
||||||
if req.Address == "" || req.Phone == "" || req.Website == "" || req.Qrcode == "" || req.Slogan == "" {
|
productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
||||||
// 没有查到,先根据模版id 查询模版数据 请求算法数据
|
productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, req.TemplateId)
|
||||||
productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
|
||||||
productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, req.TemplateId)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logc.Errorf(l.ctx, "productTemplateV2Model.FindOne:%v", err)
|
logc.Errorf(l.ctx, "productTemplateV2Model.FindOne:%v", err)
|
||||||
return resp.SetStatus(basic.CodeServiceErr, "模版不存在")
|
return resp.SetStatus(basic.CodeServiceErr, "模版不存在")
|
||||||
}
|
|
||||||
templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(req.TemplateId, productTemplateV2Info.TemplateInfo, *productTemplateV2Info.MaterialImg)
|
|
||||||
if req.Address == "" && templateSwitchInfo.MaterialData.Address.IfShow {
|
|
||||||
req.Address = templateSwitchInfo.MaterialData.Address.DefaultValue
|
|
||||||
}
|
|
||||||
if req.Phone == "" && templateSwitchInfo.MaterialData.Phone.IfShow {
|
|
||||||
req.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue
|
|
||||||
}
|
|
||||||
if req.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow {
|
|
||||||
req.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
|
|
||||||
}
|
|
||||||
if req.Qrcode == "" && templateSwitchInfo.MaterialData.QRcode.IfShow {
|
|
||||||
req.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue
|
|
||||||
}
|
|
||||||
if req.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow {
|
|
||||||
req.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// // 获取默认
|
||||||
|
// if req.Address == "" || req.Phone == "" || req.Website == "" || req.Qrcode == "" || req.Slogan == "" {
|
||||||
|
// // 没有查到,先根据模版id 查询模版数据 请求算法数据
|
||||||
|
// productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
||||||
|
// productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, req.TemplateId)
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// logc.Errorf(l.ctx, "productTemplateV2Model.FindOne:%v", err)
|
||||||
|
// return resp.SetStatus(basic.CodeServiceErr, "模版不存在")
|
||||||
|
// }
|
||||||
|
// templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(req.TemplateId, productTemplateV2Info.TemplateInfo, *productTemplateV2Info.MaterialImg)
|
||||||
|
// if req.Address == "" && templateSwitchInfo.MaterialData.Address.IfShow {
|
||||||
|
// req.Address = templateSwitchInfo.MaterialData.Address.DefaultValue
|
||||||
|
// }
|
||||||
|
// if req.Phone == "" && templateSwitchInfo.MaterialData.Phone.IfShow {
|
||||||
|
// req.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue
|
||||||
|
// }
|
||||||
|
// if req.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow {
|
||||||
|
// req.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
|
||||||
|
// }
|
||||||
|
// if req.Qrcode == "" && templateSwitchInfo.MaterialData.QRcode.IfShow {
|
||||||
|
// req.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue
|
||||||
|
// }
|
||||||
|
// if req.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow {
|
||||||
|
// req.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{
|
res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
|
@ -100,8 +107,14 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
|
||||||
Slogan: req.Slogan,
|
Slogan: req.Slogan,
|
||||||
Phone: req.Phone,
|
Phone: req.Phone,
|
||||||
Address: req.Address,
|
Address: req.Address,
|
||||||
|
Qrcode: req.Qrcode,
|
||||||
Qrcode: req.Qrcode,
|
LogoUrl: req.LogoUrl,
|
||||||
|
TemplateTagColor: repositories.TemplateTagColor{
|
||||||
|
Color: req.TemplateTagColor.Colors,
|
||||||
|
Index: req.TemplateTagColor.SelectedColorIndex,
|
||||||
|
},
|
||||||
|
ProductTemplateTagGroups: req.TemplateTagGroups,
|
||||||
|
ProductTemplateV2Info: productTemplateV2Info,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,16 +28,28 @@ type ResourceInfoReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogoCombineReq struct {
|
type LogoCombineReq struct {
|
||||||
LogoUrl string `json:"logo_url"` // 合图参数
|
TemplateId int64 `json:"template_id"` // 合图参数
|
||||||
TemplateId int64 `json:"template_id"` // 合图参数
|
TemplateTag string `json:"template_tag"` // 合图参数
|
||||||
TemplateTag string `json:"template_tag"` // 合图参数
|
Website string `json:"website,optional"` // 合图参数
|
||||||
Color [][]string `json:"color"` // 颜色组合
|
Slogan string `json:"slogan,optional"` // 合图参数
|
||||||
SelectedIndex int `json:"selected_index"` // 主色的下标索引
|
Address string `json:"address,optional"` // 合图参数
|
||||||
Website string `json:"website,optional"` // 合图参数
|
Phone string `json:"phone,optional"` // 合图参数
|
||||||
Slogan string `json:"slogan,optional"` // 合图参数
|
Qrcode string `json:"qrcode,optional"` // 合图参数
|
||||||
Address string `json:"address,optional"` // 合图参数
|
LogoUrl string `json:"logo_url"` // 合图参数
|
||||||
Phone string `json:"phone,optional"` // 合图参数
|
TemplateTagColor TemplateTagColor `json:"template_tag_color"`
|
||||||
Qrcode string `json:"qrcode,optional"` // 合图参数
|
TemplateTagGroups []TemplateTagGroups `json:"template_tag_groups"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TemplateTagColor struct {
|
||||||
|
Colors [][]string `json:"colors"` // 颜色组合
|
||||||
|
SelectedColorIndex int `json:"selected_color_index"` // 主色的下标索引
|
||||||
|
}
|
||||||
|
|
||||||
|
type TemplateTagGroups struct {
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
Fixed int64 `json:"fixed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/server/resource/internal/handler"
|
"fusenapi/server/resource/internal/handler"
|
||||||
"fusenapi/server/resource/internal/svc"
|
"fusenapi/server/resource/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,9 +20,8 @@ var configFile = flag.String("f", "etc/resource.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"fusenapi/server/shopping-cart/internal/handler"
|
"fusenapi/server/shopping-cart/internal/handler"
|
||||||
"fusenapi/server/shopping-cart/internal/svc"
|
"fusenapi/server/shopping-cart/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,9 +21,8 @@ var configFile = flag.String("f", "etc/shopping-cart.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
c.Timeout = int64(time.Second * 15)
|
c.Timeout = int64(time.Second * 15)
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/upload.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +19,8 @@ var configFile = flag.String("f", "etc/webset.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
|
|
||||||
|
|
|
@ -110,17 +110,8 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
//用户id赋值
|
//用户id赋值
|
||||||
renderImageData.RenderData.UserId = w.userId
|
renderImageData.RenderData.UserId = w.userId
|
||||||
renderImageData.RenderData.GuestId = w.guestId
|
renderImageData.RenderData.GuestId = w.guestId
|
||||||
var (
|
|
||||||
model3dInfo *gmodel.FsProductModel3d
|
|
||||||
productTemplate *gmodel.FsProductTemplateV2
|
|
||||||
productSize *gmodel.FsProductSize
|
|
||||||
)
|
|
||||||
//获取信息
|
//获取信息
|
||||||
if renderImageData.RenderData.ProductSizeId > 0 {
|
productSize, productTemplate, model3dInfo, err := w.getProductRelateionInfo(&renderImageData)
|
||||||
productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithSizeId(&renderImageData)
|
|
||||||
} else {
|
|
||||||
productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithNoSizeId(&renderImageData)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -190,11 +181,6 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
}
|
}
|
||||||
//发送合图完毕阶段消息
|
//发送合图完毕阶段消息
|
||||||
w.sendCombineImageStepResponseMessage(renderImageData.RenderId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DiffTimeLogoCombine, res.DiffTimeUploadFile)
|
w.sendCombineImageStepResponseMessage(renderImageData.RenderId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DiffTimeLogoCombine, res.DiffTimeUploadFile)
|
||||||
//如果指定指定只返回刀版图
|
|
||||||
if renderImageData.OnlyReturnCombineImage {
|
|
||||||
logx.Info("云渲染传入only_return_combine_image = true则不走unity云渲染,只返回刀版图,render_id:", renderImageData.RenderId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//获取唯一id
|
//获取唯一id
|
||||||
taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element)
|
taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element)
|
||||||
//查询有没有缓存的资源,有就返回
|
//查询有没有缓存的资源,有就返回
|
||||||
|
@ -224,57 +210,8 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取模板相关信息(指定尺寸)(尺寸 -> 模型 ->模板)
|
// 获取模板相关信息
|
||||||
func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||||
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOneByIdProductId(w.logic.ctx, renderImageData.RenderData.ProductSizeId, renderImageData.RenderData.ProductId)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到产品的指定尺寸", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
|
|
||||||
logx.Error("product size is not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品的指定尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
|
|
||||||
logx.Error("failed to get product size:", err)
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
//获取模型
|
|
||||||
model3d, err = w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productSize.Id, constants.TAG_MODEL)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "产品尺寸对应的模型不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
|
|
||||||
logx.Error("product model is not found")
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品尺寸对应的模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
|
|
||||||
logx.Error("failed to get product model:", err)
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
//获取模板
|
|
||||||
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3d.Id, renderImageData.RenderData.TemplateTag)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0)
|
|
||||||
logx.Error("找不到对应的模板")
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应的模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0)
|
|
||||||
logx.Error("获取对应的模板失败:", err)
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
if *productTemplate.ElementModelId <= 0 {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板未开启云渲染", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0)
|
|
||||||
return nil, nil, nil, errors.New("模板未开启云渲染")
|
|
||||||
}
|
|
||||||
if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0)
|
|
||||||
return nil, nil, nil, errors.New("渲染模板的设计信息是空的")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取模板相关信息(不指定尺寸)
|
|
||||||
func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
|
||||||
//指定尺寸(尺寸 -> 模型 ->模板)
|
|
||||||
//获取模板
|
//获取模板
|
||||||
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC")
|
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -308,7 +245,6 @@ func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *web
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
|
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
|
||||||
return nil, nil, nil, errors.New("获取对应尺寸失败")
|
return nil, nil, nil, errors.New("获取对应尺寸失败")
|
||||||
}
|
}
|
||||||
renderImageData.RenderData.ProductSizeId = productSize.Id
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"fusenapi/server/websocket/internal/handler"
|
"fusenapi/server/websocket/internal/handler"
|
||||||
"fusenapi/server/websocket/internal/svc"
|
"fusenapi/server/websocket/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +22,8 @@ var configFile = flag.String("f", "etc/websocket.yaml", "the config file")
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -55,15 +55,27 @@ type (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
LogoCombineReq {
|
LogoCombineReq {
|
||||||
LogoUrl string `json:"logo_url"` // 合图参数
|
TemplateId int64 `json:"template_id"` // 合图参数
|
||||||
TemplateId int64 `json:"template_id"` // 合图参数
|
TemplateTag string `json:"template_tag"` // 合图参数
|
||||||
TemplateTag string `json:"template_tag"` // 合图参数
|
Website string `json:"website,optional"` // 合图参数
|
||||||
Color [][]string `json:"color"` // 颜色组合
|
Slogan string `json:"slogan,optional"` // 合图参数
|
||||||
SelectedIndex int `json:"selected_index"` // 主色的下标索引
|
Address string `json:"address,optional"` // 合图参数
|
||||||
Website string `json:"website,optional"` // 合图参数
|
Phone string `json:"phone,optional"` // 合图参数
|
||||||
Slogan string `json:"slogan,optional"` // 合图参数
|
Qrcode string `json:"qrcode,optional"` // 合图参数
|
||||||
Address string `json:"address,optional"` // 合图参数
|
LogoUrl string `json:"logo_url"` // 合图参数
|
||||||
Phone string `json:"phone,optional"` // 合图参数
|
TemplateTagColor TemplateTagColor `json:"template_tag_color"`
|
||||||
Qrcode string `json:"qrcode,optional"` // 合图参数
|
|
||||||
|
TemplateTagGroups []TemplateTagGroups `json:"template_tag_groups"`
|
||||||
|
}
|
||||||
|
TemplateTagColor {
|
||||||
|
Colors [][]string `json:"colors"` // 颜色组合
|
||||||
|
SelectedColorIndex int `json:"selected_color_index"` // 主色的下标索引
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateTagGroups {
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
Fixed int64 `json:"fixed"`
|
||||||
}
|
}
|
||||||
)
|
)
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/nacos-group/nacos-sdk-go/v2/clients"
|
"github.com/nacos-group/nacos-sdk-go/v2/clients"
|
||||||
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
||||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,6 +21,15 @@ type EnvConfig struct {
|
||||||
NamespaceId string `yaml:"namespace"`
|
NamespaceId string `yaml:"namespace"`
|
||||||
DataId string `yaml:"dataid"`
|
DataId string `yaml:"dataid"`
|
||||||
Group string `yaml:"group"`
|
Group string `yaml:"group"`
|
||||||
|
ProxyServer struct {
|
||||||
|
KeyFile string `yaml:"key"`
|
||||||
|
PemFile string `yaml:"pem"`
|
||||||
|
} `yaml:"proxyserver"`
|
||||||
|
|
||||||
|
ServerBackend struct {
|
||||||
|
KeyFile string `yaml:"key"`
|
||||||
|
PemFile string `yaml:"pem"`
|
||||||
|
} `yaml:"serverbackend"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var optPathDirs = []string{"/opt", "./", "../", "../../"}
|
var optPathDirs = []string{"/opt", "./", "../", "../../"}
|
||||||
|
@ -63,7 +73,7 @@ func init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, data string)) string {
|
func StartNacosConfig(configFile string, cfg any, OnChange func(namespace, group, dataId, data string)) {
|
||||||
env := GetEnvCofing()
|
env := GetEnvCofing()
|
||||||
|
|
||||||
// 创建serverConfig
|
// 创建serverConfig
|
||||||
|
@ -136,9 +146,40 @@ func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId,
|
||||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("加载成功:", cfgYaml)
|
var selfConfig map[string]interface{} = make(map[string]interface{})
|
||||||
|
err = yaml.Unmarshal([]byte(content), &selfConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return content
|
content, err = configClient.GetConfig(vo.ConfigParam{
|
||||||
|
DataId: "common",
|
||||||
|
Group: env.Group,
|
||||||
|
OnChange: nil,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var commonConfig map[string]interface{} = make(map[string]interface{})
|
||||||
|
err = yaml.Unmarshal([]byte(content), &commonConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range commonConfig {
|
||||||
|
selfConfig[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := yaml.Marshal(selfConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Print("加载成功: ", cfgYaml, "\n环境: ", env.Group, "\n", string(data))
|
||||||
|
err = conf.LoadFromYamlBytes(data, cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to get config content from Nacos: %v", err)
|
||||||
|
}
|
||||||
// log.Println(content)
|
// log.Println(content)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,33 @@ package fsconfig_test
|
||||||
import (
|
import (
|
||||||
"fusenapi/utils/fsconfig"
|
"fusenapi/utils/fsconfig"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCase1(t *testing.T) {
|
type Config struct {
|
||||||
fsconfig.StartNacosConfig("auth.yaml", nil)
|
rest.RestConf
|
||||||
|
SourceMysql string
|
||||||
|
|
||||||
|
ReplicaId uint64
|
||||||
|
|
||||||
|
MainAddress string
|
||||||
|
WebsocketAddr string
|
||||||
|
|
||||||
|
OAuth struct {
|
||||||
|
Google struct {
|
||||||
|
Appid string
|
||||||
|
Secret string
|
||||||
|
}
|
||||||
|
|
||||||
|
Facebook struct {
|
||||||
|
Appid string
|
||||||
|
Secret string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCase1(t *testing.T) {
|
||||||
|
var c Config
|
||||||
|
fsconfig.StartNacosConfig("auth.yaml", &c, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,8 @@ type DataTransferData struct {
|
||||||
|
|
||||||
// websocket接受要云渲染处理的数据
|
// websocket接受要云渲染处理的数据
|
||||||
type RenderImageReqMsg struct {
|
type RenderImageReqMsg struct {
|
||||||
RenderId string `json:"render_id"` //渲染id
|
RenderId string `json:"render_id"` //渲染id
|
||||||
OnlyReturnCombineImage bool `json:"only_return_combine_image"` //是否只返回刀版图
|
RenderData RenderData `json:"render_data"` //渲染主要参数
|
||||||
RenderData RenderData `json:"render_data"`
|
|
||||||
}
|
}
|
||||||
type RenderData struct {
|
type RenderData struct {
|
||||||
TemplateTag string `json:"template_tag"` //模板标签(必须)
|
TemplateTag string `json:"template_tag"` //模板标签(必须)
|
||||||
|
@ -25,7 +24,6 @@ type RenderData struct {
|
||||||
Address string `json:"address"` //地址(可选)
|
Address string `json:"address"` //地址(可选)
|
||||||
Phone string `json:"phone"` //电话(可选)
|
Phone string `json:"phone"` //电话(可选)
|
||||||
Qrcode string `json:"qrcode"` //二维码(可选)
|
Qrcode string `json:"qrcode"` //二维码(可选)
|
||||||
ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选)
|
|
||||||
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
|
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
|
||||||
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
|
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user