Skip to content
Snippets Groups Projects

Initial implementation of an elasticsearch indexer in Go

Merged Nick Thomas requested to merge 1-initial-implementation into master
All threads resolved!
3 files
+ 259
204
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 50
0
package elastic
import (
"encoding/json"
"io"
"io/ioutil"
)
type Config struct {
URL []string `json:"url"`
AWS bool `json:"aws"`
Region string `json:"aws_region"`
AccessKey string `json:"aws_access_key"`
SecretKey string `json:"aws_secret_access_key"`
}
func ReadConfig(r io.Reader) (*Config, error) {
var out Config
if err := json.NewDecoder(r).Decode(&out); err != nil {
return nil, err
}
return &out, nil
}
type ReaderAsJSONString struct {
io.Reader
}
func (r *ReaderAsJSONString) MarshalJSON() ([]byte, error) {
/* TODO: fewer copies
out := bytes.NewBuffer(nil)
err := out.WriteByte('"')
_, err = io.Copy(out, r.Reader) // FIXME: convert to valid JSON string data, escape quote marks
err = out.WriteByte('"')
return out.Bytes(), err
*/
data, err := ioutil.ReadAll(r.Reader)
if err != nil {
return nil, err
}
return json.Marshal(string(data))
}
type Req struct {
Blob *ReaderAsJSONString `json:"blob"`
}
Loading