最新的api路径

This commit is contained in:
eson 2023-07-12 14:11:04 +08:00
parent 3c9fb417aa
commit 4dbb77b306
29 changed files with 221 additions and 162 deletions

View File

@ -1,32 +0,0 @@
#!/bin/bash
# 定义输出文件名
output_file="allapis.txt"
# 清空输出文件(如果存在)
> "$output_file"
# 定义要处理的 .api 文件列表
api_files=("server_api/basic.api" "server_api/home-user-auth.api")
# 遍历 server_api 目录下的指定 .api 文件
# for api_file in server_api/*.api; do
for api_file in "${api_files[@]}"; do
# 获取文件名(不包含扩展名)
filename=$(basename "$api_file" .api)
# 将文件名添加到输出文件
echo "// ${filename}.api" >> "$output_file"
# 删除指定内容并将过滤后的 .api 文件内容追加到输出文件
sed -e '/syntax = "v1"/d' \
-e '/info (/,/)/d' \
-e '/title: \/\/ TODO: add title/d' \
-e '/desc: \/\/ TODO: add description/d' \
-e '/author: ""/d' \
-e '/email: ""/d' "$api_file" >> "$output_file"
# 在不同 .api 文件内容之间添加一个空行
echo "" >> "$output_file"
done

View File

@ -1,21 +0,0 @@
#!/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

View File

@ -1,15 +1,36 @@
#! /bin/bash
name=${1%%\\*}
#!/bin/bash
name=${1%%\\*}
options=("backend" "product-template" "product-model")
for option in "${options[@]}"; do
if [ "$name" = "$option" ]; then
echo "不能在"$name"里使用"
excluded_names=("backend" "product-template" "product-model" "basic")
for excluded_name in "${excluded_names[@]}"; do
if [ "$name" = "$excluded_name" ]; then
echo "不能在$name里使用"
exit
fi
fi
done
echo $name
goctl api go -api server_api/$name.api -dir server/$name --home ./goctl_template/
# ctxName=server/$name/internal/svc/servicecontext.go
# gofmt -w $ctxName
# List of API filenames without the '.api' extension
# api_names=("backend" "canteen" "home-user-auth" "map-library" "product" "product-template" "shopping-cart-confirmation" "webset" "data-transfer" "inventory" "orders" "product-model" "render" "upload")
# # Iterate over API filenames and generate Go code, excluding certain names
# for api_name in "${api_names[@]}"; do
# skip=false
# for excluded_name in "${excluded_names[@]}"; do
# if [ "$api_name" = "$excluded_name" ]; then
# skip=true
# break
# fi
# done
# if [ "$skip" = true ]; then
# continue
# fi
# echo "Generating Go code for $api_name"
# goctl api go -api server_api/"$api_name".api -dir server/"$api_name" --home ./goctl_template/
# done

View File

@ -113,8 +113,9 @@ func extractPrefixRouteValues(content string) map[string]bool {
for _, line := range lines {
if strings.Contains(line, "Path:") {
path := strings.TrimSpace(strings.TrimPrefix(line, "Path:"))
path1 := strings.Split(strings.Trim(path, `"`), "/")[1]
path1 = "/" + path1
paths := strings.Split(strings.Trim(path, `"`), "/")
path1 := "/" + paths[1] + "/" + paths[2]
if _, ok := prefixPath[path1]; !ok {
prefixPath[path1] = true
}

View File

@ -9,6 +9,7 @@ import (
"net/http/httputil"
"net/url"
"strings"
"sync"
"time"
)
@ -28,7 +29,16 @@ func SetCors(w http.ResponseWriter, r *http.Request) {
}
}
var pathdict sync.Map = sync.Map{}
func main() {
pathdict.Store("/css", true)
pathdict.Store("/fonts", true)
pathdict.Store("/img", true)
pathdict.Store("/js", true)
pathdict.Store("/svg", true)
pathdict.Store("/favicon.ico", true)
rootDir := "../server" // Change this to your root directory
vueBuild := "/home/eson/workspace/fusenpack-vue-created"
apiURL, err := url.Parse("http://localhost:9900")
@ -59,27 +69,24 @@ func main() {
fs := http.FileServer(http.Dir(vueBuild))
indexHtmlPath := vueBuild + "/index.html"
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var prefix string
idx := strings.Index(r.URL.Path[1:], "/")
if idx == -1 {
prefix = r.URL.Path
} else {
prefix = r.URL.Path[:idx]
}
// log.Println(r.URL.Path, prefix)
if _, ok := allRoutes[prefix]; ok {
if strings.HasPrefix(r.URL.Path, "/api") {
proxy := httputil.NewSingleHostReverseProxy(apiURL)
proxy.ServeHTTP(w, r)
} else {
// fs.ServeHTTP(w, r)
if strings.HasPrefix(prefix, "/type") {
http.ServeFile(w, r, indexHtmlPath)
} else if strings.HasPrefix(prefix, "/dt-") {
http.ServeFile(w, r, indexHtmlPath)
idx := strings.Index(r.URL.Path[1:], "/")
var prefix string
if idx != -1 {
prefix = r.URL.Path[:idx+1]
} else {
fs.ServeHTTP(w, r)
prefix = r.URL.Path
}
if _, ok := pathdict.Load(prefix); ok {
fs.ServeHTTP(w, r)
} else {
http.ServeFile(w, r, indexHtmlPath)
}
}
}))

View File

@ -14,12 +14,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/quotation/detail",
Path: "/api/quotation/detail",
Handler: QuotationDetailHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/backend-user/login",
Path: "/api/backend-user/login",
Handler: BackendUserLoginHandler(serverCtx),
},
},

View File

@ -33,6 +33,20 @@ type Auth struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,12 +14,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/canteen-type/detail",
Path: "/api/canteen-type/detail",
Handler: GetCanteenDetailHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/canteen-type/save",
Path: "/api/canteen-type/save",
Handler: SaveCanteenTypeProductHandler(serverCtx),
},
},

