示例#1
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)
}
示例#2
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)
}
示例#3
0
func checktokenHandler(rw http.ResponseWriter, req *http.Request) {
	tokenURI := req.RequestURI
	token := filepath.Base(tokenURI)
	fmt.Println(token)
	remote, ok := tokenM[token]
	if ok {
		rw.Write(goutils.ToByte(fmt.Sprintf("current user IP:%v", remote)))
	} else {
		rw.Write(goutils.ToByte("wrong token."))
	}
}
示例#4
0
文件: main.go 项目: everfore/rpcsv
func indexV2(rw http.ResponseWriter, req *http.Request) {
	tpl, err := template.New("indexV2.html").ParseFiles("indexV2.html")
	if goutils.CheckErr(err) {
		rw.Write(goutils.ToByte(err.Error()))
		return
	}
	tpl.Execute(rw, nil)
}
示例#5
0
func logupHandler(rw http.ResponseWriter, req *http.Request) {
	count.Add(1)
	now := time.Now()
	token := logup.GenToken(&now)
	fmt.Println(token)
	tokenM[token] = req.RemoteAddr + "[" + count.String() + "]"
	rw.Write(goutils.ToByte(fmt.Sprintf("http://localhost:80/token/%s", token)))
}
示例#6
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)
}
示例#7
0
文件: c_test.go 项目: everfore/rpcsv
func TestWallBack(t *testing.T) {
	// return
	t.Parallel()
	c := RPCClientWithCodec(rpc_tcp_server)
	defer c.Close()
	job := Job{Name: "mdblog", Result: goutils.ToByte("mdblog-result")}
	out := make([]byte, 10)
	// in := make([]byte, 1)
	err := c.Call("RPC.WallBack", &job, &out)
	goutils.CheckErr(err)
	fmt.Println("out:", goutils.ToString(out))
}
示例#8
0
文件: main.go 项目: everfore/exc
func Cond(path string, info os.FileInfo) (ifExec bool, skip error) {
	if strings.EqualFold(info.Name(), ".git") {
		return false, filepath.SkipDir
	}
	if !info.IsDir() {
		if strings.HasSuffix(info.Name(), ".go") || strings.HasSuffix(info.Name(), "Dockerfile") {
			if bs, cnt := ContentContains(path, "shaalx"); cnt {
				fmt.Println(info.Name())
				rst_cnt := strings.Replace(goutils.ToString(bs), "shaalx", "toukii", -1)
				OverWrite(path, goutils.ToByte(rst_cnt))
				return true, nil
			}
		}
	}
	return false, nil
}
示例#9
0
文件: service.go 项目: everfore/rpcsv
func (r *RPC) WallBack(in *Job, out *([]byte)) error {
	if nil == in || r.back == nil {
		return fmt.Errorf("WallBack is nil")
	}
	c, ok := r.back[in.Name]
	if ok {
		select {
		case <-time.After(5e9):
			*out = goutils.ToByte(fmt.Sprintf("WallBack %s Timeout!!", in.Name))
			fmt.Println(fmt.Sprintf("WallBack %s Timeout!!", in.Name))
			break
		case c <- in.Result:
			fmt.Println(fmt.Sprintf("WallBack %s[%s]", in.Name, in.Target))
		}
	}
	return nil
}
示例#10
0
文件: main.go 项目: shaalx/mdbgEg
func init() {
	Spor = string(os.PathSeparator)
	// flag
	flag.BoolVar(&redo, "r", false, "-r [true]")
	flag.StringVar(&filename, "f", "README.md", "-f readme.md")
	flag.StringVar(&targetDir, "d", "./", "-d ./static")

	// theme
	thm_b := readFile(thm_file)
	if nil == thm_b {
		thm_b = goutils.ToByte(thm_s)
	}
	var err error
	theme, err = template.New("theme.thm").Parse(goutils.ToString(thm_b))
	if goutils.CheckErr(err) {
		panic(err.Error())
	}
}
示例#11
0
文件: default.go 项目: shaalx/upload
// @router /bash [post]
func (c *MainController) PBash() {
	req := c.Ctx.Request
	req.ParseForm()
	shcont := req.Form.Get("shcont")
	// fmt.Println(c.Ctx.Input.Request)
	// fmt.Println(c.Ctx.Input.Data)
	// shcont := c.Ctx.Input.Param("shcont")
	beego.Info(shcont)
	excm.Reset(shcont)
	b, err := excm.Debug().Do()
	if checkerr(err) {
		// c.Data["err"] = err.Error()
		b = append(b, goutils.ToByte(err.Error())...)
	} else {
		// c.Data["result"] = strings.Split(goutils.ToString(b), " ")
	}
	c.Ctx.ResponseWriter.Write(b)
	// return fmt.Sprintf("%v", ret)
	// c.TplName = "bash.html"
}
示例#12
0
文件: modle.go 项目: shaalx/gooj
func generateOjFunc(content string, w io.Writer) error {
	_, err := w.Write(goutils.ToByte(content))
	return err
}
示例#13
0
文件: main.go 项目: shaalx/webhooks
func index(rw http.ResponseWriter, req *http.Request) {
	rw.Write(goutils.ToByte("This is a webhooks service."))
}
示例#14
0
文件: judgec.go 项目: shaalx/gooj
// @router /oj/:id:int [post]
func (c *ListController) OJ() {
	var id int
	c.Ctx.Input.Bind(&id, ":id")
	if ojCheck(id) <= 0 {
		c.Data["Content"] = template.HTML("<h3>题目还未审核,如有问题,请联系管理员。</h3>")
		c.TplName = "sorry.html"
		return
	}
	fid := c.GetString("fid")
	path_ := c.GetString("rid")
	content := c.GetString("puzzle")
	if strings.Contains(content, `"os`) {
		c.Ctx.ResponseWriter.Write(goutils.ToByte("呵呵"))
		return
	}
	beego.Debug(content, path_, fid)

	// inser into db
	slt := models.Solution{}
	cur := c.SessionController.CurUser()
	if cur != nil {
		slt.User = &models.User{Id: cur.Id} //models.UserById(cur.Id)
	} else {
		slt.User = models.UserByName("Anonymous")
	}
	slt.Content = content
	// slt.Create = *goutils.LocNow("Asia/Shanghai")
	// fmt.Println(slt)
	ffid, _ := c.GetInt("fid")
	slt.Puzzle = &models.Puzzle{Id: ffid}
	n, dberr := models.ORM.Insert(&slt)
	if goutils.CheckErr(dberr) {

	}
	// insert into db

	submit_LOCKER.Lock()
	defer submit_LOCKER.Unlock()
	cmd := exc.NewCMD("go test -v").Cd(defaultpath)

	var puzzle models.Puzzle
	models.ORM.QueryTable((*models.Puzzle)(nil)).Filter("Id", id).One(&puzzle)
	m := Puzzle2Model(&puzzle)

	m.Content = content
	beego.Info(m)
	err := model_util.GenerateOjModle(path_, m)
	goutils.CheckErr(err)
	submitID++
	test_result, err := cmd.Wd().Cd(path_).Debug().Do()
	analyse_result := utils.Analyse(goutils.ToString(test_result))
	fmt.Println(analyse_result)
	goutils.CheckErr(err)
	if n > 0 {
		result := models.AnalyseResultParse(analyse_result)
		m, err := models.ORM.Insert(result)
		if !goutils.CheckErr(err) {
			result.Id = int(m)
		}
		slt.Result = result
		slt.Id = int(n)
		go func() {
			models.ORM.Update(&slt)
		}()
	}

	go cmd.Reset(fmt.Sprintf("rm -rf %s", path_)).Cd(defaultpath).Execute()

	c.Ctx.ResponseWriter.Write(goutils.ToByte(analyse_result.String()))
}