Пример #1
0
func init() {
	newInfluxHandler := &InfluxDb{}
	db.RegisterHandler(newInfluxHandler)

	// Get DbObject struct field names for columns object
	a := &db.DbObject{}
	s := reflect.ValueOf(a).Elem()
	typeOfT := s.Type()
	for i := 0; i < s.NumField(); i++ {
		newInfluxHandler.columns = append(newInfluxHandler.columns, typeOfT.Field(i).Name)
	}
}
Пример #2
0
func (self *InfluxDb) Insert(dbObject *db.DbObject) error {
	newSeries := &client.Series{
		Name:    "message",
		Columns: self.columns,
	}
	var seriesArray []*client.Series
	var values []interface{}

	s := reflect.ValueOf(dbObject).Elem()
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		values = append(values, f.Interface())
	}
	newSeries.Points = append(newSeries.Points, values)
	seriesArray = append(seriesArray, newSeries)

	err := self.connection.WriteSeries(seriesArray)
	if err != nil {
		return err
	}
	return nil
}