예제 #1
0
func (cp *CodePasteChecker) processCode(code string, lang string) (string, bool) {
	var err error
	var issues string
	var with_issues bool

	var arg lotsawa.CompileArgs = lotsawa.CompileArgs{code, lang}
	var res lotsawa.CompileReply
	err = cp.cs.Compile(&arg, &res)

	if err != nil {
		cp.Logger.Println("Failed to call rpc service:", err)
		return "", false
	}

	if res.C_Output != "" || res.C_Error != "" {
		issues = fmt.Sprintf("%s%s", res.C_Output, res.C_Error)
		with_issues = true
	}

	if !with_issues {
		id, err := paste.Paste(code)
		if err != nil {
			return "", false
		}
		return id, false
	}

	data := fmt.Sprintf("%s\n\n"+
		"----------------------------------------------------------------\n"+
		"%s", code, issues)
	id, err := paste.Paste(data)
	if err != nil {
		return "", false
	}

	return id, true
}
예제 #2
0
파일: paste.go 프로젝트: fluter01/paste
func processFile(filename string) {
	var err error
	var data string
	var res string

	if filename == "-" {
		data, err = readFromStdin()
	} else {
		data, err = readFromFile(filename)
	}

	if err != nil {
		return
	}

	res, err = paste.Paste(data)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("URL:", res)
}