Initial 2024-01-26
This commit is contained in:
87
cmpSnipper/cmpSnipperUtil.go
Normal file
87
cmpSnipper/cmpSnipperUtil.go
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
package cmpSnipper
|
||||
|
||||
import (
|
||||
"os"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func (app *App) FileReadLimit(file string, mSize int64) ([]byte, error) {
|
||||
info, err := os.Stat(file)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil, app.ErrIsDir
|
||||
}
|
||||
|
||||
fSize := info.Size()
|
||||
|
||||
if fSize > mSize {
|
||||
return nil, errors.New("File is big")
|
||||
}
|
||||
|
||||
fd, err := os.Open(file)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var rata = make([]byte, fSize);
|
||||
|
||||
rSize, err := fd.Read(rata);
|
||||
|
||||
if fSize != int64(rSize) {
|
||||
return nil, errors.New("Can't read full file size")
|
||||
}
|
||||
|
||||
return rata, nil
|
||||
}
|
||||
|
||||
func (app *App) UpperFirst(si string) string {
|
||||
bi := []byte(si)
|
||||
ss := strings.Title(string(bi[0]))
|
||||
bo := bi
|
||||
bo[0] = ss[0]
|
||||
|
||||
return string(bo)
|
||||
}
|
||||
|
||||
func (app *App) CallFuncByName(funcName string, ifcIL ...interface{}) ([]interface{}, error) {
|
||||
refCls := reflect.ValueOf(app)
|
||||
refMth := refCls.MethodByName(funcName)
|
||||
|
||||
if !refMth.IsValid() {
|
||||
app.Log("Call method \"%s\" not found", funcName)
|
||||
return nil, errors.New("Call method not founnd")
|
||||
}
|
||||
|
||||
app.Log("Call method \"%s\"", funcName)
|
||||
|
||||
refIL := make([]reflect.Value, len(ifcIL))
|
||||
|
||||
for i, ifcII := range ifcIL {
|
||||
refIL[i] = reflect.ValueOf(ifcII)
|
||||
}
|
||||
|
||||
// fmt.Println("reflect input list", refIL);
|
||||
|
||||
refOL := refMth.Call(refIL)
|
||||
|
||||
infOL := make([]interface{}, len(refOL))
|
||||
|
||||
for i, refOI := range refOL {
|
||||
infOL[i] = refOI.Interface()
|
||||
}
|
||||
|
||||
app.Log("Interface output list %+v", infOL)
|
||||
|
||||
return infOL, nil
|
||||
}
|
Reference in New Issue
Block a user