当前位置: 首页 > news >正文

wordpress站群搭建3api代码生成和swagger使用

海鸥技术下午茶-wordpress站群搭建3api代码生成和swagger使用

目标:实现api编写和swagger使用

0.本次需要使用到的脚手架命令

生成 http server 代码

goctl api go -api all.api -dir ..

生成swagger文档

goctl api plugin -plugin goctl-swagger="swagger -filename station.json -host 127.0.0.1:8000" -api all.api -dir .

运行 swagger

swagger serve --no-open -F=swagger --port 36666 station.json

1.编写api

api详细文档

base.api api公共types

syntax = "v1"// The basic response with data | 基础带数据信息
type BaseDataInfo {Code int    `json:"code"`           // Error code | 错误代码Message  string `json:"message"`    // Message | 提示信息Data string `json:"data,omitempty"` // Data | 数据
}
// The basic response with data | 基础带数据信息
type BaseListInfo {Total uint64 `json:"total"`          // The total number of data | 数据总数Data string `json:"data,omitempty"`  // Data | 数据
}
// The basic response without data | 基础不带数据信息
type BaseMsgResp {Code int    `json:"code"`          // Error code | 错误代码Message  string `json:"message"`   // Message | 提示信息
}
// The page request parameters | 列表请求参数
type PageInfo {Page   uint64    `form:"page" validate:"required,number,gt=0"`             // Page number | 第几页PageSize  uint64    `form:"pageSize" validate:"required,number,lt=100000"` // Page size | 单页数据行数
}
// Basic ID request | 基础ID参数请求
type IDReq {Id  uint64 `json:"id" validate:"number"` // ID Required: true
}
// Basic IDs request | 基础ID数组参数请求
type IDsReq {Ids  []uint64 `json:"ids"` // IDs Required: true
}
// Basic ID request | 基础ID地址参数请求
type IDPathReq {Id  uint64 `path:"id"` // ID  Required: true
}

all.api 用于聚合api

import "base.api"
import "./station/station.api"
import "./station/posts.api"
import "./station/delivery_log.api"

station.api 站点api

//站点信息
type  (// Station StationInfo {Id           uint64  `json:"id,optional"`            // 主键DomainName   string  `json:"domainName"`   // 域名Ip           string  `json:"ip,optional"`   // 域名DomainYear   int64   `json:"domainYear"`   // 域名年份GoogleWeight float64 `json:"googleWeight"` // 谷歌权重Type         string  `json:"type"`          // 网站类型Industry     string  `json:"industry"`      // 网站行业ArticlesNum  int64   `json:"articlesNum"`     // 文章数量UserName     string  `json:"userName,optional"`     // 账号名PassWord     string  `json:"passWord,optional"`     // 密码}// Station 页面查询StationReq {PageInfoDomainName   string  `form:"domainName,optional"`   // 域名Ip           string  `form:"ip,optional"`          // ipDomainYear   int64   `form:"domainYear,optional"`   // 域名年份GoogleWeight string  `form:"googleWeight,optional"` // 谷歌权重Type         string  `form:"type,optional"`          // 网站类型Industry     string  `form:"industry,optional"`      // 网站行业}// The response data of Station list | Station 列表数据StationListInfo {BaseListInfoData []StationInfo `json:"data"` // StationInfo list data | StationInfo列表数据}//Station 列表返回体StationListResp {BaseDataInfoData StationListInfo `json:"data"` // Station list data | Station列表数据}// Station 普通返回体StationInfoResp {BaseDataInfoData StationInfo `json:"data"` // Station information | Station数据}// Station Posts 返回体  StationPostsInfo {Id         uint64 `json:"id"`Title      string `json:"title"`       // Title}// 返回体StationPostsResp{BaseDataInfoData []StationPostsInfo `json:"data"`  // Station Posts 返回体}
)  
@server (group:      stationprefix: 	/stationtimeout:    10s
)
service Station {@doc "新增站点"@handler addStationpost /api/station (StationInfo) returns (StationInfoResp)@doc "修改站点"@handler updateStationput /api/station (StationInfo) returns (StationInfoResp)@doc "删除站点"@handler deleteStationdelete /api/station/:id (IDPathReq) returns (BaseDataInfo)@doc "查询站点"@handler queryStationget /api/station (StationReq) returns (StationListResp)@doc "获取关联的文章"@handler queryPostsget /api/station/posts/:id (IDPathReq) returns (StationPostsResp)
}

