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
}
Beispiel #2
0
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)
}