Beispiel #1
0
func processForm(req *http.Request, context map[string]string) {
	file, handler, err := req.FormFile("uploadfile")
	if err != nil {
		context["Error"] = "Sudoku file missing"
		log.Println("Could not open sudoku file.", err.Error())
		return
	}

	if len(handler.Header["Content-Type"]) > 0 {
		context["ContentType"] = handler.Header["Content-Type"][0]
	}

	img, _, err := image.Decode(file)
	if err != nil {
		context["Error"] = "Could not read the file"
		log.Println("Could not read the file.", err.Error())
		return
	}
	s, err := sudoku.NewSudoku(img)
	if err != nil {
		context["Error"] = err.Error()
		log.Println(err.Error())
		return
	}
	context["Image"] = imageToBase64(s.Overlay())
}
Beispiel #2
0
func findSudoku(filename string, debug bool) (sudoku.Sudoku, error) {
	img, err := getExampleImage(filename)
	if err != nil {
		log.Fatalln(err)
	}

	return sudoku.NewSudoku(img)
}