Skip to content

Commit

Permalink
Improve: unmarshal inbound (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaling888 authored Aug 7, 2023
1 parent 54b86ee commit e102539
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions constant/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,25 @@ func (i *Inbound) UnmarshalYAML(unmarshal func(any) error) error {
}

*i = Inbound(inner)
return nil
}
} else {
inner, err := parseInbound(tp)
if err != nil {
return err
}

inner, err := parseInbound(tp)
if err != nil {
return err
*i = Inbound(*inner)
}
*i = Inbound(*inner)

if !supportInboundTypes[i.Type] {
return fmt.Errorf("not support inbound type: %s", i.Type)
}
_, portStr, err := net.SplitHostPort(i.BindAddress)
if err != nil {
return fmt.Errorf("bind address parse error. addr:%s, err:%v", i.BindAddress, err)
}
port, err := strconv.Atoi(portStr)
if err != nil {
return fmt.Errorf("port not a number. addr:%s", i.BindAddress)
return fmt.Errorf("bind address parse error. addr: %s, err: %w", i.BindAddress, err)
}
if port == 0 {
return fmt.Errorf("invalid bind port. addr:%s", i.BindAddress)
port, err := strconv.ParseUint(portStr, 10, 16)
if err != nil || port == 0 {
return fmt.Errorf("invalid bind port. addr: %s", i.BindAddress)
}
return nil
}
Expand Down

0 comments on commit e102539

Please sign in to comment.