style: 修改swagger文件位置

pull/76/head
zhengkunwang223 2022-12-14 19:39:32 +08:00 committed by zhengkunwang223
parent 306e5c5b9e
commit cec416b674
9 changed files with 69 additions and 30 deletions

View File

@ -18,10 +18,10 @@ import (
type NginxService struct { type NginxService struct {
} }
func (n NginxService) GetNginxConfig() (dto.FileInfo, error) { func (n NginxService) GetNginxConfig() (response.FileInfo, error) {
nginxInstall, err := getAppInstallByKey(constant.AppNginx) nginxInstall, err := getAppInstallByKey(constant.AppNginx)
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "nginx.conf") configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "nginx.conf")
info, err := files.NewFileInfo(files.FileOption{ info, err := files.NewFileInfo(files.FileOption{
@ -29,9 +29,9 @@ func (n NginxService) GetNginxConfig() (dto.FileInfo, error) {
Expand: true, Expand: true,
}) })
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
return dto.FileInfo{FileInfo: *info}, nil return response.FileInfo{FileInfo: *info}, nil
} }
func (n NginxService) GetConfigByScope(req request.NginxScopeReq) ([]response.NginxParam, error) { func (n NginxService) GetConfigByScope(req request.NginxScopeReq) ([]response.NginxParam, error) {

View File

@ -41,7 +41,7 @@ type IWebsiteService interface {
DeleteWebsiteDomain(domainId uint) error DeleteWebsiteDomain(domainId uint) error
GetNginxConfigByScope(req request.NginxScopeReq) (*response.WebsiteNginxConfig, error) GetNginxConfigByScope(req request.NginxScopeReq) (*response.WebsiteNginxConfig, error)
UpdateNginxConfigByScope(req request.NginxConfigUpdate) error UpdateNginxConfigByScope(req request.NginxConfigUpdate) error
GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, error) GetWebsiteNginxConfig(websiteId uint) (response.FileInfo, error)
GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error)
OpWebsiteHTTPS(req request.WebsiteHTTPSOp) (response.WebsiteHTTPS, error) OpWebsiteHTTPS(req request.WebsiteHTTPSOp) (response.WebsiteHTTPS, error)
PreInstallCheck(req request.WebsiteInstallCheckReq) ([]response.WebsitePreInstallCheck, error) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]response.WebsitePreInstallCheck, error)
@ -382,19 +382,19 @@ func (w WebsiteService) UpdateNginxConfigByScope(req request.NginxConfigUpdate)
return updateNginxConfig(constant.NginxScopeServer, params, &website) return updateNginxConfig(constant.NginxScopeServer, params, &website)
} }
func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, error) { func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (response.FileInfo, error) {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId)) website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId))
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx)) nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID)) nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID))
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", website.Alias+".conf") configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", website.Alias+".conf")
@ -404,9 +404,9 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
Expand: true, Expand: true,
}) })
if err != nil { if err != nil {
return dto.FileInfo{}, err return response.FileInfo{}, err
} }
return dto.FileInfo{FileInfo: *info}, nil return response.FileInfo{FileInfo: *info}, nil
} }
func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) { func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) {

View File

@ -1,7 +0,0 @@
{
"swagger": "2.0",
"info": {
"contact": {}
},
"paths": {}
}

View File

@ -1,4 +0,0 @@
info:
contact: {}
paths: {}
swagger: "2.0"

View File

@ -5,10 +5,10 @@ import (
"net/http" "net/http"
v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/backend/docs"
"github.com/1Panel-dev/1Panel/backend/i18n" "github.com/1Panel-dev/1Panel/backend/i18n"
"github.com/1Panel-dev/1Panel/backend/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
rou "github.com/1Panel-dev/1Panel/backend/router" rou "github.com/1Panel-dev/1Panel/backend/router"
"github.com/1Panel-dev/1Panel/cmd/server/docs"
"github.com/1Panel-dev/1Panel/cmd/server/web" "github.com/1Panel-dev/1Panel/cmd/server/web"
ginI18n "github.com/gin-contrib/i18n" ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -38,17 +38,19 @@ func setWebStatic(rootRouter *gin.Engine) {
func Routers() *gin.Engine { func Routers() *gin.Engine {
Router := gin.Default() Router := gin.Default()
docs.SwaggerInfo.BasePath = "/api/v1"
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
Router.Use(middleware.OperationLog()) Router.Use(middleware.OperationLog())
Router.Use(middleware.CSRF()) Router.Use(middleware.CSRF())
Router.Use(middleware.LoadCsrfToken()) Router.Use(middleware.LoadCsrfToken())
setWebStatic(Router) setWebStatic(Router)
docs.SwaggerInfo.BasePath = "/api/v1"
Router.Use(i18n.GinI18nLocalize()) Router.Use(i18n.GinI18nLocalize())
Router.GET("/api/v1/info", v1.ApiGroupApp.BaseApi.GetSafetyStatus) Router.GET("/api/v1/info", v1.ApiGroupApp.BaseApi.GetSafetyStatus)
Router.GET("/api/v1/:code", v1.ApiGroupApp.BaseApi.SafeEntrance) Router.GET("/api/v1/:code", v1.ApiGroupApp.BaseApi.SafeEntrance)
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
Router.SetFuncMap(template.FuncMap{ Router.SetFuncMap(template.FuncMap{
"Localize": ginI18n.GetMessage, "Localize": ginI18n.GetMessage,

View File

@ -10,7 +10,12 @@ const docTemplate = `{
"info": { "info": {
"description": "{{escape .Description}}", "description": "{{escape .Description}}",
"title": "{{.Title}}", "title": "{{.Title}}",
"termsOfService": "http://swagger.io/terms/",
"contact": {}, "contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}" "version": "{{.Version}}"
}, },
"host": "{{.Host}}", "host": "{{.Host}}",
@ -20,12 +25,12 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "", Version: "1.0",
Host: "", Host: "localhost",
BasePath: "", BasePath: "/api/v1",
Schemes: []string{}, Schemes: []string{},
Title: "", Title: "1Panel",
Description: "", Description: "开源Linux面板",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate, SwaggerTemplate: docTemplate,
} }

View File

@ -0,0 +1,17 @@
{
"swagger": "2.0",
"info": {
"description": "开源Linux面板",
"title": "1Panel",
"termsOfService": "http://swagger.io/terms/",
"contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "localhost",
"basePath": "/api/v1",
"paths": {}
}

View File

@ -0,0 +1,13 @@
basePath: /api/v1
host: localhost
info:
contact: {}
description: 开源Linux面板
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: http://swagger.io/terms/
title: 1Panel
version: "1.0"
paths: {}
swagger: "2.0"

View File

@ -2,8 +2,21 @@ package main
import ( import (
"github.com/1Panel-dev/1Panel/backend/server" "github.com/1Panel-dev/1Panel/backend/server"
_ "github.com/1Panel-dev/1Panel/cmd/server/docs"
) )
// @title 1Panel
// @version 1.0
// @description 开源Linux面板
// @termsOfService http://swagger.io/terms/
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost
// @BasePath /api/v1
//go:generate swag init -o ./docs -d ../../backend/app/api/v1 -g ../../../../cmd/server/main.go
func main() { func main() {
server.Start() server.Start()
} }