From f5b3fedee357dde751cc60ebfc101699ea95556d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 10 Jul 2023 14:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=B8=80=E4=BA=9B=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E6=93=8D=E4=BD=9C=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- echo_service_path.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 echo_service_path.sh diff --git a/.gitignore b/.gitignore index 898b3d80..a78412af 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,4 @@ __debug_bin .vscode screenlog.* -allapis.txt \ No newline at end of file +*.txt \ No newline at end of file diff --git a/echo_service_path.sh b/echo_service_path.sh new file mode 100644 index 00000000..0d510f45 --- /dev/null +++ b/echo_service_path.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# 初始化输出文件 +output_file="server.txt" +echo "" > $output_file + +# 遍历所有 *.api 文件 +for api_file in server_api/*.api; do + # 提取服务名称 + service_name=$(grep -oP 'service\s+\K\w+' $api_file) + + # 提取所有以 get 或 post 开头的行,并使用 awk 获取路径 + # 将结果保存在一个名为 paths 的数组中 + paths=($(grep -E '^\s+(get|post)' $api_file | grep -oP '/\K[^/]*(?=/)' | sort | uniq | awk '{print "/"$1}' | tr '\n' ' ')) + + # 检查 $paths 是否为空,仅在非空时输出结果 + if [[ ! -z "${paths}" ]]; then + # 将服务名称和路径组合成所需的格式,并将结果追加到输出文件 + echo "$service_name [${paths[*]}]" >> $output_file + fi +done \ No newline at end of file