Example #1
0
func SendF(w http.ResponseWriter, r *http.Request, fname, tfile, ctype string, attach bool) {
	src, err := os.Open(tfile)
	if err != nil {
		http.NotFound(w, r)
		return
	}
	err = sendf(w, src, fname, ctype, attach)
	if err != nil {
		log.E("sending file(%v) error:%s", tfile, err.Error())
		http.NotFound(w, r)
		return
	}
}
Example #2
0
func StoreCache(fname string) {
	f, err := os.OpenFile(fname, os.O_CREATE|os.O_RDWR, 0644)
	if err != nil {
		log.E("open file(%s) error:%s", fname, err.Error())
		return
	}
	defer f.Close()
	buf := bufio.NewWriter(f)
	buf.WriteString("mode: set\n")
	for k, v := range cache {
		buf.WriteString(fmt.Sprintf("%v %v %v\n", k, v.A, v.B))
	}
	buf.Flush()
}
Example #3
0
File: jcr.go Project: Centny/Cny4go
func JcrStore(hs *routing.HTTPSession) routing.HResult {
	var cover string
	err := hs.ValidRVal(`
		cover,R|S,L:0
		`, &cover)
	if err != nil {
		return hs.MsgResE(1, err.Error())
	}
	spath := _conf_.SavePath()
	log.D("saving coverage report to %s", spath)
	err = util.FWrite(spath, cover)
	if err != nil {
		log.E("saving coverage report to %s error:%s", spath, err.Error())
		return hs.MsgResE(1, err.Error())
	} else {
		return hs.MsgRes("SUCCESS")
	}
}
Example #4
0
func RunAppend(dir, ex, in, out, js string) error {
	exs := strings.Split(ex, ",")
	ins := strings.Split(in, ",")
	dir, _ = filepath.Abs(dir)
	out, _ = filepath.Abs(out)
	if !util.Fexists(out) {
		err := os.Mkdir(out, os.ModePerm)
		if err != nil {
			fmt.Println(err.Error())
			return err
		}
	}
	cover_c := 0
	err := list(dir, out, func(path string) error {
		if match(exs, path) {
			return nil
		}
		if !match(ins, path) {
			return nil
		}
		defer func() {
			cover_c++
		}()
		opath := out + "/" + strings.TrimPrefix(path, dir)
		odir := filepath.Dir(opath)
		os.MkdirAll(odir, os.ModePerm)
		err := util.FCopy(path, opath)
		if err != nil {
			return err
		}
		return util.FAppend(opath, fmt.Sprintf(`
<script type="text/javascript" src="%s" ></script>
			`, js))
	})
	if err != nil {
		log.E("jcr error:%s", err.Error())
	} else {
		log.D("jcr execute success, %d file is covered...", cover_c)
	}
	return err
}