zkteco

package module
v0.0.0-...-5b25bf7 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2017 License: MIT Imports: 8 Imported by: 0

README

zkteco

Build Status Go Report Card

package zkteco parses the output files from zkteco device KQ803 and update to redis.It's based on Redigo.

How to use zkteco
  • Open opens the named file for reading. If successful, methods on the returned file can be used for reading

      if f, err = os.Open("/home/xx/1.csv"); err != nil {
          fmt.Printf("os.Open err: %v\n", err)
          return
      } 
    
  • NewKaoqin returns an pointer to Kaoqin by given Redis address, Redis password.

      if k, err = zkteco.NewKaoqin(":6379", ""); err != nil {
          fmt.Printf("zkteco.NewKaoqin err: %v\n", err)
          return
      }
    
  • Update attendances records(*File) to redis..

      if err = k.UpdateAttendances(f); err != nil {
        	fmt.Printf("UpdateAttendances err:%v\n", err)
          return
      }
    
Installation

Install Redigo using the "go get" command:

go get github.com/athrunecho/zkteco
Documentation
License

Documentation

Overview

Package zkteco parses the output files from zkteco device.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// DEBUG is debug mode. It'll output debug messages if it's true.
	DEBUG = true
)

Functions

func GetCSVRecords

func GetCSVRecords(r io.Reader) (records [][]string, err error)

GetCSVRecords returns records of a CSV file by given a type of io.Reader.

Example

1. Run "go test -c && ./zkteco.test" to generate test binary under root of project dir and start test.

2. Run "go test" will generate test binary under "/tmp" with a random test dir

package main

import (
	"log"
	"os"

	"github.com/athrunecho/zkteco"
	"github.com/northbright/pathhelper"
)

const (
	kaoqinFilePath = "./example/csv/attendance/attendance.csv"
)

// 1. Run "go test -c && ./zkteco.test" to generate test binary under root of project dir and start test.
//
// 2. Run "go test" will generate test binary under "/tmp" with a random test dir
func main() {
	var (
		err error
		p   string
		f   *os.File
		re  [][]string
	)

	log.Printf("\n")
	log.Printf("--------- GetCSVRecords() Test Begin --------\n")

	if p, err = pathhelper.GetAbsPath(kaoqinFilePath); err != nil {
		goto end
	}

	if f, err = os.Open(p); err != nil {
		goto end
	}
	defer f.Close()

	if re, err = zkteco.GetCSVRecords(f); err != nil {
		goto end
	}

	log.Printf("%v\n", re)

end:
	if err != nil {
		log.Printf("err: %v\n", err)
	}
	log.Printf("--------- BatchCreate() Test End --------\n")
}
Output:

func GetField

func GetField(t time.Time, i int) (field string)

GetField adds days and returns according to i.

func GetRedisConn

func GetRedisConn(redisAddr, redisPassword string) (c redis.Conn, err error)

GetRedisConn gets the Redis connection.

func GetStartDate

func GetStartDate(timeRange string) (t time.Time)

GetStartDate returns start time of attendance by given a time range.

Types

type Kaoqin

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

Kaoqin contains Redis address, Redis password and Redis connection

func NewKaoqin

func NewKaoqin(redisAddr, redisPassword string) (k *Kaoqin, err error)

NewKaoqin returns an pointer to Kaoqin by given Redis address, Redis password.

func (*Kaoqin) Close

func (k *Kaoqin) Close() error

Close close the redis connection from Kaoqin struct

func (*Kaoqin) UpdateAttendances

func (k *Kaoqin) UpdateAttendances(r io.Reader) (err error)

UpdateAttendances updates attendances records to redis.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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