Example #1
0
func Serve(args []string) {
	if len(args) < 1 {
		displayServeError("missing broker url", nil)
	}

	pwd, _ := os.Getwd()
	pd := file.ProjDirFrom(pwd)
	if pd == "" {
		displayServeError("must be called within social machines project", nil)
	}

	scope := rt.NewScope(nil)
	_, err := LoadProjectDir(pd, scope)
	if err != nil {
		displayServeError("failed to load project directory", err)
	}

	ln, port := rt.StartListening(10810)
	rt.RT.Port = port

	pname := filepath.Base(pd)
	body := encodeProject(pname, port)
	postErr := postProjectToBroker(args[0], pname, body)
	if postErr != nil {
		displayServeError("failed to post project to broker", err)
	}

	log.Printf("Serving '%s' on %d => %s\n", pname, port, args[0])
	log.Fatal(http.Serve(ln, nil))
}
Example #2
0
func startREPL(s *rt.Scope) {
	if len(rt.RT.Peers) > 0 {
		ln, port := rt.StartListening(10810)
		rt.RT.Port = port

		go http.Serve(ln, nil)
	}

	for {
		fmt.Printf(">>> ")
		reader := bufio.NewReader(os.Stdin)
		raw, _ := reader.ReadString('\n')

		input := strings.TrimSpace(raw)
		if input != "" {
			if isConsoleCmd(input) {
				evalConsoleCmd(input)
			} else {
				evaluateInput(input, s)
			}
		}
	}
}