TODO: render/ 相关模块
This commit is contained in:
		
							parent
							
								
									8ba8a67dfb
								
							
						
					
					
						commit
						9b56d7ba51
					
				
							
								
								
									
										6
									
								
								constants/concact_service.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								constants/concact_service.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | package constants | ||||||
|  | 
 | ||||||
|  | type ConcactService string | ||||||
|  | 
 | ||||||
|  | const TYPE_DEFAULT ConcactService = "default" | ||||||
|  | const TYPE_ORDER ConcactService = "order" | ||||||
| @ -2,6 +2,8 @@ package gmodel | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fusenapi/constants" | ||||||
|  | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| ) | ) | ||||||
| @ -31,7 +33,19 @@ func (p *FsCloudPickUpModel) SavePickUpWithTransaction(ctx context.Context, pick | |||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64) (cloudOrder *FsCloudPickUp, err error) { | func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64, cs *FsContactService) (cloudOrder *FsCloudPickUp, err error) { | ||||||
|  | 	err = p.db.WithContext(ctx).Model(cloudOrder).Transaction(func(tx *gorm.DB) error { | ||||||
|  | 		err = tx.Model(cloudOrder).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, RelationID).Take(&cloudOrder).Error | ||||||
|  | 		if err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 		ctime := time.Now().Unix() | ||||||
|  | 		cs.Ctime = &ctime | ||||||
|  | 		if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT { | ||||||
|  | 			*cs.RelationId = 0 | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
|  | 		return tx.Model(cs).Create(cs).Error | ||||||
|  | 	}) | ||||||
| 	return cloudOrder, err | 	return cloudOrder, err | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,6 +2,8 @@ package gmodel | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fusenapi/constants" | ||||||
|  | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| ) | ) | ||||||
| @ -27,11 +29,19 @@ func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error { | |||||||
| 	return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error | 	return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64) (order *FsOrder, err error) { | func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64, cs *FsContactService) (order *FsOrder, err error) { | ||||||
| 	err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | 	err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | ||||||
| 		err = tx.Model(order).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error | 		err = tx.Model(order).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error | ||||||
| 		tx.Table("").Model(FsContactService{}) | 		if err != nil { | ||||||
| 		return err | 			return err | ||||||
|  | 		} | ||||||
|  | 		ctime := time.Now().Unix() | ||||||
|  | 		cs.Ctime = &ctime | ||||||
|  | 		if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT { | ||||||
|  | 			*cs.RelationId = 0 | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		return tx.Model(cs).Create(cs).Error | ||||||
| 	}) | 	}) | ||||||
| 	return order, err | 	return order, err | ||||||
| } | } | ||||||
|  | |||||||
| @ -37,13 +37,14 @@ func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactSe | |||||||
| 		return resp.SetStatus(basic.CodeUnAuth) | 		return resp.SetStatus(basic.CodeUnAuth) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	cs := gmodel.FsContactService{} | 	cs := gmodel.FsContactService{ | ||||||
| 
 | 		UserId: &userinfo.UserId, | ||||||
| 	collect.LoadJsonTag(cs, req) | 	} | ||||||
|  | 	collect.LoadJsonTag(&cs, &req) | ||||||
| 
 | 
 | ||||||
