예제 #1
0
func (n *ng) GetMiddleware(key engine.MiddlewareKey) (*engine.Middleware, error) {
	mKey := n.path("frontends", key.FrontendKey.Id, "middlewares", key.Id)
	bytes, err := n.getVal(mKey)
	if err != nil {
		return nil, err
	}
	return engine.MiddlewareFromJSON([]byte(bytes), n.registry.GetSpec, key.Id)
}
예제 #2
0
func parseMiddlewarePack(v []byte, r *plugin.Registry) (*engine.Middleware, time.Duration, error) {
	var mp middlewareReadPack
	if err := json.Unmarshal(v, &mp); err != nil {
		return nil, 0, err
	}
	if len(mp.Middleware) == 0 {
		return nil, 0, &scroll.MissingFieldError{Field: "Middleware"}
	}
	f, err := engine.MiddlewareFromJSON(mp.Middleware, r.GetSpec)
	if err != nil {
		return nil, 0, err
	}
	var ttl time.Duration
	if mp.TTL != "" {
		ttl, err = time.ParseDuration(mp.TTL)
		if err != nil {
			return nil, 0, err
		}
	}
	return f, ttl, nil
}