Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
108 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package controllers | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"sync" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/zachrey/blog/models" | ||
) | ||
|
||
var wg sync.WaitGroup | ||
|
||
// RemoveFile 根据标题删除文章及相关项 | ||
func RemoveFile(c *gin.Context) { | ||
wg.Add(3) | ||
fileName := c.Query("name") | ||
if fileName == "" { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"status": 1, | ||
"msg": "Filed name is empty.", | ||
}) | ||
return | ||
} | ||
|
||
post := models.GetPostByTitle(fileName) | ||
|
||
// 删除分类关联表 | ||
go func() { | ||
models.RemovePCByPostID(post.Id) | ||
wg.Done() | ||
}() | ||
// 删除标签关联表 | ||
go func() { | ||
models.RemovePLByPostID(post.Id) | ||
wg.Done() | ||
}() | ||
// 删除文件 | ||
go func() { | ||
err := os.Remove("./posts/" + post.FileName) | ||
if err != nil { | ||
log.Println("[ERROR] ", err) | ||
} | ||
wg.Done() | ||
}() | ||
wg.Wait() | ||
models.RemovePostByID(post.Id) | ||
|
||
c.JSON(http.StatusOK, gin.H{ | ||
"status": 0, | ||
"msg": "删除文章成功!", | ||
}) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,2 @@ | ||
[GIN] 2018/06/10 - 21:02:19 | 200 | 998.6µs | 127.0.0.1 | GET /get-posts | ||
[GIN] 2018/06/10 - 21:02:21 | 200 | 1.9988ms | 127.0.0.1 | GET /get-labels | ||
[GIN] 2018/06/10 - 21:02:23 | 200 | 999µs | 127.0.0.1 | GET /get-posts-by-label/20 | ||
[GIN] 2018/06/10 - 21:02:24 | 200 | 1.9976ms | 127.0.0.1 | GET /get-html-str/32 | ||
[GIN] 2018/06/10 - 21:02:26 | 200 | 1.9985ms | 127.0.0.1 | GET /get-labels | ||
[GIN] 2018/06/10 - 21:02:26 | 200 | 4.998ms | 127.0.0.1 | GET /get-posts-by-label/21 | ||
[GIN] 2018/06/10 - 21:02:28 | 200 | 999.4µs | 127.0.0.1 | GET /get-html-str/32 | ||
[GIN] 2018/06/10 - 21:02:30 | 200 | 1.0002ms | 127.0.0.1 | GET /get-categoies | ||
[GIN] 2018/06/10 - 21:02:31 | 200 | 1.9984ms | 127.0.0.1 | GET /get-posts-by-category/82 | ||
[GIN] 2018/06/10 - 21:02:32 | 200 | 3.9973ms | 127.0.0.1 | GET /get-html-str/32 | ||
[GIN] 2018/06/10 - 21:02:34 | 200 | 0s | 127.0.0.1 | GET /get-categoies | ||
[GIN] 2018/06/10 - 21:02:35 | 200 | 2.9996ms | 127.0.0.1 | GET /get-html-str/32 | ||
[GIN] 2018/06/10 - 21:02:36 | 200 | 0s | 127.0.0.1 | GET /get-labels | ||
[GIN] 2018/06/10 - 21:02:38 | 200 | 3.9964ms | 127.0.0.1 | GET /get-posts | ||
[GIN] 2018/06/10 - 21:02:41 | 200 | 998.1µs | 127.0.0.1 | GET /get-html-str/32 | ||
[GIN] 2018/06/10 - 21:02:43 | 200 | 999.8µs | 127.0.0.1 | GET /get-posts | ||
[GIN] 2018/06/11 - 11:44:36 | 200 | 387.7766ms | ::1 | GET /remove?name=一个博客的名称 | ||
[GIN] 2018/06/11 - 11:45:16 | 200 | 133.9227ms | ::1 | POST /upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters