ztic

package module
v0.0.0-...-14ceb6b Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2019 License: MIT Imports: 9 Imported by: 0

README

go-ztic

Golang library to load Service Tickets from file

Usage

package main

import (
  "fmt"
  "time"

  ztic "github.com/vmoret/go-ztic"
)

func main() {
  // open CSV file
  file, err := os.Open("export.csv")
  if err != nil {
    panic(err)
  }
  defer file.Close()
  
  // initialize decoder
  d := ztic.NewDecoder()

  // read the CSV file
  r := ztic.NewCSVReader(file)

  // Read all the tickets 
  tickets, err := d.DecodeAll(r.ReadAll())
  if err != nil {
    panic(err)
  }

  // Load location for Taipei
  loc, _ := time.LoadLocation("Asia/Taipei")

  // isUnassigned is a predicate to confirm this is unassigned `ServiceTicket`
  isUnassigned := func(t *ztic.ServiceTicket) bool {
    return t.Owner = ""
  }

  // iterate thru the tickets
  for _, ticket := range export.Data.Filter(isUnassigned) {
    // print ticket in local timezone
    fmt.Println(ticket)

    // print ticket in timezone of Taipei
    fmt.Println(ticket.InLocation(loc))
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(data map[string]string, obj interface{}) error

Unmarshal parses the ZTIC-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

Types

type CSVReader

type CSVReader struct {
	// contains filtered or unexported fields
}

CSVReader read

func NewCSVReader

func NewCSVReader(rd io.Reader) *CSVReader

NewCSVReader returns a new Reader that reads from r.

func (*CSVReader) ReadAll

func (r *CSVReader) ReadAll() [][]string

ReadAll reads all the remaining records from r. Each record is a slice of fields.

type Contact

type Contact string

Contact describes a contact

func (*Contact) UnmarshalZTIC

func (c *Contact) UnmarshalZTIC(data string) error

UnmarshalZTIC implements the Unmarshaler interface

type Decoder

type Decoder struct{}

Decoder decodes `ServiceTicets` from a io.Reader

func NewDecoder

func NewDecoder() *Decoder

NewDecoder returns a new `Decoder`

func (*Decoder) Decode

func (d *Decoder) Decode(data map[string]string) (*ServiceTicket, error)

Decode decodes a `map[string]string` as a `ServiceTicket`

func (*Decoder) DecodeAll

func (d *Decoder) DecodeAll(lines [][]string) (ServiceTickets, error)

DecodeAll decodes `lines` and returns `ServiceTickets`

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type Predicate

type Predicate func(ticket *ServiceTicket) bool

Predicate describes a predicate function on a `ServiceTicket`

type ServiceTicket

type ServiceTicket struct {
	ID                int       `ztic:"Service Order ID"`
	Description       string    `ztic:"Service Order Description"`
	Owner             Contact   `ztic:"Employee Responsible Name"`
	PostingDate       time.Time `ztic:"Posting Date,02.01.2006"`
	FirstResponseTime time.Time `ztic:"First Response Date,02.01.2006 15:04:05 "`
	FollowUpDate      time.Time `ztic:"Follow-up Date,02.01.2006"`
	ChangedOnTime     time.Time `ztic:"Changed On,02.01.2006 15:04:05"`
	UserStatus        string    `ztic:"User Status"`
}

ServiceTicket describes a service ticket

func (*ServiceTicket) InLocation

func (s *ServiceTicket) InLocation(loc *time.Location) *ServiceTicket

InLocation returns a copy of `s` where all dates have been set to given `loc`.

func (*ServiceTicket) String

func (s *ServiceTicket) String() string

type ServiceTickets

type ServiceTickets []*ServiceTicket

ServiceTickets represents a list of `ServiceTicket`

func (ServiceTickets) Filter

func (l ServiceTickets) Filter(pred Predicate) ServiceTickets

Filter returns `ServiceTickets` which match given `Predicate`

func (ServiceTickets) InLocation

func (l ServiceTickets) InLocation(loc *time.Location) ServiceTickets

InLocation returns a copy of `l` where all dates have been set to given `loc`.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalZTIC(data string) error
}

Unmarshaler is the interface implemented by types that can unmarshal a string description of themselves. The input can be assumed to be a valid string.

Jump to

Keyboard shortcuts

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