api: fix Decode method
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
bcf7cf10d3
commit
270ad1b889
23
api/api.go
23
api/api.go
@ -5,6 +5,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/unistack-org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"github.com/unistack-org/micro/v3/server"
|
||||||
)
|
)
|
||||||
@ -102,19 +103,23 @@ func Encode(e *Endpoint) map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode decodes endpoint metadata into an endpoint
|
// Decode decodes endpoint metadata into an endpoint
|
||||||
func Decode(e map[string]string) *Endpoint {
|
func Decode(e metadata.Metadata) *Endpoint {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Endpoint{
|
ep := &Endpoint{}
|
||||||
Name: e["endpoint"],
|
ep.Name, _ = e.Get("endpoint")
|
||||||
Description: e["description"],
|
ep.Description, _ = e.Get("description")
|
||||||
Method: slice(e["method"]),
|
epmethod, _ := e.Get("method")
|
||||||
Path: slice(e["path"]),
|
ep.Method = []string{epmethod}
|
||||||
Host: slice(e["host"]),
|
eppath, _ := e.Get("path")
|
||||||
Handler: e["handler"],
|
ep.Path = []string{eppath}
|
||||||
}
|
ephost, _ := e.Get("host")
|
||||||
|
ep.Host = []string{ephost}
|
||||||
|
ep.Handler, _ = e.Get("handler")
|
||||||
|
|
||||||
|
return ep
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates an endpoint to guarantee it won't blow up when being served
|
// Validate validates an endpoint to guarantee it won't blow up when being served
|
||||||
|
Loading…
x
Reference in New Issue
Block a user