hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.41k stars 4.43k forks source link

golang api with `params` avaialable #1400

Open JeffChien opened 9 years ago

JeffChien commented 9 years ago

current public api can't allow user to specify parameters which is no flexible, It would be great if we can have api that can pass custom params as parameter

ryanuber commented 9 years ago

Are there some options in particular that you want to pass that are not available using the WriteOptions or QueryOptions structs? You should be able to pass any query parameters required using those in the request. Let me know if something is missing!

JeffChien commented 9 years ago

Sorry I did not make my question clear, I want to have a json reponse keys information under some prefix but not one level deeper, it look like List api with recurse and separator flag enable suite my need. please make some api signature like getInternal. Thanks.

sethvargo commented 9 years ago

Hey @JeffChien

Thank you for your reply. Would you be able to share a command sample of what behavior you would like to see? It is still unclear from your response what behavior you desire. Specifically:

Thanks and sorry for the confusion! :smile:

JeffChien commented 9 years ago

I did some test with http api and find the result was not I expected, if that is by design, I'm ok with it. Just list what I saw, and what result I was expected.

suppose I have these keys in consul

└── foo
    ├── child-1
    │   └── grandchild
    └── child-2
        └── grandchild

$ curl -L 'http://localhost:8500/v1/kv/foo/?keys&separator=/&pretty'

[
    "foo/child-1/",
    "foo/child-1",
    "foo/child-2/",
    "foo/child-2"
]

the result is expected.

$ curl -L 'http://localhost:8500/v1/kv/foo/?recurse&separator=/&pretty'

[
    {
        "Key": "foo/child-1/grandchild",
        "Value": null
    },
    {
        "Key": "foo/child-1",
        "Value": null
    },
    {
        "Key": "foo/child-2/grandchild",
        "Value": null
    },
    {
        "Key": "foo/child-2",
        "Value": null
    }
]

the result is not I expected, it give me all the keys information, but I thought it will give me just child-1 and child-2.

so when I look at the code yesterday, I thought if I can add separator:"/" to getInternal, it will output the result I want. hope this clear the confusion :)

JeffChien commented 9 years ago

sorry for the typo..... updated

ryanuber commented 9 years ago

Hey @JeffChien, I think I see the problem. You want to pass ?separator=/ to a recursive K/V fetch, but it is not supported. Is that right? Currently the semantics of ?recurse are just to fetch the entire sub-tree and return it. It's possible that we could also provide filtering using ?separator to return a subset of keys. Let me know if that's what you are looking for.

JeffChien commented 9 years ago

@ryanuber that is exactly what I want

aanm commented 8 years ago

@ryanuber Any updates on this?