View File

@ -35,26 +35,35 @@ type SaveCanteenProduct struct {
SId string `json:"s_id"`
}
type Request struct {
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}
type ResponseJwt struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
}
type Auth struct {
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,12 +14,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/standard-logo/list",
Path: "/api/standard-logo/list",
Handler: GetStandardLogoListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/qrcode-set/list",
Path: "/api/qrcode-set/list",
Handler: GetQrCodeSetListHandler(serverCtx),
},
},

View File

@ -14,57 +14,57 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/user/login",
Path: "/api/user/login",
Handler: UserLoginHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/accept-cookie",
Path: "/api/user/accept-cookie",
Handler: AcceptCookieHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/user/fonts",
Path: "/api/user/fonts",
Handler: UserFontsHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/user/get-type",
Path: "/api/user/get-type",
Handler: UserGetTypeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/basic-info",
Path: "/api/user/basic-info",
Handler: UserSaveBasicInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/status-config",
Path: "/api/user/status-config",
Handler: UserStatusConfigHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/user/basic-info",
Path: "/api/user/basic-info",
Handler: UserBasicInfoHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/user/address-list",
Path: "/api/user/address-list",
Handler: UserAddressListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/add-address",
Path: "/api/user/add-address",
Handler: UserAddAddressHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/contact-service",
Path: "/api/user/contact-service",
Handler: UserContactServiceHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/order-delete",
Path: "/api/user/order-delete",
Handler: UserOderDeleteHandler(serverCtx),
},
},

View File

@ -14,22 +14,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/inventory/take",
Path: "/api/inventory/take",
Handler: TakeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inventory/list",
Path: "/api/inventory/list",
Handler: GetCloudListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/inventory/supplement",
Path: "/api/inventory/supplement",
Handler: SupplementHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inventory/pick-up-list",
Path: "/api/inventory/pick-up-list",
Handler: GetPickupListHandler(serverCtx),
},
},

View File

