Skip to content

helloticket/ffparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a3cc2cd · Sep 5, 2022

History

29 Commits
Jun 11, 2020
Nov 9, 2019
Jun 6, 2020
Apr 27, 2017
Nov 9, 2019
Jun 6, 2020
Apr 10, 2020
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Nov 9, 2019
Nov 9, 2019
Nov 9, 2019
Nov 9, 2019

Repository files navigation

ffparser

The library is a Flat-File Parser

Install

go get -v github.com/helloticket/ffparser

Using

package main

import (
	"log"
	"time"

	"github.com/helloticket/ffparser"
)

type Pojo struct {
	Value1 time.Time `record:"start=1,end=21"`
	Value2 int       `record:"start=22,end=32"`
	Value3 int64     `record:"start=33,end=43"`
	Value4 float64   `record:"start=44,end=54"`
	Value5 string    `record:"start=55,end=65"`
}

func main() {
	ffp := ffparser.NewSimpleParser()

	result, _ := ffp.ParseToText(&Pojo{
		Value1: time.Date(2017, 5, 10, 0, 0, 0, 0, time.UTC),
		Value2: 12402,
		Value3: 4567822222,
		Value4: 4567833.22,
		Value5: "be happy",
	})

	log.Println(result)
}

Inspired

https://github.com/ffpojo/ffpojo