Skip to content

Commit

Permalink
add assets to dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ixre committed Feb 13, 2021
1 parent d55a727 commit 01af3ba
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ FROM golang:latest AS build
ENV GOPATH=/gobuild
COPY ./app ./app
COPY ./core ./core
COPY ./assets ./assets
COPY ./*.go go.mod LICENSE README.md app.conf ./

#ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.io
RUN rm -rf go.sum && sed -i 's/replace github.com\/ixre/\/\/replace github.com\/ixre/g' go.mod && \
go mod tidy && \
Expand Down
2 changes: 1 addition & 1 deletion app/api/api_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"errors"
"fmt"
"github.com/ixre/gof/api"
"github.com/ixre/gof/log"
"github.com/ixre/gof/storage"
"github.com/ixre/gof/util"
"github.com/ixre/gof/log"
"net/http"
"net/url"
"time"
Expand Down
4 changes: 2 additions & 2 deletions app/restapi/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ package restapi

import (
"github.com/ixre/gof"
"github.com/ixre/gof/log"
"github.com/ixre/gof/storage"
"github.com/labstack/echo/v4"
mw "github.com/labstack/echo/v4/middleware"
"go2o/app/api"
"go2o/core/variable"
"github.com/ixre/gof/log"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -65,7 +65,7 @@ func Run(ch chan bool, app gof.App, port int) {
store = app.Storage()
API_DOMAIN = app.Config().GetString(variable.ApiDomain)
handler := newServe(app.Config(), store)
log.Println("[ Go2o][ API]: api gateway serve on port :"+strconv.Itoa(port))
log.Println("[ Go2o][ API]: api gateway serve on port :" + strconv.Itoa(port))

err := http.ListenAndServe(":"+strconv.Itoa(port), handler)

Expand Down
1 change: 0 additions & 1 deletion core/dao/impl/rbac_dao_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ func (p *rbacDaoImpl) BatchDeletePermRes(where string, v ...interface{}) (int64,
return r, err
}


// Get 用户角色关联
func (p *rbacDaoImpl) GetPermUserRole(primary interface{}) *model.PermUserRole {
e := model.PermUserRole{}
Expand Down
10 changes: 9 additions & 1 deletion core/infrastructure/tool/sensitive/sensitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func Singleton() *SensitiveMap {
return s
}


// 初始化敏感词词典,根据DFA算法构建trie
func initDictionary(dictionaryPath string) *SensitiveMap {
s := &SensitiveMap{
Expand Down Expand Up @@ -149,3 +148,12 @@ func (s *SensitiveMap) FindAllSensitive(text string) map[string]*Target {
}
return ta
}

func (s *SensitiveMap) ReplaceAll(text string,replacement string)string{
match := s.FindAllSensitive(text)
word := text
for k, v := range match {
word = strings.Replace(word, k, strings.Repeat(replacement, v.Len), -1)
}
return word
}
27 changes: 12 additions & 15 deletions core/service/impl/2.rbac_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type rbacServiceImpl struct {
serviceUtil
}


func NewRbacService(s storage.Interface, o orm.Orm, registryRepo registry.IRegistryRepo) *rbacServiceImpl {
return &rbacServiceImpl{
s: s,
Expand Down Expand Up @@ -160,9 +159,8 @@ func (p *rbacServiceImpl) getUserRolesPerm(userId int64) ([]int64, []string) {
return roles, permissions
}


// 移动资源顺序
func (p *rbacServiceImpl) MoveResOrdinal(_ context.Context,r *proto.MoveResOrdinalRequest) (*proto.Result, error) {
func (p *rbacServiceImpl) MoveResOrdinal(_ context.Context, r *proto.MoveResOrdinalRequest) (*proto.Result, error) {
res := p.dao.GetPermRes(r.ResourceId)
if res == nil {
return p.error(errors.New("no such data")), nil
Expand All @@ -175,7 +173,7 @@ func (p *rbacServiceImpl) MoveResOrdinal(_ context.Context,r *proto.MoveResOrdin
s = "sort_num > $1"
}
swapRes := p.dao.GetPermResBy(s+" AND pid = $2 AND depth=$3 AND res_type=$4 ORDER BY sort_num ASC",
res.SortNum,res.Pid, res.Depth, res.ResType)
res.SortNum, res.Pid, res.Depth, res.ResType)
// 交换顺序
if swapRes != nil {
sortNum := swapRes.SortNum
Expand All @@ -184,10 +182,9 @@ func (p *rbacServiceImpl) MoveResOrdinal(_ context.Context,r *proto.MoveResOrdin
p.dao.SavePermRes(res)
p.dao.SavePermRes(swapRes)
}
return p.success(nil),nil
return p.success(nil), nil
}


func (p *rbacServiceImpl) GetUserResource(_ context.Context, r *proto.GetUserResRequest) (*proto.RbacUserResourceResponse, error) {
dst := &proto.RbacUserResourceResponse{}
var resList []*model.PermRes
Expand Down Expand Up @@ -686,7 +683,7 @@ func (p *rbacServiceImpl) SavePermRes(_ context.Context, r *proto.SavePermResReq
}
}
// 上级是否改变
var parentChanged = dst.Pid != r.Pid || (r.Pid !=0 && dst.Depth ==0)
var parentChanged = dst.Pid != r.Pid || (r.Pid != 0 && dst.Depth == 0)
dst.Name = r.Name
dst.ResType = int16(r.ResType)
dst.Pid = r.Pid
Expand All @@ -707,10 +704,10 @@ func (p *rbacServiceImpl) SavePermRes(_ context.Context, r *proto.SavePermResReq
if err != nil {
ret.ErrCode = 1
ret.ErrMsg = err.Error()
}else{
if parentChanged{
} else {
if parentChanged {
depth := p.getResDepth(dst.Pid)
p.updateResDepth(dst,int16(depth))
p.updateResDepth(dst, int16(depth))
}
}
return ret, nil
Expand Down Expand Up @@ -766,7 +763,7 @@ func (p *rbacServiceImpl) QueryResList(_ context.Context, r *proto.QueryPermResR
where += " AND res_type IN(0,2)"
}
//todo: 搜索结果不为pid
arr := p.dao.SelectPermRes(where+ " ORDER BY sort_num ASC,id ASC")
arr := p.dao.SelectPermRes(where + " ORDER BY sort_num ASC,id ASC")
root := proto.SPermRes{}
p.walkPermRes(&root, arr)
ret := &proto.QueryPermResResponse{
Expand Down Expand Up @@ -810,11 +807,11 @@ func (p *rbacServiceImpl) updateUserRoles(userId int64, roles []int64) error {
// 获取资源的深度
func (p *rbacServiceImpl) getResDepth(pid int64) int {
depth := 0
for pid > 0{
v := p.dao.GetPermResBy("id=$1",pid)
if v != nil{
for pid > 0 {
v := p.dao.GetPermResBy("id=$1", pid)
if v != nil {
pid = v.Pid
depth ++
depth++
}
}
return depth
Expand Down
15 changes: 5 additions & 10 deletions core/service/impl/foudation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go2o/core/module"
"go2o/core/module/bank"
"go2o/core/service/proto"
"strings"
)

var _ proto.FoundationServiceServer = new(foundationService)
Expand All @@ -36,18 +35,14 @@ type foundationService struct {

// 检测是否包含敏感词
func (s *foundationService) CheckSensitive(_ context.Context, r *proto.String) (*proto.Bool, error) {
_,b := sensitive.Singleton().CheckSensitive(r.Value)
return &proto.Bool{Value: b},nil
_, b := sensitive.Singleton().CheckSensitive(r.Value)
return &proto.Bool{Value: b}, nil
}

// 替换敏感词
func (s *foundationService) ReplaceSensitive(_ context.Context, r *proto.ReplaceSensitiveRequest) ( *proto.String, error) {
mp := sensitive.Singleton().FindAllSensitive(r.Word)
word := r.Word
for k, _ := range mp {
word = strings.Replace(word, k, r.Replacement, -1)
}
return &proto.String{Value: word}, nil
func (s *foundationService) ReplaceSensitive(_ context.Context, r *proto.ReplaceSensitiveRequest) (*proto.String, error) {
v := sensitive.Singleton().ReplaceAll(r.Word,r.Replacement)
return &proto.String{Value: v}, nil
}

func NewFoundationService(rep valueobject.IValueRepo, registryRepo registry.IRegistryRepo, notifyRepo notify.INotifyRepo) *foundationService {
Expand Down
2 changes: 1 addition & 1 deletion core/service/impl/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func initService(ctx gof.App, db db.Connector, orm orm.Orm, sto storage.Interfac
PortalService = NewPortalService(CommonDao)
QueryService = NewQueryService(orm, sto)
AppService = NewAppService(sto, orm)
RbacService = NewRbacService(sto, orm,registryRepo)
RbacService = NewRbacService(sto, orm, registryRepo)
}

// 服务工具类,实现的服务组合此类,可直接调用其方法
Expand Down
4 changes: 2 additions & 2 deletions go2o-serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func main() {

// 默认的ETCD端点
if len(etcdEndPoints) == 0 {
etcdEndPoints = strings.Split(os.Getenv("GO2O_ETCD_ADDR"),",")
if len(etcdEndPoints) == 0 || etcdEndPoints[0] ==""{
etcdEndPoints = strings.Split(os.Getenv("GO2O_ETCD_ADDR"), ",")
if len(etcdEndPoints) == 0 || etcdEndPoints[0] == "" {
etcdEndPoints = []string{"http://127.0.0.1:2379"}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestGetMember(t *testing.T) {
func TestModifyPwd(t *testing.T) {
repo := ti.Factory.GetMemberRepo()
m := repo.GetMember(2)
newPwd := domain.MemberSha1Pwd(domain.Md5("13268240456"),m.GetValue().Salt)
newPwd := domain.MemberSha1Pwd(domain.Md5("13268240456"), m.GetValue().Salt)
err := m.Profile().ModifyPassword(newPwd, "")
if err != nil {
t.Error(err)
Expand Down
10 changes: 5 additions & 5 deletions tests/service/foundation_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
* history :
*/

