sil

package module
v0.0.0-...-988ebd9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

README

SIL

Create a SIL File in Go

README Needs updating and is outdated right now

Changing fairly often right now but starting to stabilize on needed API. High level goal is to have a type define the SIL structure and add data and get []bytes representing a complete SIL file that processes without errors.

Like JSON or XML tags are being used to define the structure of the SIL using a type. Currently there are two tags, sil and default. The sil tag is used to define the data type and default will fill in data that is missing but required. Pointers will be optional values but right now they are treated the same as non pointers and processed normally, I would recommend creating any types using pointers for optional values because they work right now and will eventually allow for more compact and smarter SIL file creation.

Goals:
  • Type
    • Marshal function
    • Unmarshal function
    • Allow pointers to be used for optional elements
    • [] single quote for most data types and no quotes for integers
      • [] confirm data is integer for integer types
    • Validate that element name is a proper SIL type
    • Validate that data passed for Rows matches type used for Make
    • Accept time.Time as type for DATE(7)
  • Header
    • Batch number creation
  • View
    • Define table name with struct tag
    • View Header
      • respect default tag
      • check for unsafe elements, correct or error as needed
    • View Data
      • Create View data
      • Only insert optional elements into SIL file when they are used.
Eventuals
  • Read SQL structure to create Go Types for tables automagically

Example

Needs to be re-written

Documentation

Index

Constants

View Source
const (
	ADD    = "ADD"
	ADDRPL = "ADDRPL"
	CHANGE = "CHANGE"
	REMOVE = "REMOVE"
)

Batch Type Name Constants

Variables

This section is empty.

Functions

func JulianDate

func JulianDate(t time.Time) string

JulianDate takes a time.Time and turns it into a julian date - just formatting

func JulianDateTime

func JulianDateTime(t time.Time) string

JulianDateTime takes a time.Time and turns it into a julian date and time

func JulianNow

func JulianNow() string

JulianNow returns the julian date for right now

func JulianTimeNow

func JulianTimeNow() string

JulianTimeNow returns the JulianDate with time for right now

func JulianTimePart

func JulianTimePart(t time.Time) string

JulianTimePart returns the time part of a julian formatted time

Types

type Footer []string

Footer is an array of strings to be apended to end of file

type Header struct {
	Type              string `sil:"F901" default:"HM"`             // Batch type
	Identifier        string `sil:"F902" default:"00000001"`       // Batch identifier
	Creator           string `sil:"F903" default:"MANUAL"`         // Batch creator
	Destination       string `sil:"F904" default:"PAL"`            // Batch destination
	AuditFile         string `sil:"F905"`                          // Batch audit file
	ResponseFile      string `sil:"F906"`                          // Batch response file
	EndingDate        int    `sil:"F907" default:"NOW"`            // Batch ending date
	EndingTime        int    `sil:"F908" default:"0000"`           // Batch ending time
	ActiveDate        int    `sil:"F909" default:"NOW"`            // Batch active date
	ActiveTime        int    `sil:"F910" default:"0000"`           // Batch active time
	PurgeDate         string `sil:"F911"`                          // Batch purge date
	ActionType        string `sil:"F912" default:"ADDRPL"`         // Batch action type
	Description       string `sil:"F913" default:"ADDRPL FROM GO"` // Batch description
	UserOneState      string `sil:"F914"`                          // Batch user 1 (state)
	MaximumErrorCount string `sil:"F918"`                          // Batch maximum error count
	FileVersion       string `sil:"F919"`                          // Batch file version
	CreatorVersion    string `sil:"F920"`                          // Batch creator version
	PrimaryKey        string `sil:"F921"`                          // Batch primary key
	SpecificCommand   string `sil:"F922"`                          // Batch specific command
	TagType           string `sil:"F930"`                          // Shelf tag type
	ExecutionPriority string `sil:"F931"`                          // Batch execution priority
	LongDescription   string `sil:"F932"`                          // Batch long description
}

Header tells the system what the SIL file is doing. Since the header insert is not needed the only sil tag that is used is INTEGER - the rest are dummy holders but should get correct and validate data against the sql data type. Pointers are not handled normally and should be used for optional elements. 0000 note: a default of NOW inserts to JulianNow F912 can be ADD, ADDRPL, CHANGE and REMOVE

type Multi

type Multi map[string]*SIL

Multi holds an array of SIL's and methods to work with them

func (Multi) AppendView

func (m Multi) AppendView(name string, data interface{})

AppendView appends data to the view

func (Multi) Make

func (m Multi) Make(name string, definition interface{})

Make creates a SIL object within the Multi type

func (Multi) Marshal

func (m Multi) Marshal() (data []byte, err error)

Marshal creates the SIL structure from the information in the Multi

func (Multi) SetHeaders

func (m Multi) SetHeaders(name string)

SetHeaders sets all the headers in a sil file to the same name

func (*Multi) Write

func (m *Multi) Write(filename string, archive bool) error

Write writes a SIL to a file

type SIL

type SIL struct {
	Header Header
	View   View
	Footer Footer

	TableType interface{}
	Include   bool
	// contains filtered or unexported fields
}

SIL is the structure of a SIL file

func Make

func Make(name string, definition interface{}) *SIL

Make makes a sil file of the definition (as struct) passed

func New

func New(definition interface{}) *SIL

func (*SIL) Append

func (s *SIL) Append(str string)

Append adds a line to the bottom of the SIL file

func (*SIL) JSON

func (s *SIL) JSON(filename string) error

JSON Creates a JSON file of the SIL file

func (*SIL) Marshal

func (s *SIL) Marshal(include bool) (data []byte, err error)

Marshal creates the SIL structure from the information in the SIL type

func (*SIL) Write

func (s *SIL) Write(filename string, include bool, archive bool) error

Write writes a SIL to a file

type View

type View struct {
	Name     string
	Required bool
	Action   string
	Data     []interface{}
}

View is the data of the SIL file Name is the table name Data is an array of interfaces

Directories

Path Synopsis
Package silread reads sil files into SIL or Multi objects from the sil module
Package silread reads sil files into SIL or Multi objects from the sil module

Jump to

Keyboard shortcuts

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