コード例 #1
0
ファイル: cl.go プロジェクト: zxpbenson/rog-go
func main() {
	var user g9p.User
	var file *g9pc.File

	flag.Parse()

	if *ouser == "" {
		user = g9p.OsUsers.Uid2User(os.Geteuid())
	} else {
		user = g9p.OsUsers.Uname2User(*ouser)
	}

	naddr := *addr
	if strings.LastIndex(naddr, ":") == -1 {
		naddr = naddr + ":5640"
	}

	var plog g9p.Logger
	if *serveHTTP != "" {
		plog = g9plog.NewClient(naddr, -1, 0)
		go func() {
			if err := http.ListenAndServe(*serveHTTP, nil); err != nil {
				log.Exitln("http listen: ", err)
			}
		}()
	}

	c, err := g9pc.Mount("tcp", naddr, "", user, plog)
	if err != nil {
		log.Exitln("error mounting %s: %s", naddr, err)
	}

	//	if *debug {
	//		c.Debuglevel = 1
	//	}
	//	if *debugall {
	//		c.Debuglevel = 2
	//	}

	walkone(c, "/")

	if file != nil {
		//process(c)
		fmt.Sprint(os.Stderr, "file reading unimplemented\n")
	} else if flag.NArg() > 0 {
		flags := flag.Args()
		for _, uc := range flags {
			cmd(c, uc)
		}
	} else {
		interactive(c)
	}

	return
}
コード例 #2
0
ファイル: main.go プロジェクト: AaronO/lightwave
func main() {
	log.SetFlags(log.Lshortfile)
	// Configure and start all servers
	config, err := configure()
	if err != nil {
		log.Exitln(err)
		return
	}

	//  lightwave.RegisterNodeFactory("application/x-protobuf-wave", wave.NewWaveletNode)
	//  lightwave.RegisterNodeFactory("application/x-json-wave", wave.NewWaveletNode)

	// Allow for JSON documents
	lightwave.RegisterNodeFactory("application/json", lightwave.DocumentNodeFactory)
	// Login pages post here to login and to be redirected
	http.HandleFunc("/_login", loginHandler)
	// Logout gets thus page to logout and to be redirected
	http.HandleFunc("/_logout", logoutHandler)
	// RPC to retrieve information about the session bound to the session cookie
	http.HandleFunc("/_sessioninfo", sessionInfoHandler)
	// The SignUp page posts here to register a new user and to be redirected
	http.HandleFunc("/_signup", signupHandler)
	// Opens a document and sends a snapshot to the client. Further updates to the document are sent as well
	http.HandleFunc("/_open", openHandler)
	// Stops sending updates of this document to the client
	http.HandleFunc("/_close", closeHandler)
	// Retrieves the latest document updates belonging to the current session. Return immediately if there are none.
	http.HandleFunc("/_sessionget", sessionGetHandler)
	// Retrieves the latest document updates belonging to the current session. Wait if there are none.
	http.HandleFunc("/_sessionpoll", sessionPollHandler)
	http.HandleFunc("/_session/_openView", openViewHandler)
	http.HandleFunc("/_session/_closeView", closeViewHandler)

	// Behave like a wave server with HTTP transport
	//  http.HandleFunc("/wave/fed/", waveFederationHandler)
	// Run the generalized federation protocol via HTTP. It is more powerful than wave but non-standard
	http.HandleFunc("/fed/", federationHandler)
	// Run the client/server protocol
	http.HandleFunc("/client/", clientHandler)
	// Serve static files (HTML, images)
	http.HandleFunc("/", fileHandler)
	err = http.ListenAndServe(fmt.Sprintf(":%v", config.Port), nil)
	if err != nil {
		log.Exitln(err)
	}
}