move util
This commit is contained in:
38
api/api.go
38
api/api.go
@@ -60,22 +60,6 @@ type Service struct {
|
|||||||
Services []*registry.Service
|
Services []*registry.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func strip(s string) string {
|
|
||||||
return strings.TrimSpace(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func slice(s string) []string {
|
|
||||||
var sl []string
|
|
||||||
|
|
||||||
for _, p := range strings.Split(s, ",") {
|
|
||||||
if str := strip(p); len(str) > 0 {
|
|
||||||
sl = append(sl, strip(p))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sl
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode encodes an endpoint to endpoint metadata
|
// Encode encodes an endpoint to endpoint metadata
|
||||||
func Encode(e *Endpoint) map[string]string {
|
func Encode(e *Endpoint) map[string]string {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
@@ -152,28 +136,6 @@ func Validate(e *Endpoint) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Design ideas
|
|
||||||
|
|
||||||
// Gateway is an api gateway interface
|
|
||||||
type Gateway interface {
|
|
||||||
// Register a http handler
|
|
||||||
Handle(pattern string, http.Handler)
|
|
||||||
// Register a route
|
|
||||||
RegisterRoute(r Route)
|
|
||||||
// Init initialises the command line.
|
|
||||||
// It also parses further options.
|
|
||||||
Init(...Option) error
|
|
||||||
// Run the gateway
|
|
||||||
Run() error
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGateway returns a new api gateway
|
|
||||||
func NewGateway() Gateway {
|
|
||||||
return newGateway()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// WithEndpoint returns a server.HandlerOption with endpoint metadata set
|
// WithEndpoint returns a server.HandlerOption with endpoint metadata set
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
|
21
api/util.go
Normal file
21
api/util.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func strip(s string) string {
|
||||||
|
return strings.TrimSpace(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func slice(s string) []string {
|
||||||
|
var sl []string
|
||||||
|
|
||||||
|
for _, p := range strings.Split(s, ",") {
|
||||||
|
if str := strip(p); len(str) > 0 {
|
||||||
|
sl = append(sl, strip(p))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sl
|
||||||
|
}
|
Reference in New Issue
Block a user