podhmo / go-jsontmpl

[WIP] generating json with template
MIT License
2 stars 0 forks source link

generate command #1

Open podhmo opened 2 years ago

podhmo commented 2 years ago

handling metadata

see also

podhmo commented 2 years ago

e.g.

# query

query package is json builder package for accessing elasticsearch, in internal use.

## SearchQuery

for search query.

```json
{
    "size": "${Size:int}",
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "word.autocomplete": {
                            "query": "${Word}"
                        }
                    }
                },
                {
                    "match": {
                        "word.readingform": {
                            "query": "${Word}",
                            "fuzziness": "AUTO",
                            "operator": "and"
                        }
                    }
                }
            ]
        }
    }
}
podhmo commented 2 years ago

generated code like following (this is go doc output)

package query // import "m/00elasticsearch/query"

TYPES

type SearchQueryBuilder struct {
    Params struct {
        // Word: query
        Word string `target:"${Word}"`

        // Size: number of limit
        Size int `target:"${Size:int}"`
    }
    // Has unexported fields.
}
    SearchQueryBuilder for search query.

func NewSearchQueryBuilder(c *gojsontmpl.Config) *SearchQueryBuilder

func (b *SearchQueryBuilder) Size(v int) *SearchQueryBuilder

func (b *SearchQueryBuilder) ToReader() (*bytes.Buffer, error)

func (b *SearchQueryBuilder) Word(v string) *SearchQueryBuilder
podhmo commented 2 years ago

and example test

image