posts.api 文章api

//博客信息
type (// PostsPostsInfo {Id         uint64 `json:"id,optional"`Title      string `json:"title"` // 标题Source     string `json:"source"` // 来源Author     int64 `json:"author"` // 作者ThrownNum  int64  `json:"thrownNum"` // 投放数量Categories  string  `json:"categories"` // 分类CreateTime string `json:"createTime,optional"` //时间Content    string `json:"content"` //详情}// Posts 页面查询PostsReq {PageInfoTitle      string `form:"title,optional"` // 标题Source     string `form:"source,optional"` // 来源Categories     string `form:"categories,optional"` // 分类Author     int64 `form:"author,optional"` // 作者CreateTime int64  `form:"createTime,optional"` // 时间}// The response data of Posts list | Posts 列表数据PostsListInfo {BaseListInfoData []PostsInfo `json:"data"` // PostsInfo list data | PostsInfo列表数据}//Posts 列表返回体PostsListResp {BaseDataInfoData PostsListInfo `json:"data"` // Posts list data | Posts列表数据}// Posts 普通返回体PostsInfoResp {BaseDataInfoData PostsInfo `json:"data"` // Posts information | Posts数据}
)
@server (group:      postsprefix:     /station
)
service Station {@doc "新增Posts"@handler addPostspost /api/posts (PostsInfo) returns (PostsInfoResp)@doc "修改Posts"@handler updatePostsput /api/posts (PostsInfo) returns (PostsInfoResp)@doc "删除Posts"@handler deletePostsdelete /api/posts/:id (IDPathReq) returns (BaseDataInfo)@doc "查询Posts"@handler queryPostsget /api/posts (PostsReq) returns (PostsListResp)@doc "查询Posts详情"@handler getPostsget /api/posts/:id (IDPathReq) returns (PostsInfoResp)
}

delivery_log.api 文章分发日志api

//博客信息
type (// DeliveryLogDeliveryLogInfo {Id           uint64 `json:"id,optional"`Title        string `json:"title"` // 标题Source       string `json:"source,optional"` // 来源DomainName   string `json:"domainName"` // 域名DeliveryDate string `json:"deliveryDate,optional"` // 投放日期Deliverer    string `json:"deliverer,optional"` // 投放人Status       int64  `json:"status,optional"` // 投放状态Author       uint64 `json:"author,optional"` // 作者WpCateIds    string `json:"wpCateIds,optional"` // wp分类StationId    uint64 `json:"stationId,optional"` // 站点idPostsId      uint64 `json:"postsId,optional"` // 文章id}// 投放对象DeliveryInfo {StationInfoList []StationInfo `json:"stationInfoList"` // 站点idPostsInfoList   []PostsInfo   `json:"postsInfoList"` // 文章id}// DeliveryLog 页面查询DeliveryLogReq {PageInfoTitle        string `form:"title,optional"` // 标题Source       string `form:"source,optional"` // 来源DomainName   string `form:"domainName,optional"` // 域名DeliveryDate int64  `form:"deliveryDate,optional"` // 投放日期Deliverer    string `form:"deliverer,optional"` // 投放人Status       int64  `form:"status,optional"` // 投放状态Author       uint64 `form:"author,optional"` // 作者}// The response data of DeliveryLog list | DeliveryLog 列表数据DeliveryLogListInfo {BaseListInfoData []DeliveryLogInfo `json:"data"`	// DeliveryLogInfo list data | DeliveryLogInfo列表数据}// The response data of DeliveryLog list | DeliveryLog 列表数据DeliveryListInfo {Data []DeliveryLogInfo `json:"data"`	// DeliveryInfo list data | DeliveryInfo列表数据}//DeliveryLog 列表返回体DeliveryLogListResp {BaseDataInfoData DeliveryLogListInfo `json:"data"` // DeliveryLog list data | DeliveryLog列表数据}// DeliveryLog 普通返回体DeliveryLogInfoResp {BaseDataInfoData DeliveryLogInfo `json:"data"`  // DeliveryLog information | DeliveryLog数据}
)@server (group:      deliveryLogprefix:     /station
)
service Station {@doc "投放" @handler addDeliveryLogpost /api/deliverylog (DeliveryListInfo) returns (BaseDataInfo)@doc "修改DeliveryLog"@handler updateDeliveryLogput /api/deliverylog (DeliveryLogInfo) returns (DeliveryLogInfoResp)@doc "删除DeliveryLog"@handler deleteDeliveryLogdelete /api/deliverylog/:id (IDPathReq) returns (BaseDataInfo)@doc "查询DeliveryLog"@handler queryDeliveryLogget /api/deliverylog (DeliveryLogReq) returns (DeliveryLogListResp)@doc "获取投放列表"@handler generateDeliveryListpost /api/deliverylog/list (DeliveryInfo) returns (DeliveryLogListResp)
}

