2020-07-06 08:33:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2020-07-06 09:58:24 +00:00
|
|
|
"log"
|
2020-07-06 08:33:35 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ISource 源接口结构
|
|
|
|
type ISource interface {
|
2020-07-07 10:14:14 +00:00
|
|
|
GetUrl() string //
|
|
|
|
GetTargetType() string //
|
|
|
|
GetSource() sql.NullString //
|
|
|
|
GetExt() interface{} //
|
|
|
|
GetUpdateTime() time.Time //
|
|
|
|
GetOperator() int32 //
|
|
|
|
GetErrorMsg() sql.NullString //
|
|
|
|
|
2020-07-06 08:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store 储存
|
|
|
|
type Store struct {
|
|
|
|
db *sql.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewStore 创建一个存储实例
|
|
|
|
func NewStore() *Store {
|
|
|
|
db, err := sql.Open("mysql", InitConfig.Database.URI)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return &Store{db: db}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save 储存数据
|
|
|
|
func (store *Store) Save(isource ISource) {
|
2020-07-07 10:14:14 +00:00
|
|
|
_, err := store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext, operator, error_msg) values(?,?,?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt(), isource.GetOperator(), isource.GetErrorMsg())
|
2020-07-06 09:58:24 +00:00
|
|
|
if err != nil {
|
2020-07-07 04:04:05 +00:00
|
|
|
log.Fatalln(err)
|
2020-07-06 09:58:24 +00:00
|
|
|
}
|
2020-07-06 08:33:35 +00:00
|
|
|
}
|