func TestCheckSensitive (t *testing.T) {
ret,_ := impl.FoundationService.ReplaceSensitive(context.TODO(),
func TestCheckSensitive(t *testing.T) {
ret, _ := impl.FoundationService.ReplaceSensitive(context.TODO(),
&proto.ReplaceSensitiveRequest{
Word: "共产党是我们唯一的领导政府",
Replacement: "",
Word: "我自愿加入中国共产党,坚持党的领导,守护我们的长城",
Replacement: "*",
})
t.Log(ret.Value)
}
}
2 changes: 1 addition & 1 deletion tests/service/member_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCheckTradePwd(t *testing.T) {
r, _ := impl.MemberService.VerifyTradePwd(context.TODO(),
&proto.PwdVerifyRequest{
MemberId: int64(memberId),
Pwd: pwd,
Pwd: pwd,
})
t.Logf("%#v", r)
}
Expand Down
11 changes: 9 additions & 2 deletions tests/ti/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go2o/core"
"go2o/core/repos"
"go2o/core/service/impl"
"os"
"time"
)

Expand All @@ -37,13 +38,19 @@ func init() {
DialTimeout: 5 * time.Second,
}
confPath := "app.conf"

for {
_, err := os.Stat(confPath)
if err == nil {
break
}
confPath = "../" + confPath
}
app := core.NewApp(confPath, &cfg)
gof.CurrentApp = app
core.Init(app, false, false)
conn := app.Db()
sto := app.Storage()
o := orm.NewOrm(conn.Driver(), conn.Raw())
Factory = (&repos.RepoFactory{}).Init(o, sto)
impl.InitTestService(app, conn, o, sto)
Factory = (&repos.RepoFactory{}).Init(o, sto)
}

0 comments on commit 01af3ba

Please sign in to comment.