示例#1
0
func main() {
	z, err := expr.EvalString(strings.Join(os.Args[1:], " "))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Println(z)
	}
}
示例#2
0
func CalcServer(w http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	if q := req.Form.Get("q"); q != "" {
		if x, err := expr.EvalString(q); err == nil {
			req.Form.Set("q", x.String())
		} else {
			req.Form.Set("e", err.Error())
		}
	}
	req.Form.Set("r", serveRoute)
	templ.Execute(w, req.Form)
}