Update pod.go
This commit is contained in:
		@ -11,20 +11,14 @@ var Pod pod
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type pod struct{}
 | 
					type pod struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Controller中的方法入参是gin.Context,用于从上下文中获取请求参数以及定义响应内容
 | 
					 | 
				
			||||||
//流程:绑定参数 --> 调用service代码 --> 根据调用结果响应具体内容
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// GetPods 获取Pod列表,支持分页、过滤、排序
 | 
					// GetPods 获取Pod列表,支持分页、过滤、排序
 | 
				
			||||||
func (p *pod) GetPods(ctx *gin.Context) {
 | 
					func (p *pod) GetPods(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	//匿名结构体用于定义入参,get请求为form格式,其他请求为json格式
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		FilterName string `form:"filter_name"`
 | 
							FilterName string `form:"filter_name"`
 | 
				
			||||||
		Namespace  string `form:"namespace"`
 | 
							Namespace  string `form:"namespace"`
 | 
				
			||||||
		Limit      int    `form:"limit"`
 | 
							Limit      int    `form:"limit"`
 | 
				
			||||||
		Page       int    `form:"page"`
 | 
							Page       int    `form:"page"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//form格式使用Bind方法,json格式使用ShouldBindJSON方法
 | 
					 | 
				
			||||||
	if err := ctx.Bind(params); err != nil {
 | 
						if err := ctx.Bind(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind绑定参数失败" + err.Error())
 | 
							logger.Error("Bind绑定参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
@ -50,13 +44,10 @@ func (p *pod) GetPods(ctx *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//获取Pod详情
 | 
					//获取Pod详情
 | 
				
			||||||
func (p *pod) GetPodDetail(ctx *gin.Context) {
 | 
					func (p *pod) GetPodDetail(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	//匿名结构体用于定义入参,get请求为form格式,其他请求为json格式
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		PodName   string `form:"pod_name"`
 | 
							PodName   string `form:"pod_name"`
 | 
				
			||||||
		Namespace string `form:"namespace"`
 | 
							Namespace string `form:"namespace"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//form格式使用Bind方法,json格式使用ShouldBindJSON方法
 | 
					 | 
				
			||||||
	if err := ctx.Bind(params); err != nil {
 | 
						if err := ctx.Bind(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind绑定参数失败" + err.Error())
 | 
							logger.Error("Bind绑定参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
@ -82,13 +73,11 @@ func (p *pod) GetPodDetail(ctx *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//删除Pod
 | 
					//删除Pod
 | 
				
			||||||
func (p *pod) DeletePod(ctx *gin.Context) {
 | 
					func (p *pod) DeletePod(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	//匿名结构体用于定义入参,get请求为form格式,其他请求为json格式
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		PodName   string `json:"pod_name"`
 | 
							PodName   string `json:"pod_name"`
 | 
				
			||||||
		Namespace string `json:"namespace"`
 | 
							Namespace string `json:"namespace"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//form格式使用Bind方法,json格式使用ShouldBindJSON方法
 | 
					
 | 
				
			||||||
	if err := ctx.ShouldBindJSON(params); err != nil {
 | 
						if err := ctx.ShouldBindJSON(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind绑定参数失败" + err.Error())
 | 
							logger.Error("Bind绑定参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
@ -114,13 +103,11 @@ func (p *pod) DeletePod(ctx *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//更新Pod
 | 
					//更新Pod
 | 
				
			||||||
func (p *pod) UpdatePod(ctx *gin.Context) {
 | 
					func (p *pod) UpdatePod(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	//匿名结构体用于定义入参,get请求为form格式,其他请求为json格式
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		Namespace string `json:"namespace"`
 | 
							Namespace string `json:"namespace"`
 | 
				
			||||||
		Content   string `json:"content"`
 | 
							Content   string `json:"content"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//PUT请求,绑定参数方法改为ctx.ShouldBindJSON方法
 | 
					
 | 
				
			||||||
	if err := ctx.ShouldBindJSON(params); err != nil {
 | 
						if err := ctx.ShouldBindJSON(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind绑定参数失败" + err.Error())
 | 
							logger.Error("Bind绑定参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
@ -146,12 +133,10 @@ func (p *pod) UpdatePod(ctx *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//获取Pod容器
 | 
					//获取Pod容器
 | 
				
			||||||
func (p *pod) GetPodContainer(ctx *gin.Context) {
 | 
					func (p *pod) GetPodContainer(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		PodName   string `form:"pod_name"`
 | 
							PodName   string `form:"pod_name"`
 | 
				
			||||||
		Namespace string `form:"namespace"`
 | 
							Namespace string `form:"namespace"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//GET请求,绑定参数方法改为ctx.Bind方法
 | 
					 | 
				
			||||||
	if err := ctx.Bind(params); err != nil {
 | 
						if err := ctx.Bind(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind请求参数失败" + err.Error())
 | 
							logger.Error("Bind请求参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
@ -177,13 +162,11 @@ func (p *pod) GetPodContainer(ctx *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//获取Pod容器日志
 | 
					//获取Pod容器日志
 | 
				
			||||||
func (p *pod) GetPodLog(ctx *gin.Context) {
 | 
					func (p *pod) GetPodLog(ctx *gin.Context) {
 | 
				
			||||||
	//处理入参
 | 
					 | 
				
			||||||
	params := new(struct {
 | 
						params := new(struct {
 | 
				
			||||||
		ContainerName string `form:"container_name"`
 | 
							ContainerName string `form:"container_name"`
 | 
				
			||||||
		PodName       string `form:"pod_name"`
 | 
							PodName       string `form:"pod_name"`
 | 
				
			||||||
		Namespace     string `form:"namespace"`
 | 
							Namespace     string `form:"namespace"`
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	//GET请求,绑定参数方法改为ctx.Bind方法
 | 
					 | 
				
			||||||
	if err := ctx.Bind(params); err != nil {
 | 
						if err := ctx.Bind(params); err != nil {
 | 
				
			||||||
		logger.Error("Bind请求参数失败" + err.Error())
 | 
							logger.Error("Bind请求参数失败" + err.Error())
 | 
				
			||||||
		ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
							ctx.JSON(http.StatusInternalServerError, gin.H{
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user