Пример #1
0
func parseDotApi(dotApi string) ([]proxy.ApiProxySpec, error) {
	arrayProxyOut := make([]proxy.ApiProxySpec, 0)

	var errors *multierror.Error
	confTree, err := hcl.Parse(dotApi)

	output := parseRawObject("api", confTree, errors)

	if err != nil {
		panic(err)
	}

	for _, rawApi := range output {
		//fmt.Println(spew.Sdump(rawApi))
		methods := parseRawArray("method", rawApi, errors)
		for _, meth := range methods {
			proxyOut := proxy.Empty()
			proxyOut.Method = meth
			proxyOut.Enabled = parseRawBool("enabled", rawApi, errors)
			proxyOut.Pattern = parseKey(rawApi)
			proxyOut.Id = parseRawString("id", rawApi, errors)
			if proxyOut.Id == "" {
				proxyOut.Id = proxyOut.Method + "_" + proxyOut.Pattern
			}
			proxyOut.Chain = parseRawChain(rawApi, errors)
			arrayProxyOut = append(arrayProxyOut, proxyOut)
		}

	}

	//fmt.Println(spew.Sdump(arrayProxyOut))
	return arrayProxyOut, nil

}
Пример #2
0
// Parse parses the given input and returns the root object.
//
// The input format can be either HCL or JSON.
func Parse(input string) (*hcl.Object, error) {
	switch lexMode(input) {
	case lexModeHcl:
		return hcl.Parse(input)
	case lexModeJson:
		return json.Parse(input)
	}

	return nil, fmt.Errorf("unknown config format")
}