Example #1
0
func ValidateOptionsAndDefaults(typ string, fields map[string]reflect.StructField, requiredDefaults reflect.Value, options map[string]string) (newOptions map[string]string, err error) {
	newOptions = make(map[string]string)
	// validate optional attributes
	for name, value := range options {
		field, ok := fields[strings.ToLower(name)]
		if !ok {
			ErrorAndExit(fmt.Sprintf("validation error: %s:%s is not a valid option for field type %s", name, value, typ))
		} else {
			newOptions[field.Tag.Get("xml")] = options[name]
		}
	}

	// validate required attributes
	s := requiredDefaults
	tod := s.Type()
	for i := 0; i < s.NumField(); i++ {
		_, ok := options[inflect.CamelizeDownFirst(tod.Field(i).Name)]
		if !ok {
			switch s.Field(i).Type().Name() {
			case "int":
				newOptions[tod.Field(i).Tag.Get("xml")] = strconv.Itoa(s.Field(i).Interface().(int))
				break
			case "bool":
				if typ == "bool" {
					if _, ok = options["formula"]; ok {
						if tod.Field(i).Tag.Get("xml") == "defaultValue" {
							break
						}
					}
				} //else {
				newOptions[tod.Field(i).Tag.Get("xml")] = strconv.FormatBool(s.Field(i).Interface().(bool))
				//}
				break
			case "string":
				newOptions[tod.Field(i).Tag.Get("xml")] = s.Field(i).Interface().(string)
				break
			}
		} else {
			newOptions[tod.Field(i).Tag.Get("xml")] = options[inflect.CamelizeDownFirst(tod.Field(i).Name)]
		}
	}
	return newOptions, err
}
Example #2
0
// Parse native names into go parameter names
func toVarName(name string) string {
	if name == "options" {
		return "options_"
	}
	if name == "type" {
		return "type_"
	}
	p := partsRegexp.ReplaceAllString(name, "_")
	return inflect.CamelizeDownFirst(p)
}
Example #3
0
// Parse native names into go parameter names
func parseParamName(name string) string {
	if name == "r_s_version" {
		return "rsVersion"
	}
	if name == "type" {
		return "type_"
	}
	if name == "options" {
		return "options_"
	}
	p := partsRegexp.ReplaceAllString(name, "_")
	return inflect.CamelizeDownFirst(p)
}
Example #4
0
func WriteNode(data *Data) {
	MakeLibraryDir("node")
	RunTemplate := ChooseTemplate("node")

	name := data.Pkg["name"].(string)

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("package.json", "package.json", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir("lib")
	RunTemplate("lib/index.js", "index.js", data)

	MakeDir(inflect.CamelizeDownFirst(name))
	RunTemplate("lib/client.js", "client.js", data)

	MakeDir("error")
	RunTemplate("lib/error/index.js", "index.js", data)
	RunTemplate("lib/error/client_error.js", "client_error.js", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/index.js", "index.js", data)
	RunTemplate("lib/http_client/auth_handler.js", "auth_handler.js", data)
	RunTemplate("lib/http_client/error_handler.js", "error_handler.js", data)
	RunTemplate("lib/http_client/request_handler.js", "request_handler.js", data)
	RunTemplate("lib/http_client/response.js", "response.js", data)
	RunTemplate("lib/http_client/response_handler.js", "response_handler.js", data)
	MoveDir("..")

	MakeDir("api")

	for k, v := range data.Api["class"].(map[string]interface{}) {
		data.Api["active"] = ActiveClassInfo(k, v)
		RunTemplate("lib/api/api.js", inflect.CamelizeDownFirst(k)+".js", data)
		delete(data.Api, "active")
	}
}
Example #5
0
// lowerCamelCase returns camel case version of a word
// with lower case first character
func lowerCamelCase(s string) string {
	return inflect.CamelizeDownFirst(s)
}