Skip to content

Commit

Permalink
Use alias instead of type declaration
Browse files Browse the repository at this point in the history
This avoids the hiding of the underlying type and its methods. A
use case would be to access the methods of `soap.XSDDateTime`.
Consider the following code:

```
type StartDate soap.XSDDateTime

type FooBar struct {
    Date *StartDate
}

...

fooBar := FooBar{}
```

It is not possible to access `foobar.Date.ToGoTime()`. This commit
declares the `StartDate` type as follows:

```
type StartDate = soap.XSDDateTime
```
Which allows the complete access to the underlying type.
  • Loading branch information
koplas committed Oct 9, 2024
1 parent 2a06cec commit 9149b50
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gowsdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestDateTimeType(t *testing.T) {
t.Fatal(err)
}

expected := `type StartDate soap.XSDDateTime`
expected := `type StartDate = soap.XSDDateTime`

if actual != expected {
t.Error("got \n" + actual + " want \n" + expected)
Expand Down
4 changes: 2 additions & 2 deletions types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var typesTmpl = `
{{else}}
type {{$typeName}} interface{}
{{end}}
{{if .Restriction.Enumeration}}
const (
{{with .Restriction}}
Expand All @@ -164,7 +164,7 @@ var typesTmpl = `
{{else}}
{{$type := toGoType .Type .Nillable | removePointerFromType}}
{{if ne ($typeName) ($type)}}
type {{$typeName}} {{$type}}
type {{$typeName}} = {{$type}}
{{if eq ($type) ("soap.XSDDateTime")}}
func (xdt {{$typeName}}) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return soap.XSDDateTime(xdt).MarshalXML(e, start)
Expand Down

0 comments on commit 9149b50

Please sign in to comment.