2 回答
TA贡献1848条经验 获得超2个赞
package main
import (
"fmt"
"io/ioutil"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
schema := `measures: {
count: {
type: 'count',
drillMembers: [country]
}
},
dimensions: {
`
a := []string{"country", "year", "gdpPercap", "lifeExp", "pop", "continent"}
var cubeSchema string
for _, s := range a {
cubeSchema += s + ": {\n\tsql: " + s + ",\n\ttype: `string`\n},\n"
}
fileText := []byte(schema + cubeSchema + "}\n}")
fmt.Println(cubeSchema)
err := ioutil.WriteFile("test.js", fileText, 0644)
check(err)
}
检查此代码。
TA贡献2065条经验 获得超14个赞
我试着做第二部分:
package main
import (
"encoding/json"
"fmt"
)
func main() {
a := []string{"country", "year", "gdpPercap", "lifeExp", "pop", "continent"}
var items map[string]sqlType
items = make(map[string]sqlType)
for _, v := range a {
items[v] = sqlType{SQL: v, Type: "string"}
}
dimensions := dimensions{Dimensions: items}
bytes, err := json.Marshal(dimensions)
if err != nil {
panic(err)
}
c := string(bytes)
fmt.Println(c)
}
type sqlType struct {
SQL string `json:"sql"`
Type string `json:"type"`
}
type dimensions struct {
Dimensions map[string]sqlType `json:"dimensions"`
}
- 2 回答
- 0 关注
- 137 浏览
添加回答
举报