I've suggested this approach based in the slack, adding it here as well to
make it searchable.
Implement Reader/Writer such that you can do:
func ProcessLine(in *Reader, out *Writer) error {
start, finish, participant := in.Float64(), in.Float64(), in.String()
if err := in.Err(); err != nil {
return err
}
out.String(participant)
out.Float64(finish - start)
return nil
}
+ Egon
On Thursday, 10 August 2017 19:17:04 UTC+3, Sofiane Cherchalli wrote:
>
> Hi Medina,
>
> Sorry I was on vacations.
>
> So do you mean the way to do it is to hardcode most of functionality. No
> need to use custom types, interfaces. Just plain text parsing?
>
> In that case, how easy is it to evolve or refactor the code?
>
> Thanks
>
> On Wednesday, July 26, 2017 at 8:36:15 PM UTC+2, Diego Medina wrote:
>>
>> I think we have a similar setup to what you are trying to do, we also
>> started with Scala and about 3 years ago we moved it to Go (still use Scala
>> for other parts of our app).
>>
>> While working in Scala and other languages you are encourage to abstract
>> things as much as you can, in Go it is often better to just address the
>> issues/requirements at hand and be clear on what you are doing.
>> In our case we define a struct that has the expected fields and types for
>> each column, and as we walk each row, we check that we get the expected
>> type, then it's a matter of cleaning/adjusting values as we need to, assign
>> the result of this cell to a variable and continue with the rest of the
>> cells on this row, once done, we initialize our struct and save it to the
>> database, move to the next row and repeat.
>>
>> Hope it helps.
>>
>>
>> On Wednesday, July 26, 2017 at 10:09:07 AM UTC-4, Sofiane Cherchalli
>> wrote:
>>>
>>> The schema is statically specified. The values always arrive in a
>>> defined order. Each value has a defined type.
>>>
>>> On Tuesday, July 25, 2017 at 3:01:14 AM UTC+2, rog wrote:
>>>>
>>>> On 24 July 2017 at 23:21, Sofiane Cherchalli <[email protected]> wrote:
>>>>
>>>>> Yes, I'm trying to stream CSV values encoded in strings. A schema
>>>>> defines a type of each value, so I have to parse values to verify they
>>>>> match the type. Once validation is done, I apply functions on each value.
>>>>>
>>>>
>>>> Is the schema dynamically or statically specified? That is, do you know
>>>> in advance what the schema is, or do are you required to write
>>>> general code that deals with many possible schemas?
>>>>
>>>>
>>>>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.