2.生成代码

进入到api项目的desc目录,运行生成api代码脚手架命令

cd ./desc
goctl api go -api all.api -dir ..

3.swagger使用

还是在desc目录下,生成swaagger json

goctl api plugin -plugin goctl-swagger="swagger -filename station.json -host 127.0.0.1:8000" -api all.api -dir .

运行swagger

swagger serve --no-open -F=swagger --port 36666 station.json

4.允许跨域配置

在入口文件 station.go中修改

//rest.MustNewServer(c.RestConf)
//修改为下面的代码
rest.MustNewServer(c.RestConf, rest.WithCors())

5.测试api

运行rpc和api后。

启动完swagger,我们可以在swagger上面进行api测试了。

访问 http://127.0.0.1:36666/docs 页面,可以直接在页面上进行测试。
在这里插入图片描述
项目源码地址

上一篇: wordpress站群搭建2代码初始化

相关文章:

wordpress站群搭建3api代码生成和swagger使用

海鸥技术下午茶-wordpress站群搭建3api代码生成和swagger使用 目标:实现api编写和swagger使用 0.本次需要使用到的脚手架命令 生成 http server 代码 goctl api go -api all.api -dir ..生成swagger文档 goctl api plugin -plugin goctl-swagger"swagger -filename st…...

如何在使用 Qt 时打印到控制台

在开发过程中,打印变量值到控制台对于调试和监控非常重要。使用 Qt 和 C 开发时,有多种方法可以实现这一点。在本文中,我们将探索几种在 Qt 中打印到控制台的专业方法。 1. 使用 qDebug、qWarning、qCritical 和 qFatal Qt 提供了一些方便的…...

ffmpeg音视频开发从入门到精通——ffmpeg下载编译与安装

音视频领域学习ffmpeg的重要性 音视频领域中ffmpeg的广泛应用,包括直播、短视频、网络视频、实时互动和视频监控等领域。掌握FM和音视频技术可以获得更好的薪酬。 学习建议音视频学习建议与实战应用 音视频处理机制的学习,需要勤加练习,带…...

数据通信与网络(三)

物理层概述: 物理层是网络体系结构中的最低层 它既不是指连接计算机的具体物理设备,也不是指负责信号传输的具体物理介质, 而是指在连接开放系统的物理媒体上为上一层(指数据链路层)提供传送比特流的一个物理连接。 物理层的主要功能——为…...

盲盒小程序模式?有什么功能?

近些年,盲盒成为了热门的休闲娱乐消费方式,深深吸引着消费者的目光,行业更是持续上升发展,成为了具有巨大发展前景的行业之一。 随着市场的逐步发展,盲盒也开始向线上模式发展,以互联网为媒介,…...

【MySQL进阶之路 | 高级篇】InnoDB搜索引擎行格式

1. COMPACT行格式 COMPACT行格式是MySQL5.1的默认行格式.其结构示意图如下. 大体可以分为两部分. 记录的额外信息.这里面有包括变长字段长度列表,NULL值列表和记录头信息.记录的真实数据. (1).变长字段长度列表 MySQL支持一些变长的数据类型.比如VARCHAR(m), VA…...

大数据面试-Scala

谈谈scala的闭包、柯里化、高阶函数 如果一个函数,访问到了它的外部(局部)变量的值,那么这个函数和他所处的环境,称为闭包。 闭包在函数式编程中是一个重要的概念,广泛用于高阶函数、柯里化等技术中。 函数…...

