添加mysql ssl登录

master
a74589669 2019-06-30 22:59:00 +08:00
parent 6466e9a6e3
commit 6f17a4a1be
9 changed files with 271 additions and 215 deletions

View File

@ -2,12 +2,12 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="882ad3e2-74c3-43b0-b9f1-5497ec2bf4ca" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/deploy.bat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/id_rsa" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/config/config.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/controller/user.go" beforeDir="false" afterPath="$PROJECT_DIR$/controller/user.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$/model/blog.go" beforeDir="false" afterPath="$PROJECT_DIR$/model/blog.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/model/model.go" beforeDir="false" afterPath="$PROJECT_DIR$/model/model.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/user.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/user.yaml" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -20,44 +20,49 @@
<session id="-1603790603">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="8" />
<entry key="project.open.time.1" value="1" />
<entry key="project.open.time.10" value="1" />
<entry key="project.closed" value="16" />
<entry key="project.open.time.1" value="4" />
<entry key="project.open.time.10" value="3" />
<entry key="project.open.time.11" value="1" />
<entry key="project.open.time.12" value="1" />
<entry key="project.open.time.14" value="1" />
<entry key="project.open.time.17" value="1" />
<entry key="project.open.time.20" value="1" />
<entry key="project.open.time.24" value="1" />
<entry key="project.open.time.3" value="1" />
<entry key="project.open.time.31" value="1" />
<entry key="project.open.time.4" value="1" />
<entry key="project.open.time.7" value="2" />
<entry key="project.open.time.8" value="3" />
<entry key="project.open.time.7" value="3" />
<entry key="project.open.time.8" value="4" />
<entry key="project.open.time.9" value="2" />
<entry key="project.opened" value="17" />
<entry key="project.opened" value="25" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="go" value="377" />
<entry key="yaml" value="97" />
<entry key="bat" value="136" />
<entry key="go" value="647" />
<entry key="yaml" value="112" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Go" value="377" />
<entry key="YAML" value="97" />
<entry key="Bat" value="136" />
<entry key="Go" value="647" />
<entry key="YAML" value="112" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="go" value="13" />
<entry key="bat" value="1" />
<entry key="go" value="21" />
<entry key="yaml" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Go" value="13" />
<entry key="Bat" value="1" />
<entry key="Go" value="21" />
<entry key="YAML" value="1" />
</counts>
</usages-collector>
@ -65,89 +70,32 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="44" column="41" selection-start-line="44" selection-start-column="41" selection-end-line="44" selection-end-column="41" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/config/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="352">
<caret line="21" column="26" selection-start-line="21" selection-start-column="26" selection-end-line="21" selection-end-column="26" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/db/sqlManager.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="395">
<caret line="36" column="20" selection-start-line="36" selection-start-column="20" selection-end-line="36" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://F:/程序/GOROOT/src/crypto/tls/tls.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3630">
<caret line="177" column="5" selection-start-line="177" selection-start-column="5" selection-end-line="177" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/vendor/github.com/go-sql-driver/mysql/utils.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="880">
<caret line="53" column="32" selection-start-line="53" selection-start-column="22" selection-end-line="53" selection-end-column="32" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://F:/程序/GOROOT/src/database/sql/sql.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="12804">
<caret line="594" column="5" selection-start-line="594" selection-start-column="5" selection-end-line="594" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/user.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="484">
<caret line="22" column="11" selection-start-line="22" selection-start-column="11" selection-end-line="22" selection-end-column="11" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/model/model.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="946">
<caret line="50" column="61" selection-start-line="50" selection-start-column="61" selection-end-line="50" selection-end-column="61" />
<state relative-caret-position="44">
<caret line="2" column="7" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
<folding>
<element signature="e#15#109#0" expanded="true" />
<element signature="e#14#220#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/model/blog.go">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/controller/user.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="616">
<caret line="32" column="8" selection-start-line="32" selection-start-column="8" selection-end-line="32" selection-end-column="8" />
<folding>
<element signature="e#15#68#0" expanded="true" />
</folding>
<state relative-caret-position="128">
<caret line="84" column="25" selection-start-line="84" selection-end-line="85" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/utils/base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="4" column="5" selection-start-line="4" selection-start-column="5" selection-end-line="4" selection-end-column="5" />
</state>
</provider>
</entry>
@ -157,6 +105,69 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2772">
<caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
<folding>
<element signature="e#22#122#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/db/sqlManager.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="594">
<caret line="40" column="17" selection-start-line="40" selection-start-column="17" selection-end-line="40" selection-end-column="17" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/model/model.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="11" column="5" selection-start-line="11" selection-start-column="5" selection-end-line="11" selection-end-column="5" />
<folding>
<element signature="e#15#109#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/deploy.bat">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="7" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/user.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="352">
<caret line="16" column="16" selection-end-line="36" selection-end-column="14" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/model/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="22" column="14" selection-start-line="22" selection-start-column="14" selection-end-line="22" selection-end-column="14" />
<folding>
<element signature="e#15#68#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/controller/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2046">
<caret line="100" column="21" selection-start-line="100" selection-start-column="21" selection-end-line="100" selection-end-column="21" />
</state>
</provider>
</entry>
@ -186,11 +197,13 @@
<option value="$PROJECT_DIR$/controller/blog.go" />
<option value="$PROJECT_DIR$/model/blog.go" />
<option value="$PROJECT_DIR$/model/model.go" />
<option value="$PROJECT_DIR$/config/config.go" />
<option value="$PROJECT_DIR$/main.go" />
<option value="$PROJECT_DIR$/vendor/github.com/go-sql-driver/mysql/utils.go" />
<option value="$PROJECT_DIR$/db/sqlManager.go" />
<option value="$PROJECT_DIR$/config/config.go" />
<option value="$PROJECT_DIR$/deploy.bat" />
<option value="$PROJECT_DIR$/user.yaml" />
<option value="$PROJECT_DIR$/db/sqlManager.go" />
<option value="$PROJECT_DIR$/controller/user.go" />
</list>
</option>
</component>
@ -219,6 +232,11 @@
<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>
</expand>
<select />
</subPane>
@ -234,12 +252,17 @@
<property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.vendoring.notification.had.been.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../damon" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="go.sdk" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\project\golang\src\background" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
@ -270,14 +293,14 @@
</recent_temporary>
</component>
<component name="ToolWindowManager">
<frame x="-8" y="32" width="2576" height="1056" extended-state="6" />
<frame x="-7" y="40" width="1294" height="1047" extended-state="7" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.11535402" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.122564934" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32915717" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32915717" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.3997722" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -286,7 +309,7 @@
<window_info anchor="bottom" id="Docker" order="8" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="9" />
<window_info anchor="bottom" id="Database Changes" order="10" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Terminal" order="11" weight="0.32915717" />
<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="Ant Build" order="1" weight="0.25" />
@ -330,20 +353,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/controller/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="792">
<caret line="43" column="10" selection-start-line="43" selection-start-column="10" selection-end-line="43" selection-end-column="10" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/controller/user.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2002">
<caret line="116" column="18" selection-start-line="116" selection-start-column="18" selection-end-line="116" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../gopkg.in/mgo.v2/session.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3476">
@ -358,13 +367,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="352">
<caret line="21" column="26" selection-start-line="21" selection-start-column="26" selection-end-line="21" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://F:/程序/GOROOT/src/crypto/tls/tls.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3630">
@ -381,35 +383,35 @@
</entry>
<entry file="file://F:/程序/GOROOT/src/database/sql/sql.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="12804">
<state relative-caret-position="477">
<caret line="594" column="5" selection-start-line="594" selection-start-column="5" selection-end-line="594" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/user.yaml">
<entry file="file://$PROJECT_DIR$/db/mssql.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/config/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="484">
<caret line="22" column="11" selection-start-line="22" selection-start-column="11" selection-end-line="22" selection-end-column="11" />
<state relative-caret-position="154">
<caret line="67" column="9" selection-start-line="67" selection-start-column="9" selection-end-line="67" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/model/model.go">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="946">
<caret line="50" column="61" selection-start-line="50" selection-start-column="61" selection-end-line="50" selection-end-column="61" />
<state relative-caret-position="44">
<caret line="2" column="7" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
<folding>
<element signature="e#15#109#0" expanded="true" />
<element signature="e#14#220#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/model/blog.go">
<entry file="file://$PROJECT_DIR$/utils/base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="616">
<caret line="32" column="8" selection-start-line="32" selection-start-column="8" selection-end-line="32" selection-end-column="8" />
<folding>
<element signature="e#15#68#0" expanded="true" />
</folding>
<state relative-caret-position="88">
<caret line="4" column="5" selection-start-line="4" selection-start-column="5" selection-end-line="4" selection-end-column="5" />
</state>
</provider>
</entry>
@ -417,20 +419,64 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2772">
<caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
<folding>
<element signature="e#22#122#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/db/sqlManager.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="395">
<caret line="36" column="20" selection-start-line="36" selection-start-column="20" selection-end-line="36" selection-end-column="20" />
<state relative-caret-position="594">
<caret line="40" column="17" selection-start-line="40" selection-start-column="17" selection-end-line="40" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.go">
<entry file="file://$PROJECT_DIR$/model/model.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="44" column="41" selection-start-line="44" selection-start-column="41" selection-end-line="44" selection-end-column="41" />
<state relative-caret-position="88">
<caret line="11" column="5" selection-start-line="11" selection-start-column="5" selection-end-line="11" selection-end-column="5" />
<folding>
<element signature="e#15#109#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/deploy.bat">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/user.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="352">
<caret line="16" column="16" selection-end-line="36" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/model/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="22" column="14" selection-start-line="22" selection-start-column="14" selection-end-line="22" selection-end-column="14" />
<folding>
<element signature="e#15#68#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/controller/blog.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2046">
<caret line="100" column="21" selection-start-line="100" selection-start-column="21" selection-end-line="100" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/controller/user.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="128">
<caret line="84" column="25" selection-start-line="84" selection-end-line="85" />
</state>
</provider>
</entry>

