--- /dev/null
+package part
+
+import (
+ "github.com/thedevsaddam/gojsonq"
+)
+
+type json struct {}
+
+func Json() (*json) {return &json{}}
+
+func (*json) GetValFrom(file,key string)interface {}{
+ var jq *gojsonq.JSONQ
+ if Checkfile().IsExist(file) {
+ jq = gojsonq.New().File(file)
+ }else{
+ jq = gojsonq.New().FromString(file)
+ }
+ return jq.Find(key)
+}
\ No newline at end of file
--- /dev/null
+package part
+
+import (
+ "os"
+ "sync"
+)
+
+type lock struct {
+ sync.Mutex
+}
+
+var (
+ lock_file *os.File
+ lock_md5Key string
+)
+
+func Lock() *lock {
+ return &lock{}
+}
+
+func (l *lock) Start(filePath string) int {
+ l.Lock()
+ defer l.Unlock()
+
+ if l.State() {return 1}
+ if Checkfile().IsOpen(lock_md5Key) {return 2}
+ if !Checkfile().IsExist(filePath) {return 3}
+
+ lock_md5Key = ".lock."+filePath
+ lock_file, _ = os.Create(lock_md5Key)
+ return 0
+}
+
+func (l *lock) Stop() int {
+ l.Lock()
+ defer l.Unlock()
+
+ if !l.State() {return 1}
+ if !Checkfile().IsExist(lock_md5Key) {return 2}
+
+ lock_file.Close()
+ os.Remove(lock_md5Key)
+ lock_md5Key = ""
+ return 0
+}
+
+func (*lock) State() bool {
+ return lock_md5Key != ""
+}
\ No newline at end of file
"github.com/klauspost/compress/zip"
"io"
"path/filepath"
- "strings"
+ "strings"
+ "bytes"
+ "time"
)
type lzip struct {sync.Mutex}
}
return nil
+}
+
+type rZip struct {
+ poit *zip.ReadCloser
+ buf map[string]*zip.File
+}
+
+func RZip() *rZip {return &rZip{}}
+
+func (t *rZip) New(zipFile string) (error) {
+ t.buf = make(map[string]*zip.File)
+
+ var err error
+ t.poit, err = zip.OpenReader(zipFile)
+ if err != nil {return err}
+
+ for _, _f := range t.poit.File {
+ if _f.FileInfo().IsDir() {continue}
+ t.buf[_f.Name] = _f
+ }
+
+ return nil
+}
+
+func (t *rZip) Read(path string) (*bytes.Buffer,string,error) {
+ var timeLayoutStr = "2006-01-02 15:04:05"
+ var err error
+
+ if f,ok := t.buf[path];ok {
+ if rc, err := f.Open();err == nil {
+ defer rc.Close();
+
+ buf := new(bytes.Buffer)
+ buf.ReadFrom(rc)
+ return buf,f.FileHeader.Modified.Format(timeLayoutStr),nil
+ }
+ return &bytes.Buffer{},time.Now().UTC().Format(timeLayoutStr),err
+ }
+ return &bytes.Buffer{},time.Now().UTC().Format(timeLayoutStr),nil
+}
+
+func (t *rZip) Close() {
+ t.poit.Close()
+ for k := range t.buf {
+ delete(t.buf, k)
+ }
}
\ No newline at end of file
go 1.14
-require github.com/klauspost/compress v1.10.10
+require (
+ github.com/klauspost/compress v1.10.10
+ github.com/thedevsaddam/gojsonq v2.3.0+incompatible
+)
github.com/klauspost/compress v1.10.10 h1:a/y8CglcM7gLGYmlbP/stPE5sR3hbhFRUjCBfd/0B3I=
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
+github.com/thedevsaddam/gojsonq v1.9.1 h1:zQulEP43nwmq5EKrNWyIgJVbqDeMdC1qzXM/f5O15a0=
+github.com/thedevsaddam/gojsonq v2.3.0+incompatible h1:i2lFTvGY4LvoZ2VUzedsFlRiyaWcJm3Uh6cQ9+HyQA8=
+github.com/thedevsaddam/gojsonq v2.3.0+incompatible/go.mod h1:RBcQaITThgJAAYKH7FNp2onYodRz8URfsuEGpAch0NA=