Example #1
0
func main() {
	conf.Load()

	runtime.GOMAXPROCS(conf.Wide.MaxProcs)

	defer glog.Flush()

	// 静态资源
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

	// 库资源
	http.Handle("/data/", http.StripPrefix("/data/", http.FileServer(http.Dir("data"))))

	// IDE 首页
	http.HandleFunc("/", indexHandler)

	// 运行相关
	http.HandleFunc("/build", output.BuildHandler)
	http.HandleFunc("/run", output.RunHandler)
	http.HandleFunc("/go/get", output.GoGetHandler)
	http.HandleFunc("/go/install", output.GoInstallHandler)
	http.HandleFunc("/output/ws", output.WSHandler)

	// 文件树
	http.HandleFunc("/files", file.GetFiles)
	http.HandleFunc("/file", file.GetFile)
	http.HandleFunc("/file/save", file.SaveFile)
	http.HandleFunc("/file/new", file.NewFile)
	http.HandleFunc("/file/remove", file.RemoveFile)

	// 编辑器
	http.HandleFunc("/editor/ws", editor.WSHandler)
	http.HandleFunc("/go/fmt", editor.GoFmtHandler)
	http.HandleFunc("/autocomplete", editor.AutocompleteHandler)
	http.HandleFunc("/finddecl", editor.FindDeclarationHandler)
	http.HandleFunc("/html/fmt", editor.HTMLFmtHandler)
	http.HandleFunc("/json/fmt", editor.JSONFmtHandler)

	// Shell
	http.HandleFunc("/shell/ws", shell.WSHandler)
	http.HandleFunc("/shell", shell.IndexHandler)

	// 用户
	http.HandleFunc("/user/new", user.AddUser)
	http.HandleFunc("/user/repos/init", user.InitGitRepos)

	// 文档
	http.Handle("/doc/", http.StripPrefix("/doc/", http.FileServer(http.Dir("doc"))))

	glog.V(0).Infof("Wide is running [%s]", conf.Wide.Server)

	err := http.ListenAndServe(conf.Wide.Server, nil)
	if err != nil {
		glog.Fatal(err)
	}
}
Example #2
0
File: main.go Project: toyang/wide
// The only one init function in Wide.
func init() {
	confPath := flag.String("conf", "conf/wide.json", "path of wide.json")
	confIP := flag.String("ip", "", "this will overwrite Wide.IP if specified")
	confPort := flag.String("port", "", "this will overwrite Wide.Port if specified")
	confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
	confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel if specified")
	confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified")
	confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
	confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified")
	confStat := flag.Bool("stat", false, "whether report statistics periodically")
	confDocker := flag.Bool("docker", false, "whether run in a docker container")
	confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified")

	flag.Parse()

	log.SetLevel("warn")
	logger = log.NewLogger(os.Stdout)

	wd := util.OS.Pwd()
	if strings.HasPrefix(wd, os.TempDir()) {
		logger.Error("Don't run Wide in OS' temp directory or with `go run`")

		os.Exit(-1)
	}

	i18n.Load()

	event.Load()

	conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel,
		*confPlayground, *confDocker)

	conf.FixedTimeCheckEnv()

	session.FixedTimeSave()
	session.FixedTimeRelease()

	if *confStat {
		session.FixedTimeReport()
	}

	logger.Debug("host ["+runtime.Version()+", "+runtime.GOOS+"_"+runtime.GOARCH+"], cross-compilation ",
		util.Go.GetCrossPlatforms())
}
Example #3
0
func addUser(username, password string) string {
	// TODO: https://github.com/b3log/wide/issues/23
	conf.Load()

	// XXX: 新建用户校验增强
	for _, user := range conf.Wide.Users {
		if user.Name == username {
			return USER_EXISTS
		}
	}

	newUser := conf.User{Name: username, Password: password}
	conf.Wide.Users = append(conf.Wide.Users, newUser)

	if !conf.Save() {
		return USER_CREATE_FAILED
	}

	glog.Infof("Created a user [%s]", username)

	return USER_CREATED
}