@ -125,6 +125,13 @@ type Auth struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`

View File

@ -14,12 +14,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/map-library/list",
Path: "/api/map-library/list",
Handler: GetMapLibraryListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/map-library/save",
Path: "/api/map-library/save",
Handler: SaveMapLibraryHandler(serverCtx),
},
},

View File

@ -87,26 +87,35 @@ type CameraStand struct {
Z int64 `json:"z,optional"`
}
type Request struct {
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}
type ResponseJwt struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
}
type Auth struct {
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,12 +14,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/order/invoice",
Path: "/api/order/invoice",
Handler: GetOrderInvoiceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/order/detail",
Path: "/api/order/detail",
Handler: GetOrderDetailHandler(serverCtx),
},
},

View File

@ -76,26 +76,35 @@ type Deposit struct {
TransNo string `json:"trans_no"`
}
type Request struct {
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}
type ResponseJwt struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
}
type Auth struct {
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,17 +14,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/product-model/detail",
Path: "/api/product-model/detail",
Handler: GetModelDetailHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product-model/other-info",
Path: "/api/product-model/other-info",
Handler: GetModelOtherInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product-model/update-model",
Path: "/api/product-model/update-model",
Handler: UpdateProductModelHandler(serverCtx),
},
},

View File

@ -90,6 +90,20 @@ type Auth struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,27 +14,27 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/product-template/detail",
Path: "/api/product-template/detail",
Handler: GetTemplatevDetailHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product-template/base-map-list",
Path: "/api/product-template/base-map-list",
Handler: GetBaseMapListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product-template/base-map-update",
Path: "/api/product-template/base-map-update",
Handler: SaveBaseMapHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product-template/base-map-add",
Path: "/api/product-template/base-map-add",
Handler: AddBaseMapHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product-template/update-template",
Path: "/api/product-template/update-template",
Handler: UpdateTemplateHandler(serverCtx),
},
},

View File

@ -81,6 +81,20 @@ type Auth struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// Set 设置Response的Code和Message值
func (resp *Response) Set(Code int, Message string) *Response {
return &Response{

View File

@ -14,47 +14,47 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/product/list",
Path: "/api/product/list",
Handler: GetProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/success-recommand",
Path: "/api/product/success-recommand",
Handler: GetSuccessRecommandHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/get-size-by-product",
Path: "/api/product/get-size-by-product",
Handler: GetSizeByProductHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/design",
Path: "/api/product/design",
Handler: GetProductDesignHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product/design-gather",
Path: "/api/product/design-gather",
Handler: DesignGatherHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/info",
Path: "/api/product/info",
Handler: GetProductInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/product/save-design",
Path: "/api/product/save-design",
Handler: SaveDesignHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/other-list",
Path: "/api/product/other-list",
Handler: OtherProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/recommand",
Path: "/api/product/recommand",
Handler: GetRecommandProductListHandler(serverCtx),
},
},

View File

@ -14,37 +14,37 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/cart/add",
Path: "/api/cart/add",
Handler: CartAddHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cart/del",
Path: "/api/cart/del",
Handler: CartDeleteHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cart/num",
Path: "/api/cart/num",
Handler: CartNumberHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cart/list",
Path: "/api/cart/list",
Handler: CartListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cart/order-detail",
Path: "/api/cart/order-detail",
Handler: CartOrderDetailHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cart/chang-order-method",
Path: "/api/cart/chang-order-method",
Handler: ChangeOrderMethodHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cart/create-order",
Path: "/api/cart/create-order",
Handler: CreateOrderHandler(serverCtx),
},
},

View File

@ -132,6 +132,13 @@ type Auth struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`

View File

@ -14,22 +14,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/upload/up-file",
Path: "/api/upload/up-file",
Handler: UploadUpFileHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/upload/upload-file-frontend",
Path: "/api/upload/upload-file-frontend",
Handler: UploadFileFrontendHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/upload/upload-file-backend",
Path: "/api/upload/upload-file-backend",
Handler: UploadFileBackendHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/upload/qrcode",
Path: "/api/upload/qrcode",
Handler: UploadQrcodeHandler(serverCtx),
},
},

View File

@ -14,7 +14,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/web-set/setting",
Path: "/api/web-set/setting",
Handler: WebSetSettingHandler(serverCtx),
},
},

View File

@ -26,7 +26,7 @@ type Auth {
}
// File 文件
type File {
type File {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`

View File

@ -15,10 +15,10 @@ service product-template {
get /api/product-template/detail(GetTemplatevDetailReq) returns (response);
//获取底图列表
@handler GetBaseMapListHandler
get /api/product-template/base-map-list( ) returns (response);
get /api/product-template/base-map-list(request) returns (response);
//底图批量保存
@handler SaveBaseMapHandler
post /api/product-template/base-map-update ( ) returns (response);
post /api/product-template/base-map-update (request) returns (response);
//新增底图
@handler AddBaseMapHandler
post /api/product-template/base-map-add (AddBaseMapReq) returns (response);

View File

@ -18,7 +18,7 @@ service shopping-cart-confirmation {
post /api/cart/del (CartDeleteReq) returns (response);
//获取用户购物车数量
@handler CartNumberHandler
get /api/cart/num ( ) returns (response);
get /api/cart/num (request) returns (response);
//获取用户购物车列表
@handler CartListHandler
get /api/cart/list (CartListReq) returns (response);