76.最小覆盖子串

给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 “” 。 注意: 对于 t 中重复字符,我们寻找的子字符串中该字符数量必须不少于 t 中该字符数量。 如果 s 中存…...

深度学习算法informer(时序预测)(三)(Encoder)

一、EncoderLayer架构如图(不改变输入形状) 二、ConvLayer架构如图(输入形状中特征维度减半) 三、Encoder整体 包括三部分 1. 多层EncoderLayer 2. 多层ConvLayer 3. 层归一化 代码如下 class AttentionLayer(nn.Module):de…...

HTML和CSS基础(一)

前言 HTML(HyperText Markup Language)是一种用于创建网页的标准标记语言。它由各种标签组成,这些标签定义了网页的结构和内容。HTML的早期形式诞生于1989年,由CERN的物理学家Tim Berners-Lee发明,最初用于在科学家之…...

低代码平台教你两步把SQL直接转换为RESTful API

文章目录 前言一、简介1. 项目亮点2. 技术栈3. 核心功能4. 数据库设计二、搭建教程1. 目录结构2. 下载2.1 下载2.2 上传2.3 解压3. 配置3.1 创建并切换数据库3.2 执行sql文件3.3 修改配置文件4. 启动/停止4.1 启动4.2 停止4.3 重启5. 浏览器访问三、配置教程1. 数据源配置1.1 创…...

JavaWeb阶段学习知识点(二)

登录校验和JWT令牌实现 JWT使用方式 创建一个springboot项目,pom.xml引入jwt依赖 <dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.1</version></dependency><!-- 针对jdk17或…...

数据结构【二叉树】

前言 我们在前面学习了使用数组来实现二叉树&#xff0c;但是数组实现二叉树仅适用于完全二叉树&#xff08;非完全二叉树会有空间浪费&#xff09;&#xff0c;所以我们本章讲解的是链式二叉树&#xff0c;但由于学习二叉树的操作需要有一颗树&#xff0c;才能学习相关的基本…...

Vue P17-54

18、计算属性 示例&#xff1a;实现姓名的联动效果 可以用插值语法、method {{func()}} 这里必须有 &#xff08;&#xff09;表示返回值 在事件处理中&#xff0c;click“func1” 有没有无所谓 computed的计算属性和data中的属性都在vm中&#xff0c;但vm._data里只有后者…...

【自动驾驶】从零开始做自动驾驶小车

文章目录 自动驾驶小车系统、运动底盘的运动学分析和串口通信控制电机PID控制IMU初始化与陀螺仪零点漂移ubuntu基础教程ROS基础键盘控制巡线(雷达避障)雷达跟随视觉跟踪2D建图、2D导航3D建图、3D导航纯视觉建图导航语音控制KCF跟随自主建图建图与导航多机编队WEB浏览器显示摄像…...

一文让你彻底搞懂什么是VR、AR、AV、MR

随着科技的飞速发展&#xff0c;现实世界与虚拟世界的界限变得越来越模糊。各种与现实增强相关的技术如雨后春笋般涌现&#xff0c;令人眼花缭乱。本文将为你详细解读四种常见的现实增强技术&#xff1a;虚拟现实&#xff08;VR&#xff09;、增强现实&#xff08;AR&#xff0…...

Python设计模式 - 简单工厂模式

定义 简单工厂模式是一种创建型设计模式&#xff0c;它通过一个工厂类来创建对象&#xff0c;而不是通过客户端直接实例化对象。 结构 工厂类&#xff08;Factory&#xff09;&#xff1a;负责创建对象的实例。工厂类通常包含一个方法&#xff0c;根据输入参数的不同创建并返…...

L55--- 257.二叉树的所有路径(深搜)---Java版

1.题目描述 2.思路 &#xff08;1&#xff09;因为是求二叉树的所有路径 &#xff08;2&#xff09;然后是带固定格式的 所以我们要把每个节点的整数数值换成字符串数值 &#xff08;3&#xff09;首先先考虑根节点&#xff0c;也就是要满足节点不为空 返回递归的形式dfs(根节…...

智慧园区解决方案PPT(53页)

