添加分类管理实现。

master
a7458969 2020-01-25 22:26:41 +08:00
parent 3b2aaa604e
commit dc1e6c6f5b
4 changed files with 15 additions and 7 deletions

View File

@ -65,6 +65,9 @@ type MongoConfig struct {
var gConf ConfAPI
func ApiConfig() ConfAPI{
return gConf
}
func Init(path string) error {
file, e := os.Open(path)
if nil != e {

View File

@ -23,8 +23,13 @@ func Init() {
blogConf := config.GetMysqlBlogConfig()
//InitMongoDb()
blogDb = Database{Type: string(""), DB: initMysql(blogConf)}
if config.ApiConfig().RunMode == "debug"{
gDb = Database{Type: string(""), DB: initMysql(mysqlconf)}
}else{
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
}
}
func initMysql(mysqlconf *config.MysqlConfig) *sql.DB {
@ -44,8 +49,8 @@ func initMysql(mysqlconf *config.MysqlConfig) *sql.DB {
}
return _db
}
func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile("pem/ca.pem")
if err != nil {
@ -65,7 +70,6 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
Certificates: clientCert,
InsecureSkipVerify: true,
})
cnn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8&tls=custom", mysqlconf.UserName, mysqlconf.Password,
mysqlconf.Addr, mysqlconf.Db)
log.Print("Connect to mysql " + cnn)
@ -73,7 +77,6 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
if err != nil {
fmt.Println("connect sql server ", err.Error())
os.Exit(200)
}
e := _db.Ping()
if nil != e {

View File

@ -110,7 +110,6 @@ func main() {
api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片
api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型
}
e := r.Run(":" + strconv.Itoa(config.GetPort()))

View File

@ -4,6 +4,7 @@ import (
"background/db"
"background/logs"
"fmt"
"qiniupkg.com/x/log.v7"
"strings"
)
@ -17,20 +18,22 @@ type Doc struct {
type ArticleType struct {
Id int64 `sql:"id" json:"id"`
Name string `sql:"name" json:"name"`
Name string `sql:"type_name" json:"type_name"`
Author string `sql:"author" json:"author"`
}
func GetArticlesType() []ArticleType {
ret := []ArticleType{}
sql := fmt.Sprintf("select * from article_type")
sql := fmt.Sprintf("select * from doc_type")
e := db.GetBlogMysql().Query2(sql, &ret)
log.Print(ret)
if nil != e {
logs.Error(e.Error())
return nil
}
return ret
}
func CreateDoc(doc Doc) error {
sql := fmt.Sprintf(`INSERT INTO doc ( doc.title, doc.content, doc.author, doc.type ) SELECT
'%s',