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,37 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"app.go",
"service.go",
],
importpath = "go-common/app/admin/main/open/service",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/open/conf:go_default_library",
"//app/admin/main/open/dao:go_default_library",
"//app/admin/main/open/model: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,73 @@
package service
import (
"context"
"crypto/md5"
"encoding/hex"
"math/rand"
"strconv"
"time"
"go-common/app/admin/main/open/model"
"go-common/library/log"
)
// AddApp represents add an app.
func (s *Service) AddApp(c context.Context, appname string) (err error) {
// Generate the secret and key
timestamp := strconv.Itoa((int)(time.Now().Unix()) + rand.Intn(1))
hashsec := md5.New()
hashsec.Write([]byte(timestamp))
appsecret := hex.EncodeToString(hashsec.Sum(nil))
hashkey := md5.New()
timestamp += "biliappkey"
hashkey.Write([]byte(timestamp))
appkey := hex.EncodeToString(hashkey.Sum(nil))
g := &model.App{
AppName: appname,
AppKey: appkey,
AppSecret: appsecret,
Enabled: 1,
}
if err = s.dao.AddApp(c, g); err != nil {
log.Error("s.dao.AddApp(%+v) error(%v)", g, err)
}
return
}
// DelApp represents delete an app.
func (s *Service) DelApp(c context.Context, appid int64) (err error) {
if err = s.dao.DelApp(c, appid); err != nil {
log.Error("s.DelApp(%d) error(%v)", appid, err)
}
return
}
// UpdateApp represents update an app.
func (s *Service) UpdateApp(c context.Context, arg *model.AppParams) (err error) {
if err = s.dao.UpdateApp(c, arg); err != nil {
log.Error("s.UpdateApps id (%d) appname(%s) error", arg.AppID, arg.AppName)
}
return
}
// ListApp represents search an app.
func (s *Service) ListApp(c context.Context, t *model.AppListParams) (res []*model.App, total int64, err error) {
if res, err = s.dao.ListApp(c, t); err != nil {
log.Error("s.dao.ListApp error (%v)", err)
return
}
// output the data
total = int64(len(res))
start := (t.PN - 1) * t.PS
if start >= total {
res = []*model.App{}
return
}
end := start + t.PS
if end > total {
end = total
}
res = res[start:end]
return
}

View File

@ -0,0 +1,33 @@
package service
import (
"context"
"go-common/app/admin/main/open/conf"
"go-common/app/admin/main/open/dao"
)
// Service biz service def.
type Service struct {
c *conf.Config
dao *dao.Dao
}
// New new a Service and return.
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
dao: dao.New(c),
}
return s
}
// Ping check dao health.
func (s *Service) Ping(c context.Context) (err error) {
return s.dao.Ping(c)
}
// Close close all dao.
func (s *Service) Close() {
s.dao.Close()
}