gox12

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2013 License: MIT Imports: 10 Imported by: 0

README

gox12

golang X12 non-validating parser

Build Status

Installation

go get github.com/azoner/gox12

Example

package main

import (
        "fmt"
        "os"
        "log"
        "github.com/azoner/gox12"
)

func main() {
        inFilename := "x12file.txt"
        inFile, err := os.Open(inFilename)
        if err != nil {
                log.Fatal(err)
                os.Exit(1)
        }
        defer inFile.Close()
        raw, err := gox12.NewRawX12FileReader(inFile)
        if err != nil {
                fmt.Println(err)
        }
        for rs := range raw.GetSegments() {
                if rs.Segment.SegmentId == "INS" {
                        fmt.Println(rs)
                        v, _, _ := rs.Segment.GetValue("INS01")
                        fmt.Println(v)
                        for v := range rs.Segment.GetAllValues() {
                                fmt.Println(v.X12Path, v.Value)
                        }
                        fmt.Println()
                }
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRawX12FileReader

func NewRawX12FileReader(inFile io.Reader) (*rawX12FileReader, error)

Types

type ElementValue

type ElementValue struct {
	X12Path X12Path
	Value   string
}

type RawSegment

type RawSegment struct {
	Segment   Segment
	LineCount int
}

type Segment

type Segment struct {
	SegmentId  string
	Composites [][]string
}

func NewSegment

func NewSegment(line string, elementTerm byte, subelementTerm byte, repTerm byte) Segment

func (*Segment) GetAllValues

func (s *Segment) GetAllValues() <-chan ElementValue

func (*Segment) GetValue

func (s *Segment) GetValue(x12path string) (val string, found bool, err error)

Acts like golang maps, if not found, returns default value with found==false X12 Path indices are 1-based

type X12Path

type X12Path struct {
	Path          string // no leading slash indicates a relative path
	SegmentId     string
	IdValue       string
	ElementIdx    int
	SubelementIdx int
}

An X12 path is comprised of a path of loop identifiers, a segment identifier, and element position, and a composite position.

The last loop id might be a segment id. /LOOP_1/LOOP_2 /LOOP_1/LOOP_2/SEG /LOOP_1/LOOP_2/SEG02 /LOOP_1/LOOP_2/SEG[424]02-1 LOOP_2/SEG02 SEG[434]02-1 02-1 02

func ParseX12Path

func ParseX12Path(rawpath string) (x12path *X12Path, err error)

Parse parses an X12 Path string into component parts, The last part of the may may be a segment identifier

func (*X12Path) Empty

func (x12path *X12Path) Empty() bool

Is the path empty?

func (*X12Path) IsAbs

func (x12path *X12Path) IsAbs() bool

func (*X12Path) String

func (p *X12Path) String() string

String reassembles the X12Path into a valid X12Path string See pkg/net/url/url.go:String

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL