mirror of
https://github.com/beego/bee.git
synced 2024-11-22 20:20:55 +00:00
update swagger links
This commit is contained in:
parent
525d2b0901
commit
20da95be6e
2
bee.go
2
bee.go
@ -25,7 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "1.4.1"
|
const version = "1.5.0"
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
// Run runs the command.
|
// Run runs the command.
|
||||||
|
21
run.go
21
run.go
@ -120,7 +120,14 @@ func runApp(cmd *Command, args []string) int {
|
|||||||
files = append(files, arg)
|
files = append(files, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if downdoc == "true" {
|
||||||
|
if _, err := os.Stat(path.Join(currpath, "swagger", "index.html")); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
downloadFromURL(swaggerlink, "swagger.zip")
|
||||||
|
unzipAndDelete("swagger.zip")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if gendoc == "true" {
|
if gendoc == "true" {
|
||||||
NewWatcher(paths, files, true)
|
NewWatcher(paths, files, true)
|
||||||
Autobuild(files, true)
|
Autobuild(files, true)
|
||||||
@ -128,14 +135,7 @@ func runApp(cmd *Command, args []string) int {
|
|||||||
NewWatcher(paths, files, false)
|
NewWatcher(paths, files, false)
|
||||||
Autobuild(files, false)
|
Autobuild(files, false)
|
||||||
}
|
}
|
||||||
if downdoc == "true" {
|
|
||||||
if _, err := os.Stat(path.Join(currpath, "swagger")); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
downloadFromURL(swaggerlink, "swagger.zip")
|
|
||||||
unzipAndDelete("swagger.zip", "swagger")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-exit:
|
case <-exit:
|
||||||
@ -155,6 +155,9 @@ func readAppDirectories(directory string, paths *[]string) {
|
|||||||
if strings.HasSuffix(fileInfo.Name(), "docs") {
|
if strings.HasSuffix(fileInfo.Name(), "docs") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasSuffix(fileInfo.Name(), "swagger") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !vendorWatch && strings.HasSuffix(fileInfo.Name(), "vendor") {
|
if !vendorWatch && strings.HasSuffix(fileInfo.Name(), "vendor") {
|
||||||
continue
|
continue
|
||||||
|
50
rundocs.go
50
rundocs.go
@ -20,7 +20,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdRundocs = &Command{
|
var cmdRundocs = &Command{
|
||||||
@ -33,8 +32,9 @@ var cmdRundocs = &Command{
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
var (
|
||||||
swaggerlink = "https://github.com/beego/swagger/archive/v1.zip"
|
swaggerVersion = "2"
|
||||||
|
swaggerlink = "https://github.com/beego/swagger/archive/v" + swaggerVersion + ".zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type docValue string
|
type docValue string
|
||||||
@ -60,7 +60,7 @@ func init() {
|
|||||||
func runDocs(cmd *Command, args []string) int {
|
func runDocs(cmd *Command, args []string) int {
|
||||||
if isDownload == "true" {
|
if isDownload == "true" {
|
||||||
downloadFromURL(swaggerlink, "swagger.zip")
|
downloadFromURL(swaggerlink, "swagger.zip")
|
||||||
err := unzipAndDelete("swagger.zip", "swagger")
|
err := unzipAndDelete("swagger.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("has err exet unzipAndDelete", err)
|
fmt.Println("has err exet unzipAndDelete", err)
|
||||||
}
|
}
|
||||||
@ -78,33 +78,42 @@ func runDocs(cmd *Command, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func downloadFromURL(url, fileName string) {
|
func downloadFromURL(url, fileName string) {
|
||||||
fmt.Println("Downloading", url, "to", fileName)
|
var down bool
|
||||||
|
if fd, err := os.Stat(fileName); err != nil && os.IsNotExist(err) {
|
||||||
|
down = true
|
||||||
|
} else if fd.Size() == int64(0) {
|
||||||
|
down = true
|
||||||
|
} else {
|
||||||
|
ColorLog("[%s] Filename %s already exist\n", INFO, fileName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if down {
|
||||||
|
ColorLog("[%s]Downloading %s to %s\n", SUCC, url, fileName)
|
||||||
output, err := os.Create(fileName)
|
output, err := os.Create(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error while creating", fileName, "-", err)
|
ColorLog("[%s]Error while creating %s: %s\n", ERRO, fileName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer output.Close()
|
defer output.Close()
|
||||||
|
|
||||||
response, err := http.Get(url)
|
response, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error while downloading", url, "-", err)
|
ColorLog("[%s]Error while downloading %s:%s\n", ERRO, url, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
n, err := io.Copy(output, response.Body)
|
n, err := io.Copy(output, response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error while downloading", url, "-", err)
|
ColorLog("[%s]Error while downloading %s:%s\n", ERRO, url, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ColorLog("[%s] %d bytes downloaded.\n", SUCC, n)
|
||||||
fmt.Println(n, "bytes downloaded.")
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unzipAndDelete(src, dest string) error {
|
func unzipAndDelete(src string) error {
|
||||||
fmt.Println("start to unzip file from " + src + " to " + dest)
|
ColorLog("[%s]start to unzip file from %s\n", INFO, src)
|
||||||
r, err := zip.OpenReader(src)
|
r, err := zip.OpenReader(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -118,12 +127,11 @@ func unzipAndDelete(src, dest string) error {
|
|||||||
}
|
}
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
|
||||||
path := filepath.Join(dest, f.Name)
|
|
||||||
if f.FileInfo().IsDir() {
|
if f.FileInfo().IsDir() {
|
||||||
os.MkdirAll(path, f.Mode())
|
os.MkdirAll(f.Name, f.Mode())
|
||||||
} else {
|
} else {
|
||||||
f, err := os.OpenFile(
|
f, err := os.OpenFile(
|
||||||
path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -135,11 +143,11 @@ func unzipAndDelete(src, dest string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
os.RemoveAll("swagger")
|
||||||
fmt.Println("Start delete src file " + src)
|
err = os.Rename("swagger-"+swaggerVersion, "swagger")
|
||||||
err = os.RemoveAll(src)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
ColorLog("[%s]Rename swagger-%s to swagger:%s\n", ERRO, swaggerVersion, err)
|
||||||
}
|
}
|
||||||
return nil
|
ColorLog("[%s]Start delete src file %s\n", INFO, src)
|
||||||
|
return os.RemoveAll(src)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user