Skip to content

Commit

Permalink
Fix 110, merge go mod and add version flag to iocli (#111)
Browse files Browse the repository at this point in the history
* fix: package script

* Fix; issue110, add version in root pkg and iocli

* Fix: add back gen-all and test-all command in release-all

* Fix: linter problem

* Fix: rmq alias

* Fix: update ci linter

* Fix: add sleep time to wati for server starting

* Fix: re push

* fix: retry

* Fix: signal bug

* Fix: fix trace stop bug

* Fix: Version ut
  • Loading branch information
LaurenceLiZhixin authored Jul 29, 2022
1 parent 278a4e6 commit fc3192e
Show file tree
Hide file tree
Showing 32 changed files with 856 additions and 5,168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# If you want to matrix build , you can append the following list.
matrix:
go_version:
- 1.17
- 1.18
os:
- ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
strategy:
matrix:
golang:
- 1.17
- 1.18
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.44.2
version: v1.46.1
args: --timeout=10m
skip-go-installation: true
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ gen-all: proto-gen
sudo make imports

tidy-all:
cd extension && go mod tidy -compat=1.17
cd example && go mod tidy -compat=1.17
cd iocli && go mod tidy -compat=1.17
go mod tidy -compat=1.17
go mod tidy

imports:
goimports -local github.com/alibaba/ioc-golang -w .
Expand All @@ -28,12 +25,9 @@ lint: tidy-all

test-all:
go test ./... -cover -p 1
cd extension && go test ./... -cover -p 1
cd example && go test ./... -cover -p 1
cd iocli && go test ./... -cover -p 1

release-all: gen-all test-all
mkdir -p .release/ioc-golang
cd iocli && make build-all-platform && mv ./.release ../.release/iocli
cp -r `ls` ./.release/ioc-golang
tar -czvf ./.release/ioc-golang.tar.gz ./.release/ioc-golang
cd ./.release && tar -czvf ./ioc-golang.tar.gz ./ioc-golang
5 changes: 1 addition & 4 deletions aop/common/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ package common

import (
"sync"

"github.com/glory-go/monkey"
)

type StructMetadata struct {
MethodMetadata map[string]*MethodMetadata
}

type MethodMetadata struct {
Guard *monkey.PatchGuard
Lock sync.Mutex
Lock sync.Mutex
}

type AllInterfaceMetadata map[string]*StructMetadata
11 changes: 9 additions & 2 deletions autowire/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package autowire
import (
"fmt"
"reflect"
"sync"

perrors "github.com/pkg/errors"

Expand Down Expand Up @@ -45,16 +46,20 @@ func getWrappedAutowire(autowire Autowire, allAutowires map[string]WrapperAutowi

type WrapperAutowireImpl struct {
Autowire
singletonImpledMap map[string]interface{}
allAutowires map[string]WrapperAutowire
singletonImpledMap map[string]interface{}
singletonImpledMapLock sync.RWMutex
allAutowires map[string]WrapperAutowire
}

// ImplWithParam is used to get impled struct with param
func (w *WrapperAutowireImpl) ImplWithParam(sdID string, param interface{}, withProxy bool) (interface{}, error) {
// 1. check singleton
w.singletonImpledMapLock.RLock()
if singletonImpledPtr, ok := w.singletonImpledMap[sdID]; w.Autowire.IsSingleton() && ok {
w.singletonImpledMapLock.RUnlock()
return singletonImpledPtr, nil
}
w.singletonImpledMapLock.RUnlock()

// 2. factory
impledPtr, err := w.Autowire.Factory(sdID)
Expand Down Expand Up @@ -88,7 +93,9 @@ func (w *WrapperAutowireImpl) ImplWithParam(sdID string, param interface{}, with

// 5. record singleton ptr
if w.Autowire.IsSingleton() {
w.singletonImpledMapLock.Lock()
w.singletonImpledMap[sdID] = impledPtr
w.singletonImpledMapLock.Unlock()
}
return impledPtr, nil
}
Expand Down
4 changes: 3 additions & 1 deletion boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
_ "github.com/alibaba/ioc-golang/extension/imports/boot"
)

const Version = "1.0.0"

func Load(opts ...config.Option) error {
printLogo()
logger.Cyan("Welcome to use ioc-golang!")
logger.Cyan("Welcome to use ioc-golang %s!", Version)

// 1. load config
logger.Blue("[Boot] Start to load ioc-golang config")
Expand Down
6 changes: 5 additions & 1 deletion example/aop/observability/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestObservability(t *testing.T) {
go func() {
app.Run()
}()
time.Sleep(time.Millisecond * 500)
time.Sleep(time.Second * 1)
output, err := iocli_command.Run([]string{"list"}, time.Second)
assert.Nil(t, err)
assert.Equal(t, `github.com/alibaba/ioc-golang/example/aop/observability.App
Expand All @@ -50,6 +50,7 @@ github.com/alibaba/ioc-golang/example/aop/observability.ServiceImpl2

output, err = iocli_command.Run([]string{"monitor", "-i", "3"}, time.Second*4)
assert.Nil(t, err)
t.Log(output)
assert.True(t, strings.Contains(output, `github.com/alibaba/ioc-golang/example/aop/observability.ServiceImpl1.GetHelloString()
Total: 1, Success: 1, Fail: 0, AvgRT: `))
assert.True(t, strings.Contains(output, `us, FailRate: 0.00%
Expand All @@ -68,6 +69,7 @@ Response 1: (string) (len=36) "This is ServiceImpl2, hello laurence"`))

output, err = iocli_command.Run([]string{"monitor", "-i", "3"}, time.Second*4)
assert.Nil(t, err)
t.Log(output)
assert.True(t, strings.Contains(output, `github.com/alibaba/ioc-golang/example/aop/observability.ServiceImpl1.GetHelloString()
Total: 1, Success: 1, Fail: 0, AvgRT: `))
assert.True(t, strings.Contains(output, `us, FailRate: 0.00%
Expand All @@ -76,12 +78,14 @@ Total: 1, Success: 1, Fail: 0, AvgRT: `))

output, err = iocli_command.Run([]string{"trace", "github.com/alibaba/ioc-golang/example/aop/observability.ServiceImpl1", "GetHelloString"}, time.Second*6)
assert.Nil(t, err)
t.Log(output)
assert.True(t, strings.Contains(output, `OperationName: github.com/alibaba/ioc-golang/example/aop/observability.(*serviceImpl2_).GetHelloString, StartTime: `))
assert.True(t, strings.Contains(output, `OperationName: github.com/alibaba/ioc-golang/example/aop/observability.(*serviceImpl1_).GetHelloString, StartTime: `))
assert.True(t, strings.Contains(output, `ReferenceSpans: [{TraceID:`))

output, err = iocli_command.Run([]string{"trace", "github.com/alibaba/ioc-golang/example/aop/observability.ServiceImpl2", "GetHelloString"}, time.Second*6)
assert.Nil(t, err)
t.Log(output)
assert.True(t, strings.Contains(output, `OperationName: github.com/alibaba/ioc-golang/example/aop/observability.(*serviceImpl2_).GetHelloString, StartTime: `))
assert.True(t, !strings.Contains(output, `OperationName: github.com/alibaba/ioc-golang/example/aop/observability.(*serviceImpl1_).GetHelloString, StartTime: `))
assert.True(t, strings.Contains(output, `ReferenceSpans: [{TraceID:`))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc3192e

Please sign in to comment.