本文整理汇总了Golang中github.com/bitly/go-simplejson.Json.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:Golang Json.GetIndex方法的具体用法?Golang Json.GetIndex怎么用?Golang Json.GetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bitly/go-simplejson.Json
的用法示例。
在下文中一共展示了Json.GetIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildMongoWhereByArray
func buildMongoWhereByArray(wheres *simplejson.Json, primaryKey string) []bson.M {
mongoWheres := []bson.M{}
for key, _ := range wheres.MustArray() {
mongoWhere := BuildMongoWhere(wheres.GetIndex(key), primaryKey)
mongoWheres = append(mongoWheres, mongoWhere)
}
return mongoWheres
}
示例2: createTableStatement
func createTableStatement(tableName *string, columnsJson *simplejson.Json, uniqueColumns *simplejson.Json, primaryKeyColumns *simplejson.Json) string {
var buffer bytes.Buffer
buffer.WriteString("CREATE TABLE ")
buffer.WriteString(*tableName)
buffer.WriteString(" (\n")
columnsArry, err := columnsJson.Array()
if err != nil {
reportError("Couldn't parse columns json: ", err)
}
for i, _ := range columnsArry {
if i != 0 {
buffer.WriteString(",\n")
}
columnSchema := columnsJson.GetIndex(i)
columnName, err := columnSchema.Get("name").String()
if err != nil {
reportError("Couldn't parse column name for table json: ", err)
}
columnType, err := columnSchema.Get("type").String()
if err != nil {
reportError("Couldn't parse column type for table json: ", err)
}
buffer.WriteString(columnName)
buffer.WriteString(" ")
buffer.WriteString(columnType)
if columnUnique, err := columnSchema.Get("unique").Bool(); err == nil && columnUnique {
buffer.WriteString(" UNIQUE")
}
if columnNull, err := columnSchema.Get("null").Bool(); err == nil && !columnNull {
buffer.WriteString(" NOT NULL")
}
}
uniqueColumnsArry, err := uniqueColumns.Array()
if err == nil && len(uniqueColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
buffer.WriteString(",\nUNIQUE (")
for i, _ := range uniqueColumnsArry {
if i != 0 {
buffer.WriteString(", ")
}
uniqueColumnName, err := uniqueColumns.GetIndex(i).String()
if err != nil {
reportError("Couldn't parse unique column name for table json: ", err)
}
buffer.WriteString(uniqueColumnName)
}
buffer.WriteString(")")
}
primaryKeyColumnsArry, err := primaryKeyColumns.Array()
if err == nil && len(primaryKeyColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
buffer.WriteString(",\nUNIQUE (")
for i, _ := range primaryKeyColumnsArry {
if i != 0 {
buffer.WriteString(", ")
}
primaryKeyColumnName, err := primaryKeyColumns.GetIndex(i).String()
if err != nil {
reportError("Couldn't parse primary key column name for table json: ", err)
}
buffer.WriteString(primaryKeyColumnName)
}
buffer.WriteString(")")
}
buffer.WriteString("\n);")
return buffer.String()
}