Skip to content

Commit 494ea0d

Browse files
authored
Merge pull request #2 from wenlng/dev-v1.0.1
update config manager setup
2 parents 5a444d7 + 035dba4 commit 494ea0d

File tree

10 files changed

+216
-187
lines changed

10 files changed

+216
-187
lines changed

.github/.github/docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ jobs:
6868
platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64
6969
push: true
7070
tags: |
71-
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:0.0.1
72-
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:amd64-0.0.1
73-
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:arm64-0.0.1
74-
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:armv7-0.0.1
71+
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:1.0.1
72+
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:amd64-1.0.1
73+
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:arm64-1.0.1
74+
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:armv7-1.0.1
7575
${{ secrets.DOCKER_USERNAME }}/go-captcha-service:${{ github.ref_name }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Variables
44
BINARY_NAME=go-captcha-service
5-
VERSION?=0.0.1
5+
VERSION?=1.0.1
66
BUILD_DIR=build
77
PLATFORMS=darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/arm/v7 windows/amd64
88
DOCKER_IMAGE?=wenlng/go-captcha-service

README.md

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Basic Configuration:
531531
* `HTTP_PORT`: HTTP service listening port.
532532
* `GRPC_PORT`: gRPC service listening port.
533533
* `API_KEYS`: API keys for authentication or authorization.
534+
* `LOG_LEVEL`: Log level.
534535

535536
Cache Configuration:
536537
* `CACHE_TYPE`: Cache type (e.g., `redis`, `memcached`, `memory`, `etcd`).
@@ -883,7 +884,7 @@ The service uses two configuration files: `config.json` for service runtime para
883884
884885
- `config_version` (integer): Configuration file version for distributed dynamic configuration management, default `1`.
885886
886-
##### resources Field
887+
> resources
887888
888889
- `version` (string): Resource configuration version to control CAPTCHA instance recreation, default `0.0.1`.
889890
- `char.languages.chinese` (string array): Chinese character set for click CAPTCHA text, default empty (uses built-in resources).
@@ -914,50 +915,50 @@ The service uses two configuration files: `config.json` for service runtime para
914915
915916
<br/>
916917
917-
##### builder Field
918+
> builder
918919
919920
Defines CAPTCHA generation styles, including configurations for click, shape click, slide, drag, and rotate CAPTCHAs.
920921
921-
###### click_config_maps
922+
#### click_config_maps
922923
923924
Defines text click CAPTCHA configurations, supporting Chinese and English with light and dark themes. The key is the ID passed in the CAPTCHA API request, e.g., `api/v1/public/get-data?id=click-default-ch`.
924925
925926
- `click-default-ch` (object): Default Chinese theme configuration.
926-
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
927-
$
928-
- `language` (string): Language, matches defined `char.languages`, e.g., `chinese` for Chinese.
929-
- `master` (object): Main CAPTCHA image configuration.
930-
- `image_size.width` (integer): Main image width, default `300`.
931-
- `image_size.height` (integer): Main image height, default `200`.
932-
- `range_length.min` (integer): Minimum number of CAPTCHA points, default `6`.
933-
- `range_length.max` (integer): Maximum number of CAPTCHA points, default `7`.
934-
- `range_angles` (object array): Text rotation angle ranges (degrees).
935-
- Example: `{"min": 20, "max": 35}` for 20°-35°.
936-
- `range_size.min` (integer): Minimum text size (pixels), default `26`.
937-
- `range_size.max` (integer): Maximum text size, default `32`.
938-
- `range_colors` (string array): Text color list (hexadecimal).
939-
- Example: `"#fde98e"`.
940-
- `display_shadow` (boolean): Display text shadow, default `true`.
941-
- `shadow_color` (string): Shadow color, default `#101010`.
942-
- `shadow_point.x` (integer): Shadow offset X coordinate, default `-1` (auto-calculated).
943-
- `shadow_point.y` (integer): Shadow offset Y coordinate, default `-1`.
944-
- `image_alpha` (float): Image opacity (0-1), default `1`.
945-
- `use_shape_original_color` (boolean): Use original shape color, default `true`.
946-
- `thumb` (object): Thumbnail (prompt text) configuration.
947-
- `image_size.width` (integer): Thumbnail width, default `150`.
948-
- `image_size.height` (integer): Thumbnail height, default `40`.
949-
- `range_verify_length.min` (integer): Minimum verification points, default `2`.
950-
- `range_verify_length.max` (integer): Maximum verification points, default `4`.
951-
- `disabled_range_verify_length` (boolean): Disable verification point limit, default `false`.
952-
- `range_text_size.min` (integer): Minimum text size, default `22`.
953-
- `range_text_size.max` (integer): Maximum text size, default `28`.
954-
- `range_text_colors` (string array): Text color list.
955-
- `range_background_colors` (string array): Background color list.
956-
- `is_non_deform_ability` (boolean): Disable deformation effect, default `false`.
957-
- `background_distort` (integer): Background distortion level, default `4`.
958-
- `background_distort_alpha` (float): Background distortion opacity, default `1`.
959-
- `background_circles_num` (integer): Number of background circle interference points, default `24`.
960-
- `background_slim_line_num` (integer): Number of background slim line interferences, default `2`.
927+
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
928+
$
929+
- `language` (string): Language, matches defined `char.languages`, e.g., `chinese` for Chinese.
930+
- `master` (object): Main CAPTCHA image configuration.
931+
- `image_size.width` (integer): Main image width, default `300`.
932+
- `image_size.height` (integer): Main image height, default `200`.
933+
- `range_length.min` (integer): Minimum number of CAPTCHA points, default `6`.
934+
- `range_length.max` (integer): Maximum number of CAPTCHA points, default `7`.
935+
- `range_angles` (object array): Text rotation angle ranges (degrees).
936+
- Example: `{"min": 20, "max": 35}` for 20°-35°.
937+
- `range_size.min` (integer): Minimum text size (pixels), default `26`.
938+
- `range_size.max` (integer): Maximum text size, default `32`.
939+
- `range_colors` (string array): Text color list (hexadecimal).
940+
- Example: `"#fde98e"`.
941+
- `display_shadow` (boolean): Display text shadow, default `true`.
942+
- `shadow_color` (string): Shadow color, default `#101010`.
943+
- `shadow_point.x` (integer): Shadow offset X coordinate, default `-1` (auto-calculated).
944+
- `shadow_point.y` (integer): Shadow offset Y coordinate, default `-1`.
945+
- `image_alpha` (float): Image opacity (0-1), default `1`.
946+
- `use_shape_original_color` (boolean): Use original shape color, default `true`.
947+
- `thumb` (object): Thumbnail (prompt text) configuration.
948+
- `image_size.width` (integer): Thumbnail width, default `150`.
949+
- `image_size.height` (integer): Thumbnail height, default `40`.
950+
- `range_verify_length.min` (integer): Minimum verification points, default `2`.
951+
- `range_verify_length.max` (integer): Maximum verification points, default `4`.
952+
- `disabled_range_verify_length` (boolean): Disable verification point limit, default `false`.
953+
- `range_text_size.min` (integer): Minimum text size, default `22`.
954+
- `range_text_size.max` (integer): Maximum text size, default `28`.
955+
- `range_text_colors` (string array): Text color list.
956+
- `range_background_colors` (string array): Background color list.
957+
- `is_non_deform_ability` (boolean): Disable deformation effect, default `false`.
958+
- `background_distort` (integer): Background distortion level, default `4`.
959+
- `background_distort_alpha` (float): Background distortion opacity, default `1`.
960+
- `background_circles_num` (integer): Number of background circle interference points, default `24`.
961+
- `background_slim_line_num` (integer): Number of background slim line interferences, default `2`.
961962
962963
- `click-dark-ch` (object): Chinese dark theme configuration, similar to `click-default-ch`, but `thumb.range_text_colors` uses brighter colors for dark backgrounds.
963964
@@ -967,69 +968,69 @@ Defines text click CAPTCHA configurations, supporting Chinese and English with l
967968
968969
<br/>
969970
970-
###### click_shape_config_maps
971+
#### click_shape_config_maps
971972
972973
Defines shape click CAPTCHA configurations.
973974
974975
- `click-shape-default` (object): Default shape click configuration, similar to `click_config_maps` `master` and `thumb` but for shape images instead of text.
975976
976977
<br/>
977978
978-
###### slide_config_maps
979+
#### slide_config_maps
979980
980981
Defines slide CAPTCHA configurations.
981982
982983
- `slide-default` (object):
983-
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
984-
- `master` (object): Main CAPTCHA image configuration.
985-
- `image_size.width` (integer): Main image width, default `300`.
986-
- `image_size.height` (integer): Main image height, default `200`.
987-
- `image_alpha` (float): Image opacity (0-1), default `1`.
988-
- `thumb` (object): Slider configuration.
989-
- `range_graph_size.min` (integer): Minimum slider graphic size (pixels), default `60`.
990-
- `range_graph_size.max` (integer): Maximum slider graphic size, default `70`.
991-
- `range_graph_angles` (object array): Slider graphic rotation angle ranges (degrees).
992-
- Example: `{"min": 20, "max": 35}`.
993-
- `generate_graph_number` (integer): Number of slider graphics to generate, default `1`.
994-
- `enable_graph_vertical_random` (boolean): Enable vertical random offset, default `false`.
995-
- `range_dead_zone_directions` (string array): Slider dead zone directions, default `["left", "right"]`.
984+
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
985+
- `master` (object): Main CAPTCHA image configuration.
986+
- `image_size.width` (integer): Main image width, default `300`.
987+
- `image_size.height` (integer): Main image height, default `200`.
988+
- `image_alpha` (float): Image opacity (0-1), default `1`.
989+
- `thumb` (object): Slider configuration.
990+
- `range_graph_size.min` (integer): Minimum slider graphic size (pixels), default `60`.
991+
- `range_graph_size.max` (integer): Maximum slider graphic size, default `70`.
992+
- `range_graph_angles` (object array): Slider graphic rotation angle ranges (degrees).
993+
- Example: `{"min": 20, "max": 35}`.
994+
- `generate_graph_number` (integer): Number of slider graphics to generate, default `1`.
995+
- `enable_graph_vertical_random` (boolean): Enable vertical random offset, default `false`.
996+
- `range_dead_zone_directions` (string array): Slider dead zone directions, default `["left", "right"]`.
996997
997998
<br/>
998999
999-
###### drag_config_maps
1000+
#### drag_config_maps
10001001
10011002
Defines drag CAPTCHA configurations.
10021003
10031004
- `drag-default` (object):
1004-
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
1005-
- `master` (object): Main CAPTCHA image configuration.
1006-
- `image_size.width` (integer): Main image width, default `300`.
1007-
- `image_size.height` (integer): Main image height, default `200`.
1008-
- `image_alpha` (float): Image opacity (0-1), default `1`.
1009-
- `thumb` (object): Drag graphic configuration.
1010-
- `range_graph_size.min` (integer): Minimum drag graphic size (pixels), default `60`.
1011-
- `range_graph_size.max` (integer): Maximum drag graphic size, default `70`.
1012-
- `range_graph_angles` (object array): Drag graphic rotation angle ranges (degrees).
1013-
- Example: `{"min": 0, "max": 0}` for no rotation.
1014-
- `generate_graph_number` (integer): Number of drag graphics to generate, default `2`.
1015-
- `enable_graph_vertical_random` (boolean): Enable vertical random offset, default `true`.
1016-
- `range_dead_zone_directions` (string array): Drag dead zone directions, default `["left", "right", "top", "bottom"]`.
1005+
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
1006+
- `master` (object): Main CAPTCHA image configuration.
1007+
- `image_size.width` (integer): Main image width, default `300`.
1008+
- `image_size.height` (integer): Main image height, default `200`.
1009+
- `image_alpha` (float): Image opacity (0-1), default `1`.
1010+
- `thumb` (object): Drag graphic configuration.
1011+
- `range_graph_size.min` (integer): Minimum drag graphic size (pixels), default `60`.
1012+
- `range_graph_size.max` (integer): Maximum drag graphic size, default `70`.
1013+
- `range_graph_angles` (object array): Drag graphic rotation angle ranges (degrees).
1014+
- Example: `{"min": 0, "max": 0}` for no rotation.
1015+
- `generate_graph_number` (integer): Number of drag graphics to generate, default `2`.
1016+
- `enable_graph_vertical_random` (boolean): Enable vertical random offset, default `true`.
1017+
- `range_dead_zone_directions` (string array): Drag dead zone directions, default `["left", "right", "top", "bottom"]`.
10171018
10181019
<br/>
10191020
1020-
###### rotate_config_maps
1021+
#### rotate_config_maps
10211022
10221023
Defines rotate CAPTCHA configurations.
10231024
10241025
- `rotate-default` (object):
1025-
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
1026-
- `master` (object): Main CAPTCHA image configuration.
1027-
- `image_square_size` (integer): Main image square side length (pixels), default `220`.
1028-
- `thumb` (object): Rotate graphic configuration.
1029-
- `range_angles` (object array): Rotation angle ranges (degrees).
1030-
- Example: `{"min": 30, "max": 330}` for 30°-330°.
1031-
- `range_image_square_sizes` (integer array): Rotate image square side length list, default `[140, 150, 160, 170]`.
1032-
- `image_alpha` (float): Image opacity (0-1), default `1`.
1026+
- `version` (string): Configuration version to control CAPTCHA instance recreation, default `0.0.1`.
1027+
- `master` (object): Main CAPTCHA image configuration.
1028+
- `image_square_size` (integer): Main image square side length (pixels), default `220`.
1029+
- `thumb` (object): Rotate graphic configuration.
1030+
- `range_angles` (object array): Rotation angle ranges (degrees).
1031+
- Example: `{"min": 30, "max": 330}` for 30°-330°.
1032+
- `range_image_square_sizes` (integer array): Rotate image square side length list, default `[140, 150, 160, 170]`.
1033+
- `image_alpha` (float): Image opacity (0-1), default `1`.
10331034
10341035
<br/>
10351036
<br/>
@@ -1040,6 +1041,8 @@ Hot reloading for `gocaptcha.json` is determined by the `version` field of each
10401041
Hot-reloadable fields in `config.json` include:
10411042
* `cache_type`
10421043
* `cache_addrs`
1044+
* `cache_username`
1045+
* `cache_password`
10431046
* `cache_ttl`
10441047
* `cache_key_prefix`
10451048
* `api_keys`
@@ -1053,7 +1056,7 @@ Hot-reloadable fields in `config.json` include:
10531056
- Verification Logic: Test handling of different inputs.
10541057
- Service Discovery: Simulate Etcd/Nacos/Zookeeper/Consul.
10551058
- Caching: Test Memory/Redis/Etcd/Memcache.
1056-
- Dynamic Configuration: Test Nacos configuration updates.
1059+
- Dynamic Configuration: Test Etcd|Nacos|Zookeeper|Consul configuration updates.
10571060
10581061
<br/>
10591062
<br/>

README_zh.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
</div>
2525

2626
<br/>
27-
<hr/>
2827
<br/>
2928

3029
## 周边项目
@@ -56,7 +55,7 @@
5655
- **分布式缓存**:支持 Memory、Redis、Etcd 和 Memcache,优化验证码数据存储。
5756
- **分布式动态配置**:通过 Etcd、Nacos、Zookeeper 或 Consul 实时更新配置。
5857
- **高可配置性**:支持自定义文本、字体、图片资源、验证码尺寸、生成规则等配置。
59-
- **高性能**:基于 Go 的并发模型,适合高流量场景,同时结合分布式架构部署,确保服务处于高可用、高性能、高响应的状态
58+
- **高性能**:基于 Go 的并发模型,适合高流量场景,同时结合分布式架构部署,确保服务处于高可用、高性能的状态
6059
- **跨平台**:支持二进制、命令行、PM2、Docker 和 Docker Compose 部署。
6160

6261
<br/>
@@ -119,13 +118,15 @@ PM2 是 Node.js 进程守护管理工具,可用于管理 Go 服务,提供进
119118
SERVICE_NAME: 'go-captcha-service',
120119
CACHE_TYPE: 'redis',
121120
CACHE_ADDRS: 'localhost:6379',
121+
LOG_LEVEL: 'error',
122122
},
123123
env_production: {
124124
CONFIG: 'config.json',
125125
GO_CAPTCHA_CONFIG: 'gocaptcha.json',
126126
SERVICE_NAME: 'go-captcha-service',
127127
CACHE_TYPE: 'redis',
128128
CACHE_ADDRS: 'localhost:6379',
129+
LOG_LEVEL: 'error',
129130
}
130131
}]
131132
};
@@ -534,6 +535,7 @@ server {
534535
* HTTP_PORT: HTTP 服务监听端口。
535536
* GRPC_PORT: gRPC 服务监听端口。
536537
* API_KEYS: API 密钥,用于认证或授权。
538+
* `LOG_LEVEL`: Log level.
537539

538540
缓存配置:
539541
* CACHE_TYPE: 缓存类型(如 redis、memcached、memory、etcd)。
@@ -881,11 +883,11 @@ server {
881883
```
882884
<br/>
883885
884-
##### 顶级字段
886+
> 顶级字段
885887
886888
- `config_version` (整数):配置文件版本号,用于分布动态配置管理,默认 `1`
887889
888-
##### resources 字段
890+
> resources 字段
889891
890892
- `version` (字符串):资源配置版本号,用于控制重新创建新的验证码实例,默认 `0.0.1`
891893
- `char.languages.chinese` (字符串数组):中文字符集,用于点击验证码的文本内容,默认空(默认取内置的资源)。
@@ -916,12 +918,12 @@ server {
916918
917919
<br/>
918920
919-
##### builder 字段
921+
#### builder 字段
920922
921923
定义验证码生成样式,包含点击、形状点击、滑动、拖拽和旋转验证码的配置。
922924
923925
924-
###### click_config_maps
926+
#### click_config_maps
925927
926928
定义文本点击验证码的配置,支持中英文和明暗主题,key为ID,在请求验证码API时传递,例如:`api/v1/public/get-data?id=click-default-ch`
927929
@@ -969,15 +971,15 @@ server {
969971
970972
<br/>
971973
972-
###### click_shape_config_maps
974+
#### click_shape_config_maps
973975
974976
定义形状点击验证码的配置。
975977
976978
- `click-shape-default` (对象):默认形状点击配置,参数与 `click_config_maps``master``thumb` 类似,但针对形状图片而非文本。
977979
978980
<br/>
979981
980-
###### slide_config_maps
982+
#### slide_config_maps
981983
982984
定义滑动验证码配置。
983985
@@ -998,7 +1000,7 @@ server {
9981000
9991001
<br/>
10001002
1001-
###### drag_config_maps
1003+
#### drag_config_maps
10021004
10031005
定义拖拽验证码配置。
10041006
@@ -1019,7 +1021,7 @@ server {
10191021
10201022
<br/>
10211023
1022-
###### rotate_config_maps
1024+
#### rotate_config_maps
10231025
10241026
定义旋转验证码配置。
10251027
@@ -1043,14 +1045,16 @@ server {
10431045
`gocaptcha.json` 热重载以每个配置项的 version 字段决定是否生效。
10441046
10451047
`config.json` 热重载有效的字段如下:
1046-
* cache_type
1047-
* cahce_addrs
1048-
* cache_ttl
1049-
* cache_key_prefix
1050-
* api_keys
1051-
* log_level
1052-
* rate_limit_qps
1053-
* rate_limit_burst
1048+
* `cache_type`
1049+
* `cache_addrs`
1050+
* `cache_username`
1051+
* `cache_password`
1052+
* `cache_ttl`
1053+
* `cache_key_prefix`
1054+
* `api_keys`
1055+
* `log_level`
1056+
* `rate_limit_qps`
1057+
* `rate_limit_burst`
10541058
10551059
10561060
### 测试:
@@ -1059,7 +1063,7 @@ server {
10591063
- 验证逻辑:测试不同输入的处理。
10601064
- 服务发现:模拟 Etcd/Nacos/Zookeeper/Consul。
10611065
- 缓存:测试 Memory/Redis/Etcd/Memcache。
1062-
- 动态配置:测试 Nacos 配置更新。
1066+
- 动态配置:测试 Etcd|Nacos|Zookeeper|Consul 配置更新。
10631067
10641068
10651069
<br/>

0 commit comments

Comments
 (0)