Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["notice_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["notice.go"],
importpath = "go-common/app/interface/main/app-resource/dao/notice",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//app/interface/main/app-resource/model/notice: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"],
)

View File

@@ -0,0 +1,58 @@
package notice
import (
"context"
"time"
"go-common/app/interface/main/app-resource/conf"
"go-common/app/interface/main/app-resource/model/notice"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_getSQL = `SELECT id,plat,title,content,build,conditions,area,url,type,ef_time,ex_time FROM notice WHERE state=1 AND ef_time<? AND ex_time>? ORDER BY mtime DESC`
)
// Dao is notice dao.
type Dao struct {
db *sql.DB
get *sql.Stmt
}
// New new a notice dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
db: sql.NewMySQL(c.MySQL.Show),
}
d.get = d.db.Prepared(_getSQL)
return
}
// GetAll get all notice data.
func (d *Dao) All(ctx context.Context, now time.Time) (res []*notice.Notice, err error) {
rows, err := d.get.Query(ctx, now, now)
if err != nil {
log.Error("query error (%v)", err)
return
}
defer rows.Close()
res = []*notice.Notice{}
for rows.Next() {
b := &notice.Notice{}
if err = rows.Scan(&b.ID, &b.Plat, &b.Title, &b.Content, &b.Build, &b.Condition, &b.Area, &b.URI, &b.Type, &b.Start, &b.End); err != nil {
log.Error("rows.Scan err (%v)", err)
return nil, err
}
res = append(res, b)
}
return
}
// Close close memcache resource.
func (dao *Dao) Close() {
if dao.db != nil {
dao.db.Close()
}
}

View File

@@ -0,0 +1,37 @@
package notice
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/app-resource/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
dir, _ := filepath.Abs("../../cmd/app-resource-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func TestAll(t *testing.T) {
Convey("get All all", t, func() {
res, err := d.All(ctx(), time.Now())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}