func main() {
	args := readArgs()

	if args.debug {
		log.Println("Running in debug mode")
	}

	info, readerr := lib.ReadInfo(os.Stdin)
	if readerr != nil {
		log.Printf("Info read error: %v", readerr)
	}

	const prefix = ""
	h := rest.MakeWebservice(info, args.jobs, prefix)

	// Add CORS to the handler
	if args.origins != "" {
		h = newcorshandler(h, args)
	}

	// Add logging to the handler
	if args.debug {
		h = loghandler{handler: h}
		rest.Debug()
	}

	addr := fmt.Sprintf("%v:%v", args.bind, args.port)
	httperr := http.ListenAndServe(addr, h)
	if httperr != nil {
		log.Fatal(httperr)
	}
}
Exemple #2
0
func main() {
	var input io.Reader = os.Stdin
	var output io.Writer = os.Stdout

	args := readArgs()
	validerr := args.zt.Validate()
	if validerr != nil {
		log.Fatal(validerr)
	}

	info, readerr := lib.ReadInfo(input)
	if readerr != nil {
		log.Fatal("Could not read info:", readerr)
	}

	z := lib.Zoom{}
	z.ZoomTarget = args.zt
	z.Prev = *info

	frames, moverr := z.Movie()
	if moverr != nil {
		log.Fatal("Error zooming:", moverr)
	}

	for _, info := range frames {
		outerr := lib.WriteInfo(output, info)
		if outerr != nil {
			log.Println("Error writing output:", outerr)
			break
		}
	}
}
func readInfo(args *commandLine) (*godelbrot.Info, error) {
	if args.config == "(none)" {
		desc := &godelbrot.Info{}
		desc.PaletteType = godelbrot.Pretty
		return desc, nil
	} else {
		f, err := os.Open(args.config)
		if err != nil {
			return nil, err
		}
		defer f.Close()
		return godelbrot.ReadInfo(f)
	}
}
// Validate and extract a render description from the command line arguments
func newRequest(args commandLine) (*config.Request, error) {
	user, uerr := userReq(args)

	if uerr != nil {
		return nil, uerr
	}

	var req *config.Request
	if args.reconfigure {
		desc, rerr := godelbrot.ReadInfo(os.Stdin)
		if rerr != nil {
			return nil, rerr
		}
		req = &desc.UserRequest
	} else {
		req = godelbrot.DefaultRequest()
	}

	argact := map[string]func(){
		"fix":      func() { req.FixAspect = user.FixAspect },
		"palette":  func() { req.PaletteCode = user.PaletteCode },
		"numerics": func() { req.Numerics = user.Numerics },
		"prec":     func() { req.Precision = user.Precision },
		"jobs":     func() { req.Jobs = user.Jobs },
		"collapse": func() { req.RegionCollapse = user.RegionCollapse },
		"render":   func() { req.Renderer = user.Renderer },
		"iterlim":  func() { req.IterateLimit = user.IterateLimit },
		"divlim":   func() { req.DivergeLimit = user.DivergeLimit },
		"width":    func() { req.ImageWidth = user.ImageWidth },
		"height":   func() { req.ImageHeight = user.ImageHeight },
		"rmin":     func() { req.RealMin = user.RealMin },
		"rmax":     func() { req.RealMax = user.RealMax },
		"imin":     func() { req.ImagMin = user.ImagMin },
		"imax":     func() { req.ImagMax = user.ImagMax },
		"samples":  func() { req.RegionSamples = user.RegionSamples },
		"reconf":   func() {},
	}

	flag.Visit(func(fl *flag.Flag) {
		act := argact[fl.Name]
		if act == nil {
			log.Fatal("BUG: unknown action ", fl.Name)
		}
		act()
	})

	return req, nil
}
func (rq *renderqueue) sysdraw(rqi *rqitem, pkt *renderpacket) {
	code := hashcode("")
	if __DEBUG {
		code = rqi.hash()
	}
	var zoomArgs []string
	if pkt.wantzoom {
		zoomArgs = process.ZoomArgs(lib.ZoomTarget{ZoomTarget: pkt.target})
	}

	buffs, berr := rqi.mkbuffs()

	if berr != nil {
		rqi.fail("failed input buffer")
		log.Printf("Buffer input error: %v, for packet %v (%v)",
			berr, rqi.hash(), rqi.packet())
		return
	}
	renderErr := rq.rs.render(buffs, zoomArgs)
	debugf("Rendered packet %v", code)

	// Copy any stderr messages
	buffs.logReport()

	if renderErr != nil {
		rqi.fail("failed render")
		log.Printf("Render error: %v, for packet %v (%v)",
			renderErr, rqi.hash(), rqi.packet())
		return
	}

	zoominfo, infoerr := lib.ReadInfo(&buffs.nextinfo)
	if infoerr != nil {
		rqi.fail("failed output buffer")
		log.Printf("Buffer output error: %v, for packet %v (%v)",
			infoerr, rqi.hash(), rqi.packet())
		return
	}

	log.Printf("Prev/Next Info for %v:\n    * Prev:\n%v\n    *Next: %v", code, rqi.packet().info, zoominfo)

	rq.ic.put(rqi.hash(), buffs.png.Bytes())
	rqi.done(zoominfo)
}
func main() {
	args := readArgs()

	if (args.cycle && args.getrq == "") || args.newrq {
		if args.config.Debug {
			log.Println("Reading stdin...")
		}
		info, ierr := lib.ReadInfo(os.Stdin)
		fatalguard(ierr)
		args.req = info.GenRequest()
	}

	shcl := newShellClient(args)

	zoomparts := map[string]bool{
		"xmin": true,
		"xmax": true,
		"ymin": true,
		"ymax": true,
	}

	first := true
	flag.Visit(func(fl *flag.Flag) {
		_, ok := zoomparts[fl.Name]
		if ok {
			shcl.zoom = true
			if args.config.Debug && first {
				log.Printf("Found parameter %v: zooming", fl.Name)
				first = false
			}
		}
	})

	// Ugly
	var r io.Reader
	if args.cycle {
		result, err := shcl.cycle()
		fatalguard(err)
		if args.config.Debug {
			log.Printf("RequestUrl: %v", result.Status.ThisUrl)
		}
		r = result.Image
	} else if args.newrq {
		rqi, err := shcl.newrq()
		fatalguard(err)
		reqr, jerr := jsonr(rqi)
		fatalguard(jerr)
		r = reqr
	} else if args.getrq != "" {
		rqi, err := shcl.getrq()
		fatalguard(err)
		reqr, jerr := jsonr(rqi)
		fatalguard(jerr)
		r = reqr
	} else if args.getimag != "" {
		png, err := shcl.getimag()
		fatalguard(err)
		r = png
	}

	_, cpyerr := io.Copy(os.Stdout, r)
	fatalguard(cpyerr)
}