intimate/store.go

44 lines
978 B
Go
Raw Normal View History

2020-07-07 10:39:24 +00:00
package intimate
import (
"database/sql"
2020-07-06 09:58:24 +00:00
"log"
"time"
_ "github.com/go-sql-driver/mysql"
)
// ISource 源接口结构
type ISource interface {
GetUrl() string //
GetTargetType() string //
GetSource() sql.NullString //
GetExt() interface{} //
GetUpdateTime() time.Time //
GetOperator() int32 //
GetErrorMsg() sql.NullString //
}
// 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) {
_, 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
}
}