@rdmind/rdmind 0.1.8-alpha.9 → 0.1.9-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +2424 -1884
- package/locales/en.js +93 -192
- package/locales/zh.js +105 -213
- package/package.json +2 -2
- package/template/pom.xml +40 -0
- package/template/sns-demo-app/pom.xml +0 -5
- package/template/sns-demo-common/pom.xml +4 -5
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/constants/AppPlatform.java +57 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/enums/ErrorCodeEnum.java +30 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/exception/AppBizException.java +51 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/utils/AssertUtils.java +137 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/utils/JsonHelper.java +129 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/utils/WrappedContextHelper.java +182 -0
- package/template/sns-demo-domain/pom.xml +0 -5
- package/template/sns-demo-infrastructure/pom.xml +0 -5
- package/template/sns-demo-start/pom.xml +0 -5
- package/template/sns-demo-start/src/main/resources/logback-spring.xml +16 -19
- package/templates/idl-template/wiki/.idea/codeStyles/Project.xml +7 -0
- package/templates/idl-template/wiki/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/templates/idl-template/wiki/.idea/inspectionProfiles/Project_Default.xml +5 -0
- package/templates/idl-template/wiki/.idea/misc.xml +14 -0
- package/templates/idl-template/wiki/.idea/modules.xml +8 -0
- package/templates/idl-template/wiki/.idea/vcs.xml +6 -0
- package/templates/idl-template/wiki/.idea/wiki.iml +9 -0
- package/templates/idl-template/wiki/SDK-Dev-Guide.md +0 -2
- package/templates/idl-template/wiki/example/.gitlab-ci.yml +3 -17
- package/templates/idl-template/wiki/example/base.thrift +94 -0
- package/templates/idl-template/wiki/example/common.thrift +39 -0
- package/templates/idl-template/wiki/example/dto.thrift +3 -0
- package/templates/idl-template/wiki/example/enum.thrift +1 -0
- package/templates/idl-template/wiki/example/gen-java.sh +5 -2
- package/templates/idl-template/wiki/example/maven_project/pom.xml +102 -83
- package/templates/idl-template/wiki/example/req.thrift +4 -0
- package/templates/idl-template/wiki/example/res.thrift +5 -0
- package/templates/idl-template/wiki/example/sdk-spec.yml +4 -3
- package/templates/idl-template/wiki/example/service.thrift +15 -0
- package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/enums/.gitkeep +0 -0
- package/templates/idl-template/wiki/.arcconfig +0 -3
- package/templates/idl-template/wiki/example/.arcconfig +0 -3
- package/templates/idl-template/wiki/example/hello.thrift +0 -29
- package/templates/idl-template/wiki/example/maven_project/src/main/java/com/xiaohongshu/sns/thrift/hello/HelloServiceAutoConfiguration.java +0 -46
- package/templates/idl-template/wiki/example/maven_project/src/main/java/com/xiaohongshu/sns/thrift/hello/HelloServiceProperties.java +0 -18
- package/templates/idl-template/wiki/example/maven_project/src/main/resources/META-INF/spring.factories +0 -3
- package/templates/idl-template/wiki/example/maven_project/src/test/java/com/xiaohongshu/sns/thrift/test/AutoConfigureTest.java +0 -53
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
package com.xiaohongshu.sns.demo.common.utils;
|
|
2
|
+
|
|
3
|
+
import com.xiaohongshu.sns.demo.common.enums.ErrorCodeEnum;
|
|
4
|
+
import com.xiaohongshu.sns.demo.common.exception.AppBizException;
|
|
5
|
+
import org.apache.commons.collections4.CollectionUtils;
|
|
6
|
+
import org.apache.commons.collections4.MapUtils;
|
|
7
|
+
import org.apache.commons.lang3.StringUtils;
|
|
8
|
+
|
|
9
|
+
import java.util.Collection;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
import java.util.function.Supplier;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @author chenhuanjie
|
|
16
|
+
*/
|
|
17
|
+
public final class AssertUtils {
|
|
18
|
+
private AssertUtils() {
|
|
19
|
+
// 私有构造函数,防止实例化
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 断言为true
|
|
24
|
+
*
|
|
25
|
+
* @param condition
|
|
26
|
+
* @param code
|
|
27
|
+
* @param supplier
|
|
28
|
+
*/
|
|
29
|
+
public static void isTrue(boolean condition, int code, Supplier<String> supplier) {
|
|
30
|
+
if (!condition) {
|
|
31
|
+
throw new AppBizException(code, supplier.get());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static void isTrue(boolean condition, ErrorCodeEnum error) {
|
|
36
|
+
if (!condition) {
|
|
37
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 断言为false
|
|
43
|
+
*
|
|
44
|
+
* @param condition
|
|
45
|
+
* @param code
|
|
46
|
+
* @param supplier
|
|
47
|
+
*/
|
|
48
|
+
public static void isFalse(boolean condition, int code, Supplier<String> supplier) {
|
|
49
|
+
if (condition) {
|
|
50
|
+
throw new AppBizException(code, supplier.get());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static void isFalse(boolean condition, ErrorCodeEnum error) {
|
|
55
|
+
if (condition) {
|
|
56
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 断言为字符串非空
|
|
62
|
+
*
|
|
63
|
+
* @param s
|
|
64
|
+
* @param code
|
|
65
|
+
* @param supplier
|
|
66
|
+
*/
|
|
67
|
+
public static void notBlank(String s, int code, Supplier<String> supplier) {
|
|
68
|
+
if (StringUtils.isBlank(s)) {
|
|
69
|
+
throw new AppBizException(code, supplier.get());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public static void notBlank(String s, ErrorCodeEnum error) {
|
|
74
|
+
if (StringUtils.isBlank(s)) {
|
|
75
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 断言为集合非空
|
|
82
|
+
*
|
|
83
|
+
* @param c
|
|
84
|
+
* @param code
|
|
85
|
+
* @param supplier
|
|
86
|
+
*/
|
|
87
|
+
public static void notEmpty(Collection c, int code, Supplier<String> supplier) {
|
|
88
|
+
if (CollectionUtils.isEmpty(c)) {
|
|
89
|
+
throw new AppBizException(code, supplier.get());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public static void notEmpty(Collection m, ErrorCodeEnum error) {
|
|
94
|
+
if (CollectionUtils.isEmpty(m)) {
|
|
95
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 断言map非空
|
|
101
|
+
*
|
|
102
|
+
* @param m
|
|
103
|
+
* @param code
|
|
104
|
+
* @param supplier
|
|
105
|
+
*/
|
|
106
|
+
public static void notEmpty(Map m, int code, Supplier<String> supplier) {
|
|
107
|
+
if (MapUtils.isEmpty(m)) {
|
|
108
|
+
throw new AppBizException(code, supplier.get());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public static void notEmpty(Map m, ErrorCodeEnum error) {
|
|
113
|
+
if (MapUtils.isEmpty(m)) {
|
|
114
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 断言为对象非空
|
|
121
|
+
*
|
|
122
|
+
* @param o
|
|
123
|
+
* @param code
|
|
124
|
+
* @param supplier
|
|
125
|
+
*/
|
|
126
|
+
public static void notNull(Object o, int code, Supplier<String> supplier) {
|
|
127
|
+
if (o == null) {
|
|
128
|
+
throw new AppBizException(code, supplier.get());
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public static void notNull(Object o, ErrorCodeEnum error) {
|
|
133
|
+
if (o == null) {
|
|
134
|
+
throw new AppBizException(error.getCode(), error.getMsg());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
package/template/sns-demo-common/src/main/java/com/xiaohongshu/sns/demo/common/utils/JsonHelper.java
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
package com.xiaohongshu.sns.demo.common.utils;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
4
|
+
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
5
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
6
|
+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
|
7
|
+
import com.fasterxml.jackson.databind.type.CollectionType;
|
|
8
|
+
import com.fasterxml.jackson.databind.type.MapType;
|
|
9
|
+
import lombok.extern.slf4j.Slf4j;
|
|
10
|
+
|
|
11
|
+
import java.util.List;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
import java.util.Set;
|
|
14
|
+
|
|
15
|
+
@Slf4j
|
|
16
|
+
public final class JsonHelper {
|
|
17
|
+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
18
|
+
private static final ObjectMapper SNAKE_CASE_OBJECT_MAPPER = new ObjectMapper();
|
|
19
|
+
|
|
20
|
+
static {
|
|
21
|
+
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
22
|
+
OBJECT_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
|
|
23
|
+
OBJECT_MAPPER.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
|
|
24
|
+
OBJECT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
25
|
+
|
|
26
|
+
SNAKE_CASE_OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
27
|
+
SNAKE_CASE_OBJECT_MAPPER.setPropertyNamingStrategy(new PropertyNamingStrategies.SnakeCaseStrategy());
|
|
28
|
+
SNAKE_CASE_OBJECT_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
|
|
29
|
+
SNAKE_CASE_OBJECT_MAPPER.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
|
|
30
|
+
SNAKE_CASE_OBJECT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 将对象转换为 JSON 字符串
|
|
36
|
+
*
|
|
37
|
+
* @param object
|
|
38
|
+
* @param snakeCase
|
|
39
|
+
* @param <T>
|
|
40
|
+
* @return
|
|
41
|
+
*/
|
|
42
|
+
public static <T> String toJson(T object, boolean snakeCase) {
|
|
43
|
+
try {
|
|
44
|
+
ObjectMapper mapper = snakeCase ? SNAKE_CASE_OBJECT_MAPPER : OBJECT_MAPPER;
|
|
45
|
+
return mapper.writeValueAsString(object);
|
|
46
|
+
} catch (Exception e) {
|
|
47
|
+
log.error("Error converting object to JSON: {}", e.getMessage(), e);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 将 JSON 字符串转换为对象
|
|
54
|
+
*
|
|
55
|
+
* @param json
|
|
56
|
+
* @param clazz
|
|
57
|
+
* @param snakeCase
|
|
58
|
+
* @param <T>
|
|
59
|
+
* @return
|
|
60
|
+
*/
|
|
61
|
+
public static <T> T fromJson(String json, Class<T> clazz, boolean snakeCase) {
|
|
62
|
+
try {
|
|
63
|
+
ObjectMapper mapper = snakeCase ? SNAKE_CASE_OBJECT_MAPPER : OBJECT_MAPPER;
|
|
64
|
+
return mapper.readValue(json, clazz);
|
|
65
|
+
} catch (Exception e) {
|
|
66
|
+
log.error("Error converting JSON to object: {}", e.getMessage(), e);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 将 JSON 字符串转换为 List
|
|
73
|
+
*
|
|
74
|
+
* @param json
|
|
75
|
+
* @param clazz
|
|
76
|
+
* @param <T>
|
|
77
|
+
* @return
|
|
78
|
+
*/
|
|
79
|
+
public static <T> List<T> fromJsonToList(String json, Class<T> clazz, boolean snakeCase) {
|
|
80
|
+
try {
|
|
81
|
+
ObjectMapper mapper = snakeCase ? SNAKE_CASE_OBJECT_MAPPER : OBJECT_MAPPER;
|
|
82
|
+
CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, clazz);
|
|
83
|
+
return mapper.readValue(json, type);
|
|
84
|
+
} catch (Exception e) {
|
|
85
|
+
log.error("Error converting JSON to List: {}", e.getMessage(), e);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 将 JSON 字符串转换为 List
|
|
92
|
+
*
|
|
93
|
+
* @param json
|
|
94
|
+
* @param clazz
|
|
95
|
+
* @param <T>
|
|
96
|
+
* @return
|
|
97
|
+
*/
|
|
98
|
+
public static <T> Set<T> fromJsonToSet(String json, Class<T> clazz, boolean snakeCase) {
|
|
99
|
+
try {
|
|
100
|
+
ObjectMapper mapper = snakeCase ? SNAKE_CASE_OBJECT_MAPPER : OBJECT_MAPPER;
|
|
101
|
+
CollectionType type = mapper.getTypeFactory().constructCollectionType(Set.class, clazz);
|
|
102
|
+
return mapper.readValue(json, type);
|
|
103
|
+
} catch (Exception e) {
|
|
104
|
+
log.error("Error converting JSON to Set: {}", e.getMessage(), e);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 将 JSON 字符串转换为 Map
|
|
111
|
+
*
|
|
112
|
+
* @param json
|
|
113
|
+
* @param keyClass
|
|
114
|
+
* @param valueClass
|
|
115
|
+
* @param <K>
|
|
116
|
+
* @param <V>
|
|
117
|
+
* @return
|
|
118
|
+
*/
|
|
119
|
+
public static <K, V> Map<K, V> fromJsonToMap(String json, Class<K> keyClass, Class<V> valueClass, boolean snakeCase) {
|
|
120
|
+
try {
|
|
121
|
+
ObjectMapper mapper = snakeCase ? SNAKE_CASE_OBJECT_MAPPER : OBJECT_MAPPER;
|
|
122
|
+
MapType type = mapper.getTypeFactory().constructMapType(Map.class, keyClass, valueClass);
|
|
123
|
+
return mapper.readValue(json, type);
|
|
124
|
+
} catch (Exception e) {
|
|
125
|
+
log.error("Error converting JSON to Map: {}", e.getMessage(), e);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
package com.xiaohongshu.sns.demo.common.utils;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
4
|
+
import com.xiaohongshu.infra.apm.utils.ContextHelper;
|
|
5
|
+
import com.xiaohongshu.infra.rpc.base.Context;
|
|
6
|
+
|
|
7
|
+
import com.xiaohongshu.sns.demo.common.constants.AppPlatform;
|
|
8
|
+
import lombok.Data;
|
|
9
|
+
import lombok.extern.slf4j.Slf4j;
|
|
10
|
+
import org.apache.commons.lang3.ObjectUtils;
|
|
11
|
+
import org.apache.commons.lang3.StringUtils;
|
|
12
|
+
import org.apache.commons.lang3.math.NumberUtils;
|
|
13
|
+
import org.springframework.stereotype.Component;
|
|
14
|
+
import org.springframework.util.CollectionUtils;
|
|
15
|
+
|
|
16
|
+
import java.net.URLDecoder;
|
|
17
|
+
import java.util.Collections;
|
|
18
|
+
import java.util.HashMap;
|
|
19
|
+
import java.util.Map;
|
|
20
|
+
import java.util.Optional;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 对中间件 ContextHelper 的封装,便于拿到当前的请求信息。
|
|
24
|
+
* 整合了 ContextUtils 现有功能及增强的上下文解析能力。
|
|
25
|
+
*
|
|
26
|
+
* @author RDMind
|
|
27
|
+
*/
|
|
28
|
+
@Component
|
|
29
|
+
@Slf4j
|
|
30
|
+
public class WrappedContextHelper {
|
|
31
|
+
|
|
32
|
+
public static final String APP_CONTEXT_PREFIX = "__app_context:";
|
|
33
|
+
public static final String HTTP_HEADER = "httpHeader";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取原始 Context
|
|
37
|
+
*/
|
|
38
|
+
public static Context get() {
|
|
39
|
+
return ContextHelper.getContext();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 获取当前用户 ID
|
|
44
|
+
*/
|
|
45
|
+
public static String getUserId() {
|
|
46
|
+
Context context = get();
|
|
47
|
+
if (context == null) {
|
|
48
|
+
return StringUtils.EMPTY;
|
|
49
|
+
}
|
|
50
|
+
String userId = context.getUserID();
|
|
51
|
+
if (StringUtils.isBlank(userId)) {
|
|
52
|
+
Map<String, String> baggageMap = context.getBaggage();
|
|
53
|
+
if (!CollectionUtils.isEmpty(baggageMap)) {
|
|
54
|
+
userId = baggageMap.get("viewerUserId");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return StringUtils.isBlank(userId) ? StringUtils.EMPTY : userId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 获取当前操作者邮箱
|
|
62
|
+
*/
|
|
63
|
+
public static String getUserEmail() {
|
|
64
|
+
Context context = get();
|
|
65
|
+
return context == null ? StringUtils.EMPTY : context.getBaggage().getOrDefault("__app_context:operatorEmail", StringUtils.EMPTY);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取当前操作者展示名称
|
|
70
|
+
*/
|
|
71
|
+
public static String getUserDisplayName() {
|
|
72
|
+
Context context = get();
|
|
73
|
+
return context == null ? StringUtils.EMPTY : context.getBaggage().getOrDefault("__app_context:displayName", StringUtils.EMPTY);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 获取当前操作者真实姓名
|
|
78
|
+
*/
|
|
79
|
+
public static String getUserRealName() {
|
|
80
|
+
Context context = get();
|
|
81
|
+
return context == null ? StringUtils.EMPTY : context.getBaggage().getOrDefault("__app_context:operatorName", StringUtils.EMPTY);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 获取当前用户IP
|
|
86
|
+
*/
|
|
87
|
+
public static String getUserIp() {
|
|
88
|
+
Context context = get();
|
|
89
|
+
if (context == null) {
|
|
90
|
+
return StringUtils.EMPTY;
|
|
91
|
+
}
|
|
92
|
+
return StringUtils.isBlank(context.getUserIP()) ? StringUtils.EMPTY : context.getUserIP();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 获取 requestId
|
|
97
|
+
*/
|
|
98
|
+
public static String getRequestId() {
|
|
99
|
+
Context context = get();
|
|
100
|
+
if (context == null || CollectionUtils.isEmpty(context.getBaggage())) {
|
|
101
|
+
return StringUtils.EMPTY;
|
|
102
|
+
}
|
|
103
|
+
return context.getBaggage().getOrDefault(APP_CONTEXT_PREFIX + "requestId", StringUtils.EMPTY);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 获取当前客户端平台
|
|
108
|
+
*/
|
|
109
|
+
public static String getPlatform() {
|
|
110
|
+
Context context = get();
|
|
111
|
+
if (context == null) {
|
|
112
|
+
return AppPlatform.UNKNOWN.value();
|
|
113
|
+
}
|
|
114
|
+
String platform = context.getAppPlatform();
|
|
115
|
+
return StringUtils.isBlank(platform) ? AppPlatform.UNKNOWN.value() : AppPlatform.findBy(platform).value();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 获取 networkType
|
|
120
|
+
*/
|
|
121
|
+
public static int getNetworkType() {
|
|
122
|
+
String cAppNetworkType = ContextHelper.getAppContext("c_app_network_type");
|
|
123
|
+
return NumberUtils.toInt(cAppNetworkType);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public static String getHttpHeaderStr() {
|
|
127
|
+
Context context = get();
|
|
128
|
+
if (context == null) {
|
|
129
|
+
return StringUtils.EMPTY;
|
|
130
|
+
}
|
|
131
|
+
Map<String, String> baggage = Optional.ofNullable(context.getBaggage()).orElse(Collections.emptyMap());
|
|
132
|
+
return baggage.getOrDefault(APP_CONTEXT_PREFIX + HTTP_HEADER, "");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private HttpHeader getParsedHttpHeader() {
|
|
136
|
+
Context context = get();
|
|
137
|
+
if (context != null && context.getBaggage().containsKey(APP_CONTEXT_PREFIX + HTTP_HEADER)) {
|
|
138
|
+
String headerJson = ContextHelper.getAppContext(HTTP_HEADER);
|
|
139
|
+
HttpHeader header = JsonHelper.fromJson(headerJson, HttpHeader.class, false);
|
|
140
|
+
return ObjectUtils.defaultIfNull(header, new HttpHeader());
|
|
141
|
+
}
|
|
142
|
+
return new HttpHeader();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 内部封装的 Http Header 对象 (使用 Jackson 注解)
|
|
147
|
+
*/
|
|
148
|
+
@Data
|
|
149
|
+
static class HttpHeader {
|
|
150
|
+
@JsonProperty("User-Agent")
|
|
151
|
+
private String userAgent;
|
|
152
|
+
@JsonProperty("xy-common-params")
|
|
153
|
+
private String commonParams;
|
|
154
|
+
@JsonProperty("X-Network-Source")
|
|
155
|
+
private String xNetworkSource;
|
|
156
|
+
@JsonProperty("Xy-Platform-Info")
|
|
157
|
+
private String platformInfo;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private Map<String, String> parseCommonParams() {
|
|
161
|
+
String paramStr = this.getParsedHttpHeader().getCommonParams();
|
|
162
|
+
if (StringUtils.isEmpty(paramStr)) {
|
|
163
|
+
return Collections.emptyMap();
|
|
164
|
+
}
|
|
165
|
+
Map<String, String> params = new HashMap<>();
|
|
166
|
+
for (String kv : paramStr.split("&")) {
|
|
167
|
+
String[] arr = kv.split("=");
|
|
168
|
+
if (arr.length == 2) {
|
|
169
|
+
try {
|
|
170
|
+
params.put(arr[0], URLDecoder.decode(arr[1], "UTF-8"));
|
|
171
|
+
} catch (Exception e) {
|
|
172
|
+
// ignore
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return params;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public String getDeviceId() {
|
|
180
|
+
return StringUtils.trimToEmpty(parseCommonParams().get("deviceId"));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -26,11 +26,6 @@
|
|
|
26
26
|
<groupId>com.xiaohongshu</groupId>
|
|
27
27
|
<artifactId>infra-framework-context</artifactId>
|
|
28
28
|
</dependency>
|
|
29
|
-
<dependency>
|
|
30
|
-
<groupId>org.springframework.boot</groupId>
|
|
31
|
-
<artifactId>spring-boot-starter-test</artifactId>
|
|
32
|
-
<scope>test</scope>
|
|
33
|
-
</dependency>
|
|
34
29
|
</dependencies>
|
|
35
30
|
|
|
36
31
|
</project>
|
|
@@ -47,11 +47,6 @@
|
|
|
47
47
|
<groupId>com.xiaohongshu</groupId>
|
|
48
48
|
<artifactId>infra-framework-rpc-core</artifactId>
|
|
49
49
|
</dependency>
|
|
50
|
-
<dependency>
|
|
51
|
-
<groupId>org.springframework.boot</groupId>
|
|
52
|
-
<artifactId>spring-boot-starter-test</artifactId>
|
|
53
|
-
<scope>test</scope>
|
|
54
|
-
</dependency>
|
|
55
50
|
</dependencies>
|
|
56
51
|
|
|
57
52
|
</project>
|
|
@@ -24,11 +24,6 @@
|
|
|
24
24
|
<groupId>com.xiaohongshu.xray</groupId>
|
|
25
25
|
<artifactId>xray-logging</artifactId>
|
|
26
26
|
</dependency>
|
|
27
|
-
<dependency>
|
|
28
|
-
<groupId>org.springframework.boot</groupId>
|
|
29
|
-
<artifactId>spring-boot-starter-test</artifactId>
|
|
30
|
-
<scope>test</scope>
|
|
31
|
-
</dependency>
|
|
32
27
|
</dependencies>
|
|
33
28
|
|
|
34
29
|
<build>
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<configuration>
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<property name="LOG_LEVEL" value="INFO"/>
|
|
4
|
+
<include resource="logback-xray-base.xml"/>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<logger name="events" level="INFO"></logger>
|
|
21
|
-
|
|
22
|
-
</configuration>
|
|
6
|
+
<logger name="org.apache.ibatis" level="INFO"></logger>
|
|
7
|
+
<logger name="org.apache.catalina" level="ERROR"></logger>
|
|
8
|
+
<logger name="org.apache.zookeeper" level="INFO"></logger>
|
|
9
|
+
<logger name="org.springframework" level="INFO"></logger>
|
|
10
|
+
<logger name="com.xiaohongshu.infra" level="ERROR"></logger>
|
|
11
|
+
<logger name="com.xiaohongshu.racing" level="WARN"></logger>
|
|
12
|
+
<logger name="com.dianping.cat" level="INFO"></logger>
|
|
13
|
+
<logger name="red.midware.shaded" level="INFO"></logger>
|
|
14
|
+
<logger name="com.xiaohongshu.infra.xds.cds.CDSSharedStubWrapper" level="ERROR"></logger>
|
|
15
|
+
<logger name="events" level="INFO"></logger>
|
|
16
|
+
<logger name="com.zaxxer.hikari.HikariConfig" level="WARN"></logger>
|
|
17
|
+
<logger name="com.zaxxer.hikari.HikariDataSource" level="WARN"></logger>
|
|
18
|
+
<logger name="com.xiaohongshu.infra.rpc.core.registry.eds.MultiRegionsEdsThriftAddressSubscriberProvider" level="off"/>
|
|
19
|
+
</configuration>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AnalysisProjectProfileManager">
|
|
4
|
+
<option name="PROJECT_PROFILE" />
|
|
5
|
+
<option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
|
|
6
|
+
<list size="0" />
|
|
7
|
+
</component>
|
|
8
|
+
<component name="ProjectRootManager">
|
|
9
|
+
<output url="file://$PROJECT_DIR$/out" />
|
|
10
|
+
</component>
|
|
11
|
+
<component name="SuppressionsComponent">
|
|
12
|
+
<option name="suppComments" value="[]" />
|
|
13
|
+
</component>
|
|
14
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
|
@@ -49,8 +49,6 @@ thrift idl开发参考[Thrift IDL开发规范](./README.md)
|
|
|
49
49
|
|
|
50
50
|
Java sdk会以`maven_project`目录作为打包的基础目录,因此可以在目录中添加代码来定制sdk的功能。
|
|
51
51
|
|
|
52
|
-
例如,使用[SpringBoot AutoConfiguration](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html)为sdk开发自动配置功能,参考[例子](example)。
|
|
53
|
-
|
|
54
52
|
## 常见问题
|
|
55
53
|
|
|
56
54
|
1. Invalid remote: origin
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
+
image: docker-reg.devops.xiaohongshu.com/shequ/sns-sdk-ci:latest
|
|
2
|
+
|
|
1
3
|
stages:
|
|
2
4
|
- build
|
|
3
|
-
# 根据项目类型保留需要build的stage 并删掉其他stage
|
|
4
|
-
build:java:
|
|
5
|
-
stage: build
|
|
6
|
-
image: docker-reg.devops.xiaohongshu.com/shequ/sns-sdk-ci:latest
|
|
7
|
-
script:
|
|
8
|
-
- skr -p ${CI_PROJECT_NAME} -c ${CI_COMMIT_REF_NAME}
|
|
9
|
-
only:
|
|
10
|
-
- branches
|
|
11
|
-
- /^\d+\.\d+\.\d+$/
|
|
12
5
|
|
|
13
|
-
build:
|
|
6
|
+
build:java:
|
|
14
7
|
stage: build
|
|
15
|
-
image: docker-reg.devops.xiaohongshu.com/shequ/sns-gosdk-ci:latest
|
|
16
8
|
script:
|
|
17
9
|
- skr -p ${CI_PROJECT_NAME} -c ${CI_COMMIT_REF_NAME}
|
|
18
10
|
only:
|
|
19
11
|
- branches
|
|
20
12
|
- /^\d+\.\d+\.\d+$/
|
|
21
|
-
|
|
22
|
-
build:node:
|
|
23
|
-
stage: build
|
|
24
|
-
image: docker-reg.devops.xiaohongshu.com/fe/ts-generator:latest
|
|
25
|
-
script:
|
|
26
|
-
- DEBUG=common-bin tsGen build --branch ${CI_COMMIT_REF_NAME} --userEmail ${GITLAB_USER_EMAIL} --ciId ${CI_COMMIT_SHA:0:8} --pId ${CI_PROJECT_ID}
|