Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/o1egl/fwencoder
Fixed width file parser (encoder/decoder) in GO (golang)
https://github.com/o1egl/fwencoder
decoder encoder fixed-size-file go golang library parser table text
Last synced: about 1 month ago
JSON representation
Fixed width file parser (encoder/decoder) in GO (golang)
- Host: GitHub
- URL: https://github.com/o1egl/fwencoder
- Owner: o1egl
- License: mit
- Created: 2017-12-25T12:55:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-23T20:02:36.000Z (over 1 year ago)
- Last Synced: 2024-10-14T10:45:01.710Z (about 2 months ago)
- Topics: decoder, encoder, fixed-size-file, go, golang, library, parser, table, text
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 27
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - fwencoder - Fixed width file parser (encoding and decoding library) for Go. (Serialization / HTTP Clients)
- zero-alloc-awesome-go - fwencoder - Fixed width file parser (encoding and decoding library) for Go. (Serialization / HTTP Clients)
- awesome-go - fwencoder - Fixed width file parser (encoder/decoder) in GO (golang) - ★ 6 (Serialization)
- awesome-go-extra - fwencoder - 12-25T12:55:29Z|2022-08-08T10:33:46Z| (Serialization / HTTP Clients)
- awesome-go-zh - fwencoder
README
# Fixed width file parser (encoder/decoder) for GO (golang)
[![License](http://img.shields.io/:license-mit-blue.svg)](LICENSE)
[![GoDoc](https://godoc.org/github.com/o1egl/fwencoder?status.svg)](https://godoc.org/github.com/o1egl/fwencoder)
![Build Status](https://github.com/o1egl/fwencoder/actions/workflows/build.yml/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/o1egl/fwencoder/branch/master/graph/badge.svg?token=BPBYoYAeZ0)](https://codecov.io/gh/o1egl/fwencoder)
[![Go Report Card](https://goreportcard.com/badge/github.com/o1egl/fwencoder)](https://goreportcard.com/report/github.com/o1egl/fwencoder)This library is using to parse fixed-width table data like:
```
Name Address Postcode Phone Credit Limit Birthday
Evan Whitehouse V4560 Camel Back Road 3122 (918) 605-5383 1000000.5 19870101
Chuck Norris P.O. Box 872 77868 (713) 868-6003 10909300 19651203
```## Install
To install the library use the following command:
```
$ go get -u github.com/o1egl/fwencoder
```## Decoding example
Parsing data from io.Reader:
```go
type Person struct {
Name string
Address string
Postcode int
Phone string
CreditLimit float64 `json:"Credit Limit"`
Bday time.Time `column:"Birthday" format:"20060102"`
}f, _ := os.Open("/path/to/file")
defer f.Closevar people []Person
err := fwencoder.UnmarshalReader(f, &people)
```You can also parse data from byte array:
```go
b, _ := ioutil.ReadFile("/path/to/file")
var people []Person
err := fwencoder.Unmarshal(b, &people)
```## Encoding example
```go
people := []Person{
Name: "John",
Address: "P.O. Box 872",
Phone: "(713) 868-6003",
CreditLimit: 10909300,
Bday: "19651203"
}b, err := Marshal(&people)
fmt.Println(string(b))
```or you can directly write to io.Writer
```go
people := []Person{
Name: "John",
Address: "P.O. Box 872",
Phone: "(713) 868-6003",
CreditLimit: 10909300,
Bday: "19651203"
}err := MarshalWriter(os.Stdout, &people)
```