intimate/store.go
2020-07-07 12:04:05 +08:00

41 lines
825 B
Go

package main
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 //
}
// 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) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt())
if err != nil {
log.Fatalln(err)
}
}