func writeJSON(w http.ResponseWriter, meta *HTTPResponseMeta, response interface{}) error { bytes, err := json.Marshal(response) if err == nil { if !isEmpty(meta.ContentType) { w.Header().Set("Content-Type", meta.ContentType) } else { w.Header().Set("Content-Type", "application/json; charset=utf-8") } for key, value := range meta.Headers { w.Header().Set(key, strings.Join(value, ";")) } w.WriteHeader(meta.StatusCode) count, err := w.Write(bytes) if count == 0 { return exception.New("writeJSON didnt write any bytes") } if err != nil { return err } } else { return err } return nil }
func (dfr *DataFileReader) executeCopyLine(line string, c *spiffy.DbConnection, tx *sql.Tx) (*sql.Stmt, error) { pieces := dfr.extractCopyLine(line) if len(pieces) < 3 { return nil, exception.New("Invalid `COPY ...` line, cannot continue.") } tableName := pieces[1] columnCSV := pieces[2] columns := strings.Split(columnCSV, ", ") return tx.Prepare(pq.CopyIn(tableName, columns...)) }