示例#1
0
文件: main.go 项目: everfore/rpcsv
func markdown(rw http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	rawContent := req.Form.Get("rawContent")
	// fmt.Println(req.RemoteAddr, req.Referer())
	fmt.Print(".")
	// fmt.Println(rawContent)
	out := make([]byte, 0, 100)
	in := goutils.ToByte(rawContent)
	times := 0
	connect()
retry:
	times++
	err := rpcsv.Markdown(RPC_Client, &in, &out)
	if goutils.CheckErr(err) {
		connect()
		if times < 6 {
			goto retry
		}
		rw.Write(goutils.ToByte(err.Error()))
		return
	}

	data := make(map[string]interface{})
	data["MDContent"] = template.HTML(goutils.ToString(out))
	err = rpcsv.Theme.Execute(rw, data)
	if goutils.CheckErr(err) {
		rw.Write(goutils.ToByte(err.Error()))
	}
	// if len(out) <= 0 {
	// 	rw.Write(goutils.ToByte("{response:nil}"))
	// 	return
	// }
	// writeCrossDomainHeaders(rw, req)
	// rw.Write(out)
}
示例#2
0
文件: main.go 项目: everfore/rpcsv
func markdownCBQiniu(rw http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	rawContent := req.Form.Get("rawContent")
	// fmt.Println(rawContent)
	fmt.Print(",")
	out := make([]byte, 0, 100)
	in := goutils.ToByte(rawContent)
	RPC_Client = rpcsv.RPCClient(rpc_tcp_server)
	err := rpcsv.Markdown(RPC_Client, &in, &out)
	if goutils.CheckErr(err) {
		rw.Write(goutils.ToByte(err.Error()))
		return
	}
	qiniuWriter.Reset()
	qiniuWriter.Write(goutils.ToByte("CallbackFunc(`"))
	data := make(map[string]interface{})
	data["MDContent"] = template.HTML(goutils.ToString(out))
	err = rpcsv.Theme.Execute(qiniuWriter, data)
	if goutils.CheckErr(err) {
		rw.Write(goutils.ToByte(err.Error()))
	}
	qiniuWriter.Write(goutils.ToByte("`)"))
	rw.Write(qiniuWriter.Bytes())
	writeCrossDomainHeaders(rw, req)
}
示例#3
0
文件: main.go 项目: shaalx/mdbgEg
// in: Linux/index.md
// out: ./MDFs
func modifiedMD(file_in, dir_out string) {
	finfo, err := os.Stat(file_in)
	if goutils.CheckErr(err) {
		return
	}
	filename := finfo.Name()
	dir := filepath.Dir(file_in)
	fs := strings.Split(filename, ".")
	in := goutils.ReadFile(file_in)
	out := make([]byte, 1)
	err = rpcsv.Markdown(rpc_client, &in, &out)
	if goutils.CheckErr(err) {
		return
	}
	// fmt.Println(goutils.ToString(out))
	target := fmt.Sprintf("%s.html", filepath.Join(dir_out, dir, fs[0]))

	goutils.Mkdir(fmt.Sprintf("%s", filepath.Join(dir_out, dir)))
	outfile, _ := os.OpenFile(fmt.Sprintf("%s.html", filepath.Join(dir_out, dir, fs[0])), os.O_CREATE|os.O_WRONLY, 0666)
	defer outfile.Close()
	dt := make(map[string]interface{})
	dt["MDContent"] = template.HTML(goutils.ToString(out))
	tpl.Execute(outfile, dt)
	fmt.Println(file_in, " ==> ", target)
}
示例#4
0
文件: main.go 项目: shaalx/bookmark
func markdown(rw http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	rawContent := req.Form.Get("rawContent")
	fmt.Println(req.RemoteAddr, req.Referer())
	// fmt.Println(rawContent)
	out := make([]byte, 0, 100)
	in := goutils.ToByte(rawContent)
	RPC_Client = rpcsv.RPCClient(rpc_tcp_server)
	err := rpcsv.Markdown(RPC_Client, &in, &out)
	if goutils.CheckErr(err) {
		rw.Write(goutils.ToByte(err.Error()))
		return
	}
	if len(out) <= 0 {
		rw.Write(goutils.ToByte("{response:nil}"))
		return
	}
	writeCrossDomainHeaders(rw, req)
	rw.Write(out)
}