osquery / osquery-go

Go bindings for osquery
MIT License
388 stars 79 forks source link

column builder DSL #7

Closed groob closed 7 years ago

groob commented 7 years ago

This is a demonstration of an idea I had to simplify writing the Columns() method for a table plugin.

The idea is that the helpers for ColumnDefinition types are moved to a separate package which is safe to import into a table plugin namespace using a . import.

Example:

import (
    "github.com/kolide/osquery-golang"
    . "github.com/kolide/osquery-golang/sql"
)

type ExampleTable struct{}

func (f *ExampleTable) Columns() []osquery.ColumnDefinition {
    return ColumnSlice(
        TextColumn("text"),
        IntegerColumn("integer"),
        BigIntColumn("big_int"),
        DoubleColumn("double"),
    )
}
zwass commented 7 years ago

I'm a bit skeptical as to the utility of this. It seems easier to me for the user to import one package by the standard means and then have all of the functions available. I wouldn't object to the ColumnSlice helper, but []osquery.ColumnDefinition is already in the type signature of the Columns() function, so I'm not sure that's a big gain either.