添加文章管理实现

master
18650180552 2019-05-17 17:45:50 +08:00
parent e1a9009d95
commit c5a4c7edab
6 changed files with 186 additions and 110 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ glide.yaml
api_user.exe api_user.exe
user.exe user.exe
background.exe background.exe
backgroun.exe

View File

@ -2,16 +2,10 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="882ad3e2-74c3-43b0-b9f1-5497ec2bf4ca" name="Default Changelist" comment=""> <list default="true" id="882ad3e2-74c3-43b0-b9f1-5497ec2bf4ca" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/background.iml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/controller/blog.go" beforeDir="false" afterPath="$PROJECT_DIR$/controller/blog.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/controller/blog.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/model/blog.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/config/config.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/db/sqlManager.go" beforeDir="false" afterPath="$PROJECT_DIR$/db/sqlManager.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/model/blog.go" beforeDir="false" afterPath="$PROJECT_DIR$/model/blog.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/user.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/user.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/user.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/user.yaml" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -21,26 +15,31 @@
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/controller/file.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/user.yaml"> <entry file="file://$PROJECT_DIR$/user.yaml">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="253"> <state relative-caret-position="299">
<caret line="11" column="7" selection-start-line="11" selection-start-column="7" selection-end-line="11" selection-end-column="7" /> <caret line="13" column="22" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.go"> <entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="194"> <state relative-caret-position="202">
<caret line="91" column="24" selection-start-line="91" selection-start-column="17" selection-end-line="91" selection-end-column="24" /> <caret line="92" column="46" selection-start-line="92" selection-start-column="46" selection-end-line="92" selection-end-column="46" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor />
<second_editor />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -48,19 +47,28 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/controller/blog.go"> <entry file="file://$PROJECT_DIR$/controller/blog.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="207"> <state relative-caret-position="248">
<caret line="9" column="10" selection-start-line="9" selection-start-column="10" selection-end-line="9" selection-end-column="10" /> <caret line="78" column="19" selection-start-line="78" selection-start-column="19" selection-end-line="78" selection-end-column="19" />
<folding> <folding>
<element signature="e#20#78#0" expanded="true" /> <element signature="e#20#97#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://C:/Go/src/strconv/atoi.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="201" column="5" selection-start-line="201" selection-start-column="5" selection-end-line="201" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/controller/user.go"> <entry file="file://$PROJECT_DIR$/controller/user.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="439"> <state relative-caret-position="2093">
<caret line="116" column="18" selection-start-line="116" selection-start-column="18" selection-end-line="116" selection-end-column="18" /> <caret line="116" column="18" selection-start-line="116" selection-start-column="18" selection-end-line="116" selection-end-column="18" />
</state> </state>
</provider> </provider>
@ -69,7 +77,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/model/model.go"> <entry file="file://$PROJECT_DIR$/model/model.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374"> <state relative-caret-position="989">
<caret line="50" column="5" selection-start-line="50" selection-start-column="5" selection-end-line="50" selection-end-column="5" /> <caret line="50" column="5" selection-start-line="50" selection-start-column="5" selection-end-line="50" selection-end-column="5" />
<folding> <folding>
<element signature="e#15#109#0" expanded="true" /> <element signature="e#15#109#0" expanded="true" />
@ -78,14 +86,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/model/blog.go"> <entry file="file://$PROJECT_DIR$/model/blog.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391"> <state relative-caret-position="115">
<caret line="17" column="10" selection-start-line="17" selection-start-column="10" selection-end-line="17" selection-end-column="10" /> <caret line="5" selection-start-line="5" selection-end-line="5" />
<folding>
<element signature="e#15#42#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -94,7 +99,7 @@
<entry file="file://$PROJECT_DIR$/db/db.go"> <entry file="file://$PROJECT_DIR$/db/db.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285"> <state relative-caret-position="285">
<caret line="124" column="70" selection-start-line="124" selection-start-column="70" selection-end-line="124" selection-end-column="70" /> <caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -102,7 +107,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://C:/Go/src/database/sql/sql.go"> <entry file="file://C:/Go/src/database/sql/sql.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285"> <state relative-caret-position="59179">
<caret line="2586" column="5" selection-start-line="2586" selection-start-column="5" selection-end-line="2586" selection-end-column="5" /> <caret line="2586" column="5" selection-start-line="2586" selection-start-column="5" selection-end-line="2586" selection-end-column="5" />
</state> </state>
</provider> </provider>
@ -124,9 +129,9 @@
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$PROJECT_DIR$/model/blog.go" />
<option value="$PROJECT_DIR$/controller/blog.go" />
<option value="$PROJECT_DIR$/main.go" /> <option value="$PROJECT_DIR$/main.go" />
<option value="$PROJECT_DIR$/controller/blog.go" />
<option value="$PROJECT_DIR$/model/blog.go" />
</list> </list>
</option> </option>
</component> </component>
@ -142,27 +147,7 @@
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" /> <pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane" />
<subPane>
<expand>
<path>
<item name="background" type="b2602c69:ProjectViewProjectNode" />
<item name="background" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="background" type="b2602c69:ProjectViewProjectNode" />
<item name="background" type="462c0819:PsiDirectoryNode" />
<item name="controller" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="background" type="b2602c69:ProjectViewProjectNode" />
<item name="background" type="462c0819:PsiDirectoryNode" />
<item name="redis" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
@ -193,18 +178,19 @@
</option> </option>
</component> </component>
<component name="RunManager"> <component name="RunManager">
<configuration name="go build main.go" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true"> <configuration name="backgroun" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
<module name="background" /> <module name="background" />
<working_directory value="$PROJECT_DIR$/" /> <working_directory value="$PROJECT_DIR$/" />
<kind value="FILE" /> <kind value="FILE" />
<filePath value="$PROJECT_DIR$/main.go" /> <filePath value="$PROJECT_DIR$/main.go" />
<package value="background" /> <package value="background" />
<directory value="$PROJECT_DIR$/" /> <directory value="$PROJECT_DIR$/" />
<output_directory value="$PROJECT_DIR$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Go Build.go build main.go" /> <item itemvalue="Go Build.backgroun" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -212,15 +198,9 @@
<frame x="-8" y="32" width="1936" height="1056" extended-state="6" /> <frame x="-8" y="32" width="1936" height="1056" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info id="Favorites" side_tool="true" /> <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2524013" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2497332" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="LuaCheck" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32960895" /> <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32960895" />
@ -228,21 +208,24 @@
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Google Cloud Storage" show_stripe_button="false" /> <window_info anchor="bottom" id="LuaCheck" order="7" />
<window_info anchor="right" id="JSON Utils" /> <window_info anchor="bottom" id="Docker" order="8" show_stripe_button="false" />
<window_info anchor="right" id="Database" /> <window_info anchor="bottom" id="Version Control" order="9" />
<window_info anchor="bottom" id="Database Changes" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Google Cloud Storage" order="3" show_stripe_button="false" />
<window_info anchor="right" id="Database" order="4" />
<window_info anchor="right" id="JSON Utils" order="5" />
</layout> </layout>
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/controller/file.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/redis/redis.go"> <entry file="file://$PROJECT_DIR$/redis/redis.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-4342"> <state relative-caret-position="-4342">
@ -253,16 +236,19 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/user.yaml"> <entry file="file://$PROJECT_DIR$/controller/file.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/controller/user.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="253"> <state relative-caret-position="2093">
<caret line="11" column="7" selection-start-line="11" selection-start-column="7" selection-end-line="11" selection-end-column="7" /> <caret line="116" column="18" selection-start-line="116" selection-start-column="18" selection-end-line="116" selection-end-column="18" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/model/model.go"> <entry file="file://$PROJECT_DIR$/model/model.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374"> <state relative-caret-position="989">
<caret line="50" column="5" selection-start-line="50" selection-start-column="5" selection-end-line="50" selection-end-column="5" /> <caret line="50" column="5" selection-start-line="50" selection-start-column="5" selection-end-line="50" selection-end-column="5" />
<folding> <folding>
<element signature="e#15#109#0" expanded="true" /> <element signature="e#15#109#0" expanded="true" />
@ -270,51 +256,63 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/controller/user.go"> <entry file="file://C:/Go/src/database/sql/sql.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="439"> <state relative-caret-position="59179">
<caret line="116" column="18" selection-start-line="116" selection-start-column="18" selection-end-line="116" selection-end-column="18" /> <caret line="2586" column="5" selection-start-line="2586" selection-start-column="5" selection-end-line="2586" selection-end-column="5" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://C:/Go/src/database/sql/sql.go"> <entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state relative-caret-position="285"> <state split_layout="SPLIT">
<caret line="2586" column="5" selection-start-line="2586" selection-start-column="5" selection-end-line="2586" selection-end-column="5" /> <first_editor />
<second_editor />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/db/db.go"> <entry file="file://$PROJECT_DIR$/db/db.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285"> <state relative-caret-position="285">
<caret line="124" column="70" selection-start-line="124" selection-start-column="70" selection-end-line="124" selection-end-column="70" /> <caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/model/blog.go"> <entry file="file://C:/Go/src/strconv/atoi.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391"> <state relative-caret-position="187">
<caret line="17" column="10" selection-start-line="17" selection-start-column="10" selection-end-line="17" selection-end-column="10" /> <caret line="201" column="5" selection-start-line="201" selection-start-column="5" selection-end-line="201" selection-end-column="5" />
<folding>
<element signature="e#15#42#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/controller/blog.go"> <entry file="file://$PROJECT_DIR$/user.yaml">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="207"> <state relative-caret-position="299">
<caret line="9" column="10" selection-start-line="9" selection-start-column="10" selection-end-line="9" selection-end-column="10" /> <caret line="13" column="22" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
<folding>
<element signature="e#20#78#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/main.go"> <entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="194"> <state relative-caret-position="202">
<caret line="91" column="24" selection-start-line="91" selection-start-column="17" selection-end-line="91" selection-end-column="24" /> <caret line="92" column="46" selection-start-line="92" selection-start-column="46" selection-end-line="92" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/controller/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="248">
<caret line="78" column="19" selection-start-line="78" selection-start-column="19" selection-end-line="78" selection-end-column="19" />
<folding>
<element signature="e#20#97#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/model/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="115">
<caret line="5" selection-start-line="5" selection-end-line="5" />
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@ -1,11 +1,59 @@
package controller package controller
import ( import (
"background/db"
"background/logs" "background/logs"
"background/model" "background/model"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strconv"
) )
func GetPageParaFromQuery(c *gin.Context) (int,int){
limit := c.Query("limit")
offset := c.Query("offset")
iLmit,e := strconv.Atoi(limit)
if nil != e{
return 0,0
}
iOffset,e := strconv.Atoi(offset)
if nil != e{
return 0,0
}
return iLmit,iOffset
}
func GetArticles(c *gin.Context) {
type ReqArticles struct {
Name string `json:"name"`
}
var req ReqArticles
rsp := RespBase{"ERR",-1,nil}
defer func() {
c.JSON(200,rsp)
}()
e := c.BindJSON(&req)
if nil != e{
logs.Error(e.Error())
return
}
article := []model.Doc{}
limit,offset := GetPageParaFromQuery(c)
var sql string
if req.Name != ""{
sql = fmt.Sprintf("select * from doc where doc.name like '%%%s%%' limit %d offset %d",req.Name,limit,offset*limit)
}else{
sql = fmt.Sprintf("select * from doc limit %d offset %d",limit,offset*limit)
}
e = db.GetMysqlClient().Query2(sql,&article)
if nil != e{
logs.Error(e.Error())
return
}
rsp.Data = article
rsp.Status = 0
rsp.Msg = "OK"
}
func AddArticle(c *gin.Context) { func AddArticle(c *gin.Context) {
rsp := RespBase{Msg:"FAIL", Status:210,} rsp := RespBase{Msg:"FAIL", Status:210,}
@ -24,6 +72,10 @@ func AddArticle(c *gin.Context) {
logs.Error(er.Error()) logs.Error(er.Error())
return return
} }
if req.Title == ""{
rsp.Msg = "title required"
return
}
e := model.CreateDoc( e := model.CreateDoc(
model.Doc{ model.Doc{
Type:req.Type, Type:req.Type,
@ -39,3 +91,14 @@ func AddArticle(c *gin.Context) {
rsp.Msg = "OK" rsp.Msg = "OK"
rsp.Status = 0 rsp.Status = 0
} }
func ArticlesType(c *gin.Context) {
rsp := RespBase{Msg:"FAIL", Status:210,}
defer func() {
c.JSON(200,rsp)
}()
rsp.Data = model.GetArticlesType()
rsp.Msg = "OK"
rsp.Status = 0
}

View File

@ -89,8 +89,9 @@ func main() {
/** 修改密码**/ /** 修改密码**/
api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd) api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd)
api.POST("articles",controller.GetArticles)
api.PUT("article",controller.AddArticle) // 添加文章 api.PUT("article",controller.AddArticle) // 添加文章
api.GET("article_type",controller.ArticlesType) //获取所有文章分类
} }
e := r.Run(":" + strconv.Itoa(config.GetPort())) e := r.Run(":" + strconv.Itoa(config.GetPort()))

View File

@ -3,7 +3,6 @@ package model
import ( import (
"background/db" "background/db"
"background/logs" "background/logs"
"errors"
"fmt" "fmt"
) )
@ -15,12 +14,26 @@ type Doc struct {
Author string `sql:"author" json:"author"` Author string `sql:"author" json:"author"`
} }
func CreateDoc(doc Doc) error { type ArticleType struct {
if doc.ID == 0{ Id int64 `sql:"id" json:"id"`
return errors.New("wrong primary key") Name string `sql:"name" json:"name"`
Author string `sql:"author" json:"author"`
}
func GetArticlesType() []ArticleType{
ret := []ArticleType{}
sql := fmt.Sprintf("select * from article_type");
e := db.GetBlogMysql().Query2(sql,&ret)
if nil != e{
logs.Error(e.Error())
return nil
} }
return ret
}
func CreateDoc(doc Doc) error {
sql := fmt.Sprintf("insert into doc(title,type,content,author) values ('%s','%d','%s','%s')",doc.Title,doc.Type,doc.Content,doc.Author) sql := fmt.Sprintf("insert into doc(title,type,content,author) values ('%s','%d','%s','%s')",doc.Title,doc.Type,doc.Content,doc.Author)
_,e := db.GetMysqlClient().Query(sql) _,e := db.GetBlogMysql().Query(sql)
if nil != e{ if nil != e{
logs.Error(e.Error()) logs.Error(e.Error())
return e return e

View File

@ -18,10 +18,10 @@ mysql:
max_open: 100 max_open: 100
MaxIdle: 99 MaxIdle: 99
mysql2: mysql2:
addr: 118.24.238.198 addr: 35.240.179.248
user: server user: root
password: server password: a7458969
db: background db: blog
max_open: 100 max_open: 100
MaxIdle: 99 MaxIdle: 99