intimate/store.go

37 lines
769 B
Go

package main
import (
"database/sql"
"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) {
store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt())
}