| 	switch req.Type { | 	switch req.Type { | ||||||
| 	case "order": | 	case "order": | ||||||
| 		_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID) | 		_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID, &cs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			if err == gorm.ErrRecordNotFound { | 			if err == gorm.ErrRecordNotFound { | ||||||
| 				return resp.SetStatus(basic.CodeOrderNotFoundErr) | 				return resp.SetStatus(basic.CodeOrderNotFoundErr) | ||||||
| @ -51,16 +52,17 @@ func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactSe | |||||||
| 			return resp.SetStatus(basic.CodeDbSqlErr) | 			return resp.SetStatus(basic.CodeDbSqlErr) | ||||||
| 		} | 		} | ||||||
| 	case "cloud": | 	case "cloud": | ||||||
| 		_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID) | 		_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID, &cs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			if err == gorm.ErrRecordNotFound { | 			if err == gorm.ErrRecordNotFound { | ||||||
| 				return resp.SetStatus(basic.CodeCloudOrderNotFoundErr) | 				return resp.SetStatus(basic.CodeCloudOrderNotFoundErr) | ||||||
| 			} | 			} | ||||||
| 			return resp.SetStatus(basic.CodeDbSqlErr) | 			return resp.SetStatus(basic.CodeDbSqlErr) | ||||||
| 		} | 		} | ||||||
|  | 		return | ||||||
| 	default: | 	default: | ||||||
| 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown") | 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return resp.SetStatus(basic.CodeOK) | 	return resp.SetStatus(basic.CodeOK, cs) | ||||||
| } | } | ||||||
|  | |||||||
| @ -18,16 +18,16 @@ func TestUserContactService(t *testing.T) { | |||||||
| 	// 获取 session,并携带 JWT token | 	// 获取 session,并携带 JWT token | ||||||
| 	ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port) | 	ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port) | ||||||
| 	tp := ses.Post(fmt.Sprintf("http://%s:%d/user/contact-service", cnf.Host, cnf.Port)) | 	tp := ses.Post(fmt.Sprintf("http://%s:%d/user/contact-service", cnf.Host, cnf.Port)) | ||||||
| 	req := types.RequestContactService{Type: "order", RelationID: 123, Email: "admin@admin.com", Name: "eson"} | 	req := types.RequestContactService{Type: "order", RelationID: 481, Email: "9107058@qq.com", Name: "zhang"} | ||||||
| 	tp.SetBodyJson(req) | 	tp.SetBodyJson(req) | ||||||
| 	// 向服务器发送 GET 请求,获取用户基本信息 | 	// 向服务器发送 GET 请求,获取用户基本信息 | ||||||
| 	resp, err = tp.TestExecute(gserver) | 	resp, err = tp.TestExecute(gserver) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Error(err) | 		t.Error(err) | ||||||
| 	} | 	} | ||||||
| 
 | 	respjson := resp.Json() | ||||||
