Create & Init Project...
This commit is contained in:
46
app/interface/main/app-show/dao/audit/BUILD
Normal file
46
app/interface/main/app-show/dao/audit/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 = ["audit_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-show/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["audit.go"],
|
||||
importpath = "go-common/app/interface/main/app-show/dao/audit",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-show/conf:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
65
app/interface/main/app-show/dao/audit/audit.go
Normal file
65
app/interface/main/app-show/dao/audit/audit.go
Normal file
@ -0,0 +1,65 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-show/conf"
|
||||
"go-common/library/database/sql"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
const (
|
||||
_getSQL = "SELECT mobi_app,build FROM audit"
|
||||
)
|
||||
|
||||
// Dao is audit dao.
|
||||
type Dao struct {
|
||||
db *sql.DB
|
||||
audGet *sql.Stmt
|
||||
}
|
||||
|
||||
// New new a audit dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: sql.NewMySQL(c.MySQL.Show),
|
||||
}
|
||||
d.audGet = d.db.Prepared(_getSQL)
|
||||
return
|
||||
}
|
||||
|
||||
// Audits get all audit build.
|
||||
func (d *Dao) Audits(ctx context.Context) (res map[string]map[int]struct{}, err error) {
|
||||
rows, err := d.audGet.Query(ctx)
|
||||
if err != nil {
|
||||
log.Error("query error(%v)", err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
var (
|
||||
mobiApp string
|
||||
build int
|
||||
)
|
||||
res = map[string]map[int]struct{}{}
|
||||
for rows.Next() {
|
||||
if err = rows.Scan(&mobiApp, &build); err != nil {
|
||||
log.Error("rows.Scan error(%v)", err)
|
||||
res = nil
|
||||
return
|
||||
}
|
||||
if plat, ok := res[mobiApp]; ok {
|
||||
plat[build] = struct{}{}
|
||||
} else {
|
||||
res[mobiApp] = map[int]struct{}{
|
||||
build: struct{}{},
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close memcache resource.
|
||||
func (dao *Dao) Close() {
|
||||
if dao.db != nil {
|
||||
dao.db.Close()
|
||||
}
|
||||
}
|
43
app/interface/main/app-show/dao/audit/audit_test.go
Normal file
43
app/interface/main/app-show/dao/audit/audit_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-show/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func ctx() context.Context {
|
||||
return context.Background()
|
||||
}
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../../cmd/app-show-test.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestAudits(t *testing.T) {
|
||||
Convey("Audits", t, func() {
|
||||
res, err := d.Audits(ctx())
|
||||
So(res, ShouldNotBeEmpty)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestClose(t *testing.T) {
|
||||
Convey("Close", t, func() {
|
||||
d.Close()
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user