(queryName, queryType, queryPath string)
| 125 | } |
| 126 | |
| 127 | func makeQuery(queryName, queryType, queryPath string) { |
| 128 | var err error |
| 129 | var file *os.File |
| 130 | file, err = os.Open(queryPath) |
| 131 | panicIfErr(err) |
| 132 | |
| 133 | fmt.Printf("making query %s ... \n", queryName) |
| 134 | var resp *http.Response |
| 135 | if queryType == ".aql" { |
| 136 | resp, err = http.Post(fmt.Sprintf("http://%s:%d/query/aql", viper.GetString(hostKeyName), viper.GetInt(portKeyName)), "application/json", file) |
| 137 | } else if queryType == ".sql" { |
| 138 | resp, err = http.Post(fmt.Sprintf("http://%s:%d/query/sql", viper.GetString(hostKeyName), viper.GetInt(portKeyName)), "application/json", file) |
| 139 | } else { |
| 140 | err = fmt.Errorf("query file has to have .aql or .sql suffix") |
| 141 | } |
| 142 | panicIfErr(err) |
| 143 | if resp.StatusCode != http.StatusOK { |
| 144 | panic(fmt.Errorf("query failed with status code %d", resp.StatusCode)) |
| 145 | } |
| 146 | |
| 147 | result, err := ioutil.ReadAll(resp.Body) |
| 148 | panicIfErr(err) |
| 149 | |
| 150 | prettJSON := &bytes.Buffer{} |
| 151 | panicIfErr(json.Indent(prettJSON, result, "", "\t")) |
| 152 | |
| 153 | fmt.Println(prettJSON.String()) |
| 154 | } |
| 155 | |
| 156 | func createTable(tableName string, tableSchemaPath string) { |
| 157 | schemaFile, err := os.Open(tableSchemaPath) |
no test coverage detected