Create & Init Project...
This commit is contained in:
46
app/interface/main/app-feed/dao/game/BUILD
Normal file
46
app/interface/main/app-feed/dao/game/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["dao_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-card/model/card/operate:go_default_library",
|
||||
"//app/interface/main/app-feed/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["dao.go"],
|
||||
importpath = "go-common/app/interface/main/app-feed/dao/game",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-card/model/card/operate:go_default_library",
|
||||
"//app/interface/main/app-feed/conf:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
52
app/interface/main/app-feed/dao/game/dao.go
Normal file
52
app/interface/main/app-feed/dao/game/dao.go
Normal file
@ -0,0 +1,52 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-card/model/card/operate"
|
||||
"go-common/app/interface/main/app-feed/conf"
|
||||
"go-common/library/database/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
_getSQL = "SELECT `id`,`title`,`desc`,`icon`,`cover`,`url_type`,`url_value`,`btn_txt`,`re_type`,`re_value`,`number`,`double_cover` FROM download_card"
|
||||
)
|
||||
|
||||
type Dao struct {
|
||||
db *sql.DB
|
||||
downloadGet *sql.Stmt
|
||||
}
|
||||
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: sql.NewMySQL(c.MySQL.Manager),
|
||||
}
|
||||
// prepare
|
||||
d.downloadGet = d.db.Prepared(_getSQL)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) DownLoad(c context.Context) (dm map[int64]*operate.Download, err error) {
|
||||
rows, err := d.downloadGet.Query(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
dm = map[int64]*operate.Download{}
|
||||
for rows.Next() {
|
||||
d := &operate.Download{}
|
||||
if err = rows.Scan(&d.ID, &d.Title, &d.Desc, &d.Icon, &d.Cover, &d.URLType, &d.URLValue, &d.BtnTxt, &d.ReType, &d.ReValue, &d.Number, &d.DoubleCover); err != nil {
|
||||
return
|
||||
}
|
||||
d.Change()
|
||||
dm[d.ID] = d
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close memcache resource.
|
||||
func (d *Dao) Close() {
|
||||
if d.db != nil {
|
||||
d.db.Close()
|
||||
}
|
||||
}
|
80
app/interface/main/app-feed/dao/game/dao_test.go
Normal file
80
app/interface/main/app-feed/dao/game/dao_test.go
Normal file
@ -0,0 +1,80 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-card/model/card/operate"
|
||||
"go-common/app/interface/main/app-feed/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../../cmd/app-feed-test.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
type args struct {
|
||||
c *conf.Config
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantD *Dao
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotD := New(tt.args.c); !reflect.DeepEqual(gotD, tt.wantD) {
|
||||
t.Errorf("New() = %v, want %v", gotD, tt.wantD)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDao_DownLoad(t *testing.T) {
|
||||
type args struct {
|
||||
c context.Context
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantDm map[int64]*operate.Download
|
||||
wantErr error
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
Convey(tt.name, t, func() {
|
||||
gotDm, err := d.DownLoad(tt.args.c)
|
||||
So(gotDm, ShouldEqual, tt.wantDm)
|
||||
So(err, ShouldEqual, tt.wantErr)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDao_Close(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
d *Dao
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.d.Close()
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user