| 	// 检查返回值中的 code 字段是否存在,并且值是否为 200 | 	// 检查返回值中的 code 字段是否存在,并且值是否为 200 | ||||||
| 	result = resp.Json().Get("code") | 	result = respjson.Get("code") | ||||||
| 	if !result.Exists() { | 	if !result.Exists() { | ||||||
| 		t.Error("code is not exists") | 		t.Error("code is not exists") | ||||||
| 	} | 	} | ||||||
| @ -36,7 +36,7 @@ func TestUserContactService(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 检查返回值中的 msg 字段是否存在,并且值是否为 "success" | 	// 检查返回值中的 msg 字段是否存在,并且值是否为 "success" | ||||||
| 	result = resp.Json().Get("msg") | 	result = respjson.Get("msg") | ||||||
| 	if !result.Exists() { | 	if !result.Exists() { | ||||||
| 		t.Error("msg is not exists") | 		t.Error("msg is not exists") | ||||||
| 	} | 	} | ||||||
| @ -45,63 +45,26 @@ func TestUserContactService(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 检查返回值中的 data 字段是否存在 | 	// 检查返回值中的 data 字段是否存在 | ||||||
| 	result = resp.Json().Get("data") | 	result = respjson.Get("data") | ||||||
| 	if !result.Exists() { | 	if !result.Exists() { | ||||||
| 		t.Error("data is not exists") | 		t.Error("data is not exists") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 检查返回值中的 type 字段是否存在,并且值是否为 0 | 	// 检查返回值中的 msg 字段是否存在,并且值是否为 "success" | ||||||
| 	result = resp.Json().Get("data.type") | 	result = respjson.Get("msg") | ||||||
| 	if !result.Exists() { | 	if !result.Exists() { | ||||||
| 		t.Error("type is not exists") | 		t.Error("msg does not exist") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 检查返回值中的 is_order_status_email 字段是否存在,并且值是否为 false | 	data := respjson.Get("data") | ||||||
| 	result = resp.Json().Get("data.is_order_status_email") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_order_status_email is not exists") |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	// 检查返回值中的 is_email_advertisement 字段是否存在,并且值是否为 false | 	// 补充检查返回值中的每个字段是否存在 | ||||||
| 	result = resp.Json().Get("data.is_email_advertisement") | 	fieldKeys := []string{"id", "type", "relation_id", "user_id", "name", "email", "phone", "remark", "is_handle", "ctime", "handle_remark", "handle_uid", "handle_time"} | ||||||
| 	if !result.Exists() { | 	for _, key := range fieldKeys { | ||||||
| 		t.Error("is_email_advertisement is not exists") | 		field := data.Get(key) | ||||||
| 	} | 		if !field.Exists() { | ||||||
| 
 | 			t.Errorf("Field '%s' does not exist", key) | ||||||
| 	// 检查返回值中的 is_order_status_phone 字段是否存在,并且值是否为 false | 		} | ||||||
| 	result = resp.Json().Get("data.is_order_status_phone") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_order_status_phone is not exists") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 检查返回值中的 is_phone_advertisement 字段是否存在,并且值是否为 false |  | ||||||
| 	result = resp.Json().Get("data.is_phone_advertisement") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_phone_advertisement is not exists") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 检查返回值中的 is_open_render 字段是否存在,并且值是否为 false |  | ||||||
| 	result = resp.Json().Get("data.is_open_render") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_open_render is not exists") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 检查返回值中的 is_thousand_face 字段是否存在,并且值是否为 false |  | ||||||
| 	result = resp.Json().Get("data.is_thousand_face") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_thousand_face is not exists") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 检查返回值中的 is_low_rendering 字段是否存在,并且值是否为 false |  | ||||||
| 	result = resp.Json().Get("data.is_low_rendering") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_low_rendering is not exists") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 检查返回值中的 is_remove_bg 字段是否存在,并且值是否为 true |  | ||||||
| 	result = resp.Json().Get("data.is_remove_bg") |  | ||||||
| 	if !result.Exists() { |  | ||||||
| 		t.Error("is_remove_bg is not exists") |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										8
									
								
								server/render/etc/render.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								server/render/etc/render.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | Name: render | ||||||
|  | Host: 0.0.0.0 | ||||||
|  | Port: 8888 | ||||||
|  | SourceMysql: "" | ||||||
|  | Auth: | ||||||
|  |     AccessSecret: fusen2023 | ||||||
|  |     AccessExpire: 604800 | ||||||
|  |     RefreshAfter: 345600 | ||||||
							
								
								
									
										9
									
								
								server/render/internal/config/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								server/render/internal/config/config.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | package config | ||||||
|  | 
 | ||||||
|  | import "github.com/zeromicro/go-zero/rest" | ||||||
|  | 
 | ||||||
|  | type Config struct { | ||||||
|  | 	rest.RestConf | ||||||
|  | 	SourceMysql string | ||||||
|  | 	Auth        types.Auth | ||||||
|  | } | ||||||
							
								
								
									
										78
									
								
								server/render/internal/handler/readimageshandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								server/render/internal/handler/readimageshandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,78 @@ | |||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"errors" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | 	"github.com/zeromicro/go-zero/rest/httpx" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/utils/auth" | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/logic" | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 	"fusenapi/server/render/internal/types" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||||||
|  | 	return func(w http.ResponseWriter, r *http.Request) { | ||||||
|  | 
 | ||||||
|  | 		var ( | ||||||
|  | 			// 定义错误变量 | ||||||
|  | 			err error | ||||||
|  | 			// 定义用户信息变量 | ||||||
|  | 			userinfo *auth.UserInfo | ||||||
|  | 		) | ||||||
|  | 		// 解析JWT token,并对空用户进行判断 | ||||||
|  | 		claims, err := svcCtx.ParseJwtToken(r) | ||||||
|  | 		// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 | ||||||
|  | 		if err != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 				Code:    401,            // 返回401状态码,表示未授权 | ||||||
|  | 				Message: "unauthorized", // 返回未授权信息 | ||||||
|  | 			}) | ||||||
|  | 			logx.Info("unauthorized:", err.Error()) // 记录错误日志 | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if claims != nil { | ||||||
|  | 			// 从token中获取对应的用户信息 | ||||||
|  | 			userinfo, err = auth.GetUserInfoFormMapClaims(claims) | ||||||
|  | 			// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 | ||||||
|  | 			if err != nil { | ||||||
|  | 				httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 					Code:    401, | ||||||
|  | 					Message: "unauthorized", | ||||||
|  | 				}) | ||||||
|  | 				logx.Info("unauthorized:", err.Error()) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 		} else { | ||||||
|  | 			// 如果claims为nil,则认为用户身份为白板用户 | ||||||
|  | 			userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		var req types.RequestReadImages | ||||||
|  | 		// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 | ||||||
|  | 		if err := httpx.Parse(r, &req); err != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 				Code:    510, | ||||||
|  | 				Message: "parameter error", | ||||||
|  | 			}) | ||||||
|  | 			logx.Info(err) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		// 创建一个业务逻辑层实例 | ||||||
|  | 		l := logic.NewReadImagesLogic(r.Context(), svcCtx) | ||||||
|  | 		resp := l.ReadImages(&req, userinfo) | ||||||
|  | 		// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; | ||||||
|  | 		if resp != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, resp) | ||||||
|  | 		} else { | ||||||
|  | 			err := errors.New("server logic is error, resp must not be nil") | ||||||
|  | 			httpx.ErrorCtx(r.Context(), w, err) | ||||||
|  | 			logx.Error(err) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										27
									
								
								server/render/internal/handler/routes.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								server/render/internal/handler/routes.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | // Code generated by goctl. DO NOT EDIT. | ||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/rest" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||||||
|  | 	server.AddRoutes( | ||||||
|  | 		[]rest.Route{ | ||||||
|  | 			{ | ||||||
|  | 				Method:  http.MethodGet, | ||||||
|  | 				Path:    "/render/to-unity", | ||||||
|  | 				Handler: ToUnityHandler(serverCtx), | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Method:  http.MethodGet, | ||||||
|  | 				Path:    "/render/read-images", | ||||||
|  | 				Handler: ReadImagesHandler(serverCtx), | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	) | ||||||
|  | } | ||||||
							
								
								
									
										78
									
								
								server/render/internal/handler/tounityhandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								server/render/internal/handler/tounityhandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,78 @@ | |||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"errors" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | 	"github.com/zeromicro/go-zero/rest/httpx" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/utils/auth" | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/logic" | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 	"fusenapi/server/render/internal/types" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||||||
|  | 	return func(w http.ResponseWriter, r *http.Request) { | ||||||
|  | 
 | ||||||
|  | 		var ( | ||||||
|  | 			// 定义错误变量 | ||||||
|  | 			err error | ||||||
|  | 			// 定义用户信息变量 | ||||||
|  | 			userinfo *auth.UserInfo | ||||||
|  | 		) | ||||||
|  | 		// 解析JWT token,并对空用户进行判断 | ||||||
|  | 		claims, err := svcCtx.ParseJwtToken(r) | ||||||
|  | 		// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 | ||||||
|  | 		if err != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 				Code:    401,            // 返回401状态码,表示未授权 | ||||||
|  | 				Message: "unauthorized", // 返回未授权信息 | ||||||
|  | 			}) | ||||||
|  | 			logx.Info("unauthorized:", err.Error()) // 记录错误日志 | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if claims != nil { | ||||||
|  | 			// 从token中获取对应的用户信息 | ||||||
|  | 			userinfo, err = auth.GetUserInfoFormMapClaims(claims) | ||||||
|  | 			// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 | ||||||
|  | 			if err != nil { | ||||||
|  | 				httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 					Code:    401, | ||||||
|  | 					Message: "unauthorized", | ||||||
|  | 				}) | ||||||
|  | 				logx.Info("unauthorized:", err.Error()) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 		} else { | ||||||
|  | 			// 如果claims为nil,则认为用户身份为白板用户 | ||||||
|  | 			userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		var req types.RequestToUnity | ||||||
|  | 		// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 | ||||||
|  | 		if err := httpx.Parse(r, &req); err != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, &basic.Response{ | ||||||
|  | 				Code:    510, | ||||||
|  | 				Message: "parameter error", | ||||||
|  | 			}) | ||||||
|  | 			logx.Info(err) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		// 创建一个业务逻辑层实例 | ||||||
|  | 		l := logic.NewToUnityLogic(r.Context(), svcCtx) | ||||||
|  | 		resp := l.ToUnity(&req, userinfo) | ||||||
|  | 		// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; | ||||||
|  | 		if resp != nil { | ||||||
|  | 			httpx.OkJsonCtx(r.Context(), w, resp) | ||||||
|  | 		} else { | ||||||
|  | 			err := errors.New("server logic is error, resp must not be nil") | ||||||
|  | 			httpx.ErrorCtx(r.Context(), w, err) | ||||||
|  | 			logx.Error(err) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								server/render/internal/logic/readimageslogic.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								server/render/internal/logic/readimageslogic.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | |||||||
|  | package logic | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fusenapi/utils/auth" | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"context" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 	"fusenapi/server/render/internal/types" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type ReadImagesLogic struct { | ||||||
|  | 	logx.Logger | ||||||
|  | 	ctx    context.Context | ||||||
|  | 	svcCtx *svc.ServiceContext | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewReadImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadImagesLogic { | ||||||
|  | 	return &ReadImagesLogic{ | ||||||
|  | 		Logger: logx.WithContext(ctx), | ||||||
|  | 		ctx:    ctx, | ||||||
|  | 		svcCtx: svcCtx, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *ReadImagesLogic) ReadImages(req *types.RequestReadImages, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | 	// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) | ||||||
|  | 	// userinfo 传入值时, 一定不为null | ||||||
|  | 
 | ||||||
|  | 	return resp.SetStatus(basic.CodeOK) | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								server/render/internal/logic/tounitylogic.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								server/render/internal/logic/tounitylogic.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | |||||||
|  | package logic | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fusenapi/utils/auth" | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"context" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 	"fusenapi/server/render/internal/types" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type ToUnityLogic struct { | ||||||
|  | 	logx.Logger | ||||||
|  | 	ctx    context.Context | ||||||
|  | 	svcCtx *svc.ServiceContext | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewToUnityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToUnityLogic { | ||||||
|  | 	return &ToUnityLogic{ | ||||||
|  | 		Logger: logx.WithContext(ctx), | ||||||
|  | 		ctx:    ctx, | ||||||
|  | 		svcCtx: svcCtx, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *ToUnityLogic) ToUnity(req *types.RequestToUnity, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | 	// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) | ||||||
|  | 	// userinfo 传入值时, 一定不为null | ||||||
|  | 
 | ||||||
|  | 	return resp.SetStatus(basic.CodeOK) | ||||||
|  | } | ||||||
							
								
								
									
										60
									
								
								server/render/internal/svc/servicecontext.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								server/render/internal/svc/servicecontext.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | |||||||
|  | package svc | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"fusenapi/server/render/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/initalize" | ||||||
|  | 	"fusenapi/model/gmodel" | ||||||
|  | 
 | ||||||
|  | 	"github.com/golang-jwt/jwt" | ||||||
|  | 	"gorm.io/gorm" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type ServiceContext struct { | ||||||
|  | 	Config config.Config | ||||||
|  | 
 | ||||||
|  | 	MysqlConn *gorm.DB | ||||||
|  | 	AllModels *gmodel.AllModelsGen | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewServiceContext(c config.Config) *ServiceContext { | ||||||
|  | 
 | ||||||
|  | 	return &ServiceContext{ | ||||||
|  | 		Config:    c, | ||||||
|  | 		MysqlConn: initalize.InitMysql(c.SourceMysql), | ||||||
|  | 		AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
|  | 	AuthKey := r.Header.Get("Authorization") | ||||||
|  | 	if AuthKey == "" { | ||||||
|  | 		return nil, nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	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)) | ||||||
|  | } | ||||||
							
								
								
									
										74
									
								
								server/render/internal/types/types.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								server/render/internal/types/types.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,74 @@ | |||||||
|  | // Code generated by goctl. DO NOT EDIT. | ||||||
|  | package types | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type RequestToUnity struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type RequestReadImages struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Request struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Response struct { | ||||||
|  | 	Code    int         `json:"code"` | ||||||
|  | 	Message string      `json:"msg"` | ||||||
|  | 	Data    interface{} `json:"data"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Auth struct { | ||||||
|  | 	AccessSecret string `json:"accessSecret"` | ||||||
|  | 	AccessExpire int64  `json:"accessExpire"` | ||||||
|  | 	RefreshAfter int64  `json:"refreshAfter"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Pagnation struct { | ||||||
|  | 	TotalCount int64 `json:"total_count"` | ||||||
|  | 	TotalPage  int64 `json:"total_page"` | ||||||
|  | 	CurPage    int64 `json:"cur_page"` | ||||||
|  | 	PageSize   int64 `json:"page_size"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // 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 | ||||||
|  | } | ||||||
							
								
								
									
										49
									
								
								server/render/render.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								server/render/render.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | |||||||
|  | package main | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"flag" | ||||||
|  | 	"fmt" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/render/internal/config" | ||||||
|  | 	"fusenapi/server/render/internal/handler" | ||||||
|  | 	"fusenapi/server/render/internal/svc" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/conf" | ||||||
|  | 	"github.com/zeromicro/go-zero/rest" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | var configFile = flag.String("f", "etc/render.yaml", "the config file") | ||||||
|  | 
 | ||||||
|  | func main() { | ||||||
|  | 	flag.Parse() | ||||||
|  | 
 | ||||||
|  | 	var c config.Config | ||||||
|  | 	conf.MustLoad(*configFile, &c) | ||||||
|  | 
 | ||||||
|  | 	server := rest.MustNewServer(c.RestConf) | ||||||
|  | 	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/render.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 | ||||||
|  | // } | ||||||
							
								
								
									
										25
									
								
								server_api/render.api
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								server_api/render.api
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  | syntax = "v1" | ||||||
|  | 
 | ||||||
|  | info ( | ||||||
|  | 	title: "渲染"// TODO: add title | ||||||
|  | 	desc: // TODO: add description | ||||||
|  | 	author: "" | ||||||
|  | 	email: "" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | import "basic.api" | ||||||
|  | 
 | ||||||
|  | type RequestToUnity { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type RequestReadImages { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | service render { | ||||||
|  | 	// 发送数据到unity渲染 | ||||||
|  | 	@handler ToUnityHandler | ||||||
|  | 	get /render/to-unity (RequestToUnity) returns (response); | ||||||
|  | 	// 读图像 | ||||||
|  | 	@handler ReadImagesHandler | ||||||
|  | 	get /render/read-images (RequestReadImages) returns (response); | ||||||
|  | } | ||||||
| @ -1,7 +1,6 @@ | |||||||
| package collect | package collect | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"log" |  | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| ) | ) | ||||||
| @ -215,23 +214,33 @@ func StructSliceJson2Maps(s interface{}) []map[string]interface{} { | |||||||
| 	return maps | 	return maps | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // LoadJsonTag 根据loader的json tag 赋值 给拥有相同json tag | ||||||
| func LoadJsonTag(v interface{}, loaded interface{}) { | func LoadJsonTag(v interface{}, loaded interface{}) { | ||||||
| 	vtype := reflect.TypeOf(v) | 	vtype := reflect.TypeOf(v) | ||||||
|  | 	if vtype.Kind() != reflect.Ptr { | ||||||
|  | 		panic("v must is a pointer") | ||||||
|  | 	} | ||||||
|  | 	vtype = vtype.Elem() | ||||||
|  | 
 | ||||||
|  | 	var vvalue reflect.Value | ||||||
| 	if vtype.Kind() == reflect.Ptr { | 	if vtype.Kind() == reflect.Ptr { | ||||||
| 		vtype = vtype.Elem() | 		vtype = vtype.Elem() | ||||||
| 	} | 		vvalue = reflect.ValueOf(v).Elem().Elem() | ||||||
| 	vvalue := reflect.ValueOf(v) | 	} else { | ||||||
| 	if vvalue.Kind() == reflect.Ptr { | 		vvalue = reflect.ValueOf(v).Elem() | ||||||
| 		vvalue = vvalue.Elem() |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	ltype := reflect.TypeOf(loaded) | 	ltype := reflect.TypeOf(loaded) | ||||||
|  | 	if ltype.Kind() != reflect.Ptr { | ||||||
|  | 		panic("loaded must is a pointer") | ||||||
|  | 	} | ||||||
|  | 	ltype = ltype.Elem() | ||||||
|  | 	var lvalue reflect.Value | ||||||
| 	if ltype.Kind() == reflect.Ptr { | 	if ltype.Kind() == reflect.Ptr { | ||||||
| 		ltype = ltype.Elem() | 		ltype = ltype.Elem() | ||||||
| 	} | 		lvalue = reflect.ValueOf(loaded).Elem().Elem() | ||||||
| 	lvalue := reflect.ValueOf(loaded) | 	} else { | ||||||
| 	if lvalue.Kind() == reflect.Ptr { | 		lvalue = reflect.ValueOf(loaded).Elem() | ||||||
| 		lvalue = lvalue.Elem() |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for i := 0; i < vtype.NumField(); i++ { | 	for i := 0; i < vtype.NumField(); i++ { | ||||||
| @ -244,26 +253,25 @@ func LoadJsonTag(v interface{}, loaded interface{}) { | |||||||
| 				if ltag, ok := lfield.Tag.Lookup("json"); ok && vtag == ltag { | 				if ltag, ok := lfield.Tag.Lookup("json"); ok && vtag == ltag { | ||||||
| 					vv := vvalue.Field(i) | 					vv := vvalue.Field(i) | ||||||
| 					lv := lvalue.Field(j) | 					lv := lvalue.Field(j) | ||||||
| 					log.Println(vv.Kind(), vv.Type().Elem(), lv.Kind()) | 
 | ||||||
| 					if vv.Kind() == reflect.Ptr { | 					if vv.Kind() == reflect.Ptr { | ||||||
|  | 
 | ||||||
| 						if lv.Kind() == reflect.Ptr { | 						if lv.Kind() == reflect.Ptr { | ||||||
| 							vv.Set(lv) | 							vv.Set(lv) | ||||||
| 						} else { | 						} else { | ||||||
| 							vv = reflect.New(vv.Type().Elem()) | 							x := reflect.New(vv.Type().Elem()) | ||||||
| 							log.Println(vv.Type().Kind(), vv.Elem().Kind(), lv, reflect.Indirect(vv)) | 							x.Elem().Set(lv) | ||||||
| 							reflect.Indirect(vv.Addr()).Set(lv.Addr()) | 							vv.Set(x) | ||||||
| 							vv = reflect.New(vv.Type().Elem()) |  | ||||||
| 
 |  | ||||||
| 							vv.Set(lv.Addr()) |  | ||||||
| 						} | 						} | ||||||
| 
 | 
 | ||||||
| 						vv.Set(lv) |  | ||||||
| 					} else { | 					} else { | ||||||
|  | 
 | ||||||
| 						if lv.Kind() != reflect.Ptr { | 						if lv.Kind() != reflect.Ptr { | ||||||
| 							vv.Set(lv) | 							vv.Set(lv) | ||||||
| 						} else { | 						} else { | ||||||
| 							vv.Set(lv.Elem()) | 							vv.Set(lv.Elem()) | ||||||
| 						} | 						} | ||||||
|  | 
 | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -1,7 +1,9 @@ | |||||||
| package collect | package collect | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
| 	"log" | 	"log" | ||||||
|  | 	"reflect" | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -40,3 +42,36 @@ func TestArrayColumnTag(t *testing.T) { | |||||||
| 	log.Printf("%##v", a) | 	log.Printf("%##v", a) | ||||||
| 	log.Println(len(a)) | 	log.Println(len(a)) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestCaseMain(t *testing.T) { | ||||||
|  | 
 | ||||||
|  | 	type MyStruct struct { | ||||||
|  | 		SomeIntPtr    *int | ||||||
|  | 		SomeStringPtr *string | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	var ms MyStruct | ||||||
|  | 
 | ||||||
|  | 	// Set int pointer | ||||||
|  | 	{ | ||||||
|  | 		var i interface{} = 3 // of type int | ||||||
|  | 
 | ||||||
|  | 		f := reflect.ValueOf(&ms).Elem().FieldByName("SomeIntPtr") | ||||||
|  | 		x := reflect.New(f.Type().Elem()) | ||||||
|  | 		x.Elem().Set(reflect.ValueOf(i)) | ||||||
|  | 		f.Set(x) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// Set string pointer | ||||||
|  | 	{ | ||||||
|  | 		var i interface{} = "hi" // of type string | ||||||
|  | 
 | ||||||
|  | 		f := reflect.ValueOf(&ms).Elem().Field(1) | ||||||
|  | 		x := reflect.New(f.Type().Elem()) | ||||||
|  | 		x.Elem().Set(reflect.ValueOf(i)) | ||||||
|  | 		f.Set(x) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fmt.Println("ms.SomeIntPtr", *ms.SomeIntPtr) | ||||||
|  | 	fmt.Println("ms.SomeStringPtr", *ms.SomeStringPtr) | ||||||
|  | } | ||||||
|  | |||||||
| @ -16,8 +16,8 @@ func GetSessionWithUserToken(t *testing.T, server requests.ITestServer, Host str | |||||||
| 	ses := requests.NewSession() | 	ses := requests.NewSession() | ||||||
| 	tp := ses.Post(fmt.Sprintf("http://%s:%d/user/login", Host, Port)) | 	tp := ses.Post(fmt.Sprintf("http://%s:%d/user/login", Host, Port)) | ||||||
| 	tp.SetBodyJson(map[string]interface{}{ | 	tp.SetBodyJson(map[string]interface{}{ | ||||||
| 		"name": "devenv@sina.cn", | 		"name": "9107058@qq.com", | ||||||
| 		"pwd":  "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC", | 		"pwd":  "$2y$13$2y4O4OIz/zcK5C0vlSc9LuSpjWySjInLBSe49yDkE.iURb.R1hDsy", | ||||||
| 	}) | 	}) | ||||||
| 	resp, err := tp.TestExecute(server) | 	resp, err := tp.TestExecute(server) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user