View File

@ -21,8 +21,10 @@ type ConfAPI struct {
Mysql MysqlConfig `yaml:"mysql"` // 认证配置
Mysql1 MysqlConfig `yaml:"mysql1"` // 认证配置
MongoConf MongoConfig `yaml:"mongo"`
CaCert string `yaml:"ca_cert"`
init bool
CaCert string `yaml:"ca_cert"`
ClientCert string `yaml:"client_cert"`
ClientKey string `yaml:"client_key"'`
init bool
}
type EntityRedis struct {

View File

@ -6,6 +6,7 @@ import (
"background/model"
"fmt"
"github.com/gin-gonic/gin"
"qiniupkg.com/x/log.v7"
"strconv"
)
@ -55,6 +56,39 @@ func GetArticles(c *gin.Context) {
rsp.Msg = "OK"
}
func GetArticle(c *gin.Context) {
resp := RespBase{Msg:"FAIL",Status: 211}
sid := c.Param("id")
var id int
var err error
defer func() {
c.JSON(200,resp)
}()
if sid == ""{
return
}else{
id,err = strconv.Atoi(sid)
if nil != err{
return
}
}
query := fmt.Sprintf("select * from doc where doc.id = '%d'",id)
docs := []model.Doc{}
e := db.GetMysqlClient().Query2(query,&docs)
if nil != e{
log.Print(e.Error())
return
}
if len(docs) > 0{
resp.Data = docs[0]
resp.Status = 0
resp.Msg = "OK"
}
}
func AddArticle(c *gin.Context) {
rsp := RespBase{Msg:"FAIL", Status:210,}
type ReqAddArticle struct {

View File

@ -123,6 +123,14 @@ func (this *UserController) ModifyPasswd(c *gin.Context) {
resp.Status = 0
}
// DelUser godoc
// @Summary Delete a user from database
// @Description you must have a token in your parameter
// @Accept json
// @Produce json
// @Param q query string false "name search by q"
// @Success 200 {array} util.RespBase
// @Router /setUser [get]
func (this *UserController) DelUser(c *gin.Context) {
}
@ -302,9 +310,10 @@ func (this *UserController) Login(c *gin.Context) {
h.Write([]byte(req.UserPwd)) // 需要加密的字符串为 123456
passmd5 := h.Sum(nil)
var result []model.Users
er := db.GetMysqlClient().Query2("select * from users where user_name = ?",
&result, req.UserName)
query := fmt.Sprintf("select * from users where user_name = '%s'",req.UserName)
er := db.GetMysqlClient().Query2(query,
&result)
logs.Debug("sql query:" + query)
if nil != er {
log.Println(er.Error())
}

View File

@ -22,8 +22,8 @@ func Init() {
mysqlconf := config.GetMysqlConfig()
blogConf := config.GetMysqlBlogConfig()
InitMongoDb()
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
blogDb = Database{Type: string(""), DB: initMysql(blogConf)}
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
}
@ -47,7 +47,7 @@ func initMysql(mysqlconf *config.MysqlConfig) *sql.DB {
func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile("D:\\data\\腾讯云测试服mysql证书\\ca.pem")
pem, err := ioutil.ReadFile("pem/ca.pem")
if err != nil {
log.Fatal(err)
}
@ -55,7 +55,7 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
log.Fatal("Failed to append PEM.")
}
clientCert := make([]tls.Certificate, 0, 1)
certs, err := tls.LoadX509KeyPair("D:\\data\\腾讯云测试服mysql证书\\client-cert.pem", "D:\\data\\腾讯云测试服mysql证书\\client-key.pem")
certs, err := tls.LoadX509KeyPair("pem/client-cert.pem", "pem/client-key.pem")
if err != nil {
log.Fatal(err)
}

11
deploy.bat Normal file
View File

@ -0,0 +1,11 @@
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build ./
scp -i ./id_rsa background ubuntu@118.24.238.198:/home/ubuntu/api/bin/userapi
scp -i ./id_rsa user.yaml ubuntu@118.24.238.198:/home/ubuntu/api/bin/user.yaml
scp -i ./id_rsa pem/ca.pem ubuntu@118.24.238.198:/home/ubuntu/api/bin/pem/ca.pem
scp -i ./id_rsa pem/client-cert.pem ubuntu@118.24.238.198:/home/ubuntu/api/bin/pem/client-cert.pem
scp -i ./id_rsa pem/client-key.pem ubuntu@118.24.238.198:/home/ubuntu/api/bin/pem/client-key.pem

View File

@ -92,8 +92,9 @@ func main() {
/** 修改密码**/
api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd)
api.GET("/article/:id",controller.GetArticle)
api.POST("articles",controller.GetArticles)
api.PUT("article",controller.AddArticle) // 添加文章
api.PUT("/article",controller.AddArticle) // 添加文章
api.GET("article_type",controller.ArticlesType) //获取所有文章分类
}

View File

@ -7,36 +7,43 @@ import (
)
type Doc struct {
ID int64 `sql:"id" json:"id"`
Title string `sql:"title" json:"title"`
Type int64 `sql:"type" json:"type"`
ID int64 `sql:"id" json:"id"`
Title string `sql:"title" json:"title"`
Type int64 `sql:"type" json:"type"`
Content string `sql:"content" json:"content"`
Author string `sql:"author" json:"author"`
Author string `sql:"author" json:"author"`
}
type ArticleType struct {
Id int64 `sql:"id" json:"id"`
Name string `sql:"name" json:"name"`
Author string `sql:"author" json:"author"`
Id int64 `sql:"id" json:"id"`
Name string `sql:"name" json:"name"`
Author string `sql:"author" json:"author"`
}
func GetArticlesType() []ArticleType{
func GetArticlesType() []ArticleType {
ret := []ArticleType{}
sql := fmt.Sprintf("select * from article_type");
e := db.GetBlogMysql().Query2(sql,&ret)
if nil != e{
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')
on duplicate key update title = '%s',type = '%d',content = '%s',author = '%s';`,doc.Title,doc.Type,doc.Content,doc.Author,doc.Title,doc.Type,doc.Content,doc.Author)
_,e := db.GetMysqlClient().Query(sql)
if nil != e{
sql := fmt.Sprintf(`INSERT INTO doc ( doc.title, doc.content, doc.author, doc.type ) SELECT
'%s',
'%s',
'%s',
%d
FROM
DUAL
WHERE
NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, doc.Content, doc.Author, doc.Type,doc.Title)
_, e := db.GetMysqlClient().Query(sql)
if nil != e {
logs.Error(e.Error())
return e
}
return nil
}
}

View File

@ -1,54 +0,0 @@
listen_api: 4596
runmode: debug
max_conn: 1500
logs:
dir: "/var/log/user"
file: "user.log"
level: 1
savefile: false
redis1:
addr: 118.24.238.198:16379
password:
db: 1
mysql:
addr: 118.24.238.198
user: caiyu
password: 123456
db: background
max_open: 100
MaxIdle: 99
mysql1:
addr: 127.0.0.1
user: root
password:
db: blog
max_open: 100
MaxIdle: 99
mongo:
addr: 118.24.238.198
port: 27017
user: root
password: root
db: test
max_open: 100
MaxIdle: 99
ca_cert: "
-----BEGIN CERTIFICATE-----
MIIDAzCCAeugAwIBAgIBATANBgkqhkiG9w0BAQsFADA8MTowOAYDVQQDDDFNeVNR
TF9TZXJ2ZXJfNS43LjIzX0F1dG9fR2VuZXJhdGVkX0NBX0NlcnRpZmljYXRlMB4X
DTE5MDYwNDE2NDE1N1oXDTI5MDYwMTE2NDE1N1owPDE6MDgGA1UEAwwxTXlTUUxf
U2VydmVyXzUuNy4yM19BdXRvX0dlbmVyYXRlZF9DQV9DZXJ0aWZpY2F0ZTCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJjj52pBNXVoBFTiE72puVNcxGAO
b23PLrjA1ezkLJLDhZ0OVhNviwxeRGItlhSR7fubXI3IWd/vQ2xFlFwJISar91e6
dUT8D+j2nXBcZhAzXRvghSlBwm9hiFpTWfcfMK3JqqSknCtTvFfkdqioabJ0evMO
CCjtjA17rHi8UJa5EU+W0kBOFIKRQmkjFTB94zdvzcBmIVk5pPXdum+JWX25PGc9
F+7x4NJ2TsChuA5Pt460+Q8yyzR1LBECZHSbk9AGzh1zR6qR2qVPvSXtOpeVezDq
f5iBPiqYHl9sbpZ73jjm4IY3PDsBdsKGoucmRy+wfARo3qmnLm6ejtglwf8CAwEA
AaMQMA4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAPz5Emud9fGJv
rBWEVLVtSYTLV6zfmV0iHP/ABU4J/460u6Rw+yAwuSvJEZy5h7/WkZ4t3sxBCu5i
OZ0JdiJWZLOVflBBSGQ0DJEyjiP4bqWHljwf4KW7Q8UTv1rBmSz+kgnNuEdlQx4F
TyEd/URi1888h1M/IjSw+5NN5xb8Zs+j9flEFpS/l33WBhRPeCBBTXqZFeOflqCq
s04QNvfpr91LHG7oQ0bzpkYop4tMaDC7F6nyOZnTBBkZGDcSkCYdIEzYxuYUuyp2
OaN8tRmoZsleJaKgsrTV7owbOP8nShp/GYJnUc5qG74Xtb3CTYx43tkPgFSmR+2/
VAYNsNQ4mw==
-----END CERTIFICATE-----"