## 1.1 智慧园区背景及需求分析 - 智慧园区的发展历程包括园区规划、经济、产业、企业、管理、理念的转变&#xff0c;强调管理模式创新&#xff0c;关注业务综合化、管理智慧化等发展。 ## 1.2 国家对智慧园区发展的政策 - 涉及多个国家部门&#xff0c;如工信部、住建部、…...

Windows安装MySQL(8.0.37)

安装&#xff1a;https://blog.csdn.net/XLBYYDS/article/details/139711682 注意点&#xff1a; &#xff08;1&#xff09;必须安装到C盘系统盘&#xff0c;否则执行 net start mysql 启动服务时&#xff0c;可能会启动失败。 &#xff08;2&#xff09;如果安装时出现 The…...

鱼香ros docker配置镜像报错:https://registry-1.docker.io/v2/

使用鱼香ros一件安装docker时的https://registry-1.docker.io/v2/问题 一键安装指令 wget http://fishros.com/install -O fishros && . fishros出现问题&#xff1a;docker pull 失败 网络不同&#xff0c;需要使用镜像源 按照如下步骤操作 sudo vi /etc/docker/dae…...

CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

免费PDF转图片工具

免费PDF转图片工具 一款简单易用的PDF转图片工具&#xff0c;可以将PDF文件快速转换为高质量PNG图片。无需安装复杂的软件&#xff0c;也不需要在线上传文件&#xff0c;保护您的隐私。 工具截图 主要特点 &#x1f680; 快速转换&#xff1a;本地转换&#xff0c;无需等待上…...

GitFlow 工作模式(详解)

今天再学项目的过程中遇到使用gitflow模式管理代码&#xff0c;因此进行学习并且发布关于gitflow的一些思考 Git与GitFlow模式 我们在写代码的时候通常会进行网上保存&#xff0c;无论是github还是gittee&#xff0c;都是一种基于git去保存代码的形式&#xff0c;这样保存代码…...

C#学习第29天:表达式树(Expression Trees)

目录 什么是表达式树&#xff1f; 核心概念 1.表达式树的构建 2. 表达式树与Lambda表达式 3.解析和访问表达式树 4.动态条件查询 表达式树的优势 1.动态构建查询 2.LINQ 提供程序支持&#xff1a; 3.性能优化 4.元数据处理 5.代码转换和重写 适用场景 代码复杂性…...

根目录0xa0属性对应的Ntfs!_SCB中的FileObject是什么时候被建立的----NTFS源代码分析--重要

根目录0xa0属性对应的Ntfs!_SCB中的FileObject是什么时候被建立的 第一部分&#xff1a; 0: kd> g Breakpoint 9 hit Ntfs!ReadIndexBuffer: f7173886 55 push ebp 0: kd> kc # 00 Ntfs!ReadIndexBuffer 01 Ntfs!FindFirstIndexEntry 02 Ntfs!NtfsUpda…...

【Kafka】Kafka从入门到实战:构建高吞吐量分布式消息系统

Kafka从入门到实战:构建高吞吐量分布式消息系统 一、Kafka概述 Apache Kafka是一个分布式流处理平台,最初由LinkedIn开发,后成为Apache顶级项目。它被设计用于高吞吐量、低延迟的消息处理,能够处理来自多个生产者的海量数据,并将这些数据实时传递给消费者。 Kafka核心特…...

boost::filesystem::path文件路径使用详解和示例

boost::filesystem::path 是 Boost 库中用于跨平台操作文件路径的类&#xff0c;封装了路径的拼接、分割、提取、判断等常用功能。下面是对它的使用详解&#xff0c;包括常用接口与完整示例。 1. 引入头文件与命名空间 #include <boost/filesystem.hpp> namespace fs b…...

【PX4飞控】mavros gps相关话题分析,经纬度海拔获取方法,卫星数锁定状态获取方法

使用 ROS1-Noetic 和 mavros v1.20.1&#xff0c; 携带经纬度海拔的话题主要有三个&#xff1a; /mavros/global_position/raw/fix/mavros/gpsstatus/gps1/raw/mavros/global_position/global 查看 mavros 源码&#xff0c;来分析他们的发布过程。发现前两个话题都对应了同一…...