intimate/store.go
2020-07-07 18:39:24 +08:00

44 lines
978 B
Go

package intimate
import (
"database/sql"
"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())
if err != nil {
log.Fatalln(err)
}
}