func (c *Ctx) W(args ...string) error { if len(args) < 1 { return Err("write file error:%v", "file path not set") } if len(args) < 2 { return Err("write file error:%v", "content not set") } fpath := c.Compile(args[0]) f, err := os.OpenFile(args[0], os.O_CREATE|os.O_RDWR, 0644) if err != nil { return err } defer f.Close() var val interface{} = nil if e_reg_v.MatchString(args[1]) { val, err = c.Kvs.ValP(strings.Trim(args[1], " \t$()")) if err != nil { return err } } else { val = args[1] } var l int = 0 if mv := util.MapVal(val); mv != nil { jbys, _ := json.Marshal(mv) l, err = f.Write(jbys) } else { l, err = f.WriteString(util.StrVal(val)) } if err == nil { c.log("wite %d data to file:%v", l, fpath) } return err }
func ValY(v interface{}) bool { if v == nil { return false } if bv, ok := v.(bool); ok { return bv } iv := util.IntVal(v) if iv != math.MaxInt64 { return iv != 0 } sv := util.StrVal(v) if len(sv) > 0 { return true } return false }