Skip to content

Commit

Permalink
Fix prototype bug (#18)
Browse files Browse the repository at this point in the history
* fix:     has scope: 'prototype' and arguments use  @{SendEmail()} error panic: runtime error: invalid memory address or nil pointer dereference

* fix: PackageName is empty

Co-authored-by: wuji <wuji@gaoding.com>
  • Loading branch information
cq-z and wuji committed Feb 26, 2021
1 parent 832e079 commit 9912c52
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions dingotest/dingo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@ services:
type: '*HTTPSignerClient'
properties:
CreateSigner: '@{Signer}'

CustomerWelcomePrototype:
type: '*CustomerWelcome'
returns: NewCustomerWelcome(@{SendEmail})
arguments:
appid: 'string'
scope: 'prototype'
CustomerWelcomePrototype2:
type: '*CustomerWelcome'
returns: NewCustomerWelcome(@{SendEmail})
arguments:
canaryConfig: '*v1.ObjectMetaAccessor'
scope: 'prototype'
import:
- 'k8s.io/apimachinery/pkg/apis/meta/v1'
3 changes: 3 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (service *Service) astFunctionBody(file *File, services Services, name, ser
if name != "" && service.Scope == ScopePrototype {
var arguments []string
for _, dep := range service.Returns.Dependencies() {
if dep[len(dep)-1:]!=")" {
dep = dep+"()"
}
arguments = append(arguments, fmt.Sprintf("container.Get%s", dep))
}
arguments = append(arguments, service.Arguments.Names()...)
Expand Down
4 changes: 3 additions & 1 deletion type.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (ty Type) LocalPackageName() string {

pkgNameParts := strings.Split(ty.UnversionedPackageName(), "/")
lastPart := pkgNameParts[len(pkgNameParts)-1]

if lastPart == "" {
lastPart = ty.PackageName()
}
return strings.Replace(lastPart, "-", "_", -1)
}

Expand Down

0 comments on commit 9912c52

Please sign in to comment.