func parseRawChain(hclObj *hclObj.Object, errors *multierror.Error) chain.ChainSpec { if rawChain := hclObj.Get("chain", false); rawChain != nil { // iterate over all modules for a given chain for _, mod := range rawChain.Elem(true) { modules := parseRawModules(mod, errors) return chain.NewWithModules(modules) } } return chain.New() }
// Example of json // {"id": <string>, // "method": <string>, // "enabled": <bool>, // "pattern": <string>, // "chain": [ // {"ref": <string>, "params": {"key": <string>, "key2": <string>}, // {"ref": <string>, "params": {"key": <string>} // ] // } func newProxyFromJson(valueAsJson []byte) (proxy.ApiProxySpec, error) { // convert to map[string] interface{} var input map[string]interface{} err := json.Unmarshal(valueAsJson, &input) if err != nil { return nil, err } //fmt.Printf("%+v\n", input) // convert to api struct var meta mapstructure.Metadata var result ApiProxyEtcdValue config := &mapstructure.DecoderConfig{ Metadata: &meta, Result: &result, } decoder, _ := mapstructure.NewDecoder(config) errD := decoder.Decode(input) if errD != nil { return nil, errD } ch := chain.New() for _, mod := range result.Chain { ch.AppendModule(modprobe.Find(mod.Ref, params.ModuleParams(mod.Params))) } p := proxy.New(result.Id, result.Method, result.Pattern, result.Enabled, ch) // fmt.Printf("Unused keys: %#v\n", meta.Unused) // fmt.Printf("id: %s\n", result.Id) // fmt.Printf("method: %s\n", result.Method) // fmt.Printf("enabled: %t\n", result.Enabled) // fmt.Printf("pattern: %s\n", result.Pattern) // fmt.Printf("chain: %+v\n", result.Chain) return p, nil }
func getMockChain() chain.ChainSpec { OnRequest1Fn := func(ctx context.ContextSpec) (*http.Response, error) { return nil, nil } OnResponse1Fn := func(ctx context.ContextSpec) (*http.Response, error) { return nil, nil } OnRequest2Fn := func(ctx context.ContextSpec) (*http.Response, error) { return httputils.NewTextResponse(nil, 200, "happy life"), nil } OnResponse2Fn := func(ctx context.ContextSpec) (*http.Response, error) { return nil, nil } modMock1 := modules.NewWithParams("mod_mock_1", OnRequest1Fn, OnResponse1Fn) modMock2 := modules.NewWithParams("mod_mock_2", OnRequest2Fn, OnResponse2Fn) chain := chain.New() chain.AppendModule(modMock1) chain.AppendModule(modMock2) return chain }
func Empty() *BaseProxy { return &BaseProxy{ Chain: chain.New(), } }