Example #1
0
func main() {
	xweb.AddAction(&MainAction{})
	xweb.RootApp().AppConfig.CheckXsrf = false
	go xweb.Run("0.0.0.0:9999")

	values := url.Values{"key": {"Value"}, "id": {"123"},
		"user.id": {"2"}, "user2.ptrId": {"3"},
		"user2.id": {"4"}, "user2.child.id": {"66"},
		"keys":  {"1", "2", "3"},
		"keys2": {"1", "2", "3"},
	}
	resp, err := http.PostForm("http://127.0.0.1:9999/", values)
	if err != nil {
		fmt.Println(err)
		return
	}

	bytes, err := ioutil.ReadAll(resp.Body.(io.Reader))
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(bytes))

	var s chan int
	<-s
}
Example #2
0
func main() {
	defer func() {
		if res := recover(); res != nil {
			content := fmt.Sprintf("Crashed with error: %v", res)
			for i := 1; ; i += 1 {
				_, file, line, ok := runtime.Caller(i)
				if !ok {
					break
				} else {
					content += "\n"
				}
				content += fmt.Sprintf("%v %v", file, line)
			}

			fmt.Println(content)
		}
	}()

	models.InitModels()

	mode, _ := models.Cfg.GetValue("app", "run_mode")
	var isPro bool = true
	if mode == "dev" {
		log.SetOutputLevel(log.Ldebug)
		isPro = false
	}
	log.Info("run in " + mode + " mode")
	f, err := os.Create("./website.log")
	if err != nil {
		fmt.Println(err)
		return
	}

	log.SetOutput(io.MultiWriter(f, os.Stdout))
	xweb.SetLogger(log.Std)

	actions.InitApp()

	// Register routers.
	xweb.AddAction(&actions.HomeAction{})
	xweb.AutoAction(&actions.DocsAction{}, &actions.LinkAction{})
	xweb.AddTmplVars(&xweb.T{
		"i18n":    i18n.Tr,
		"IsPro":   isPro,
		"AppVer":  APP_VER,
		"XwebVer": xweb.Version,
		"GoVer":   strings.Trim(runtime.Version(), "go"),
	})
	port, _ := models.Cfg.GetValue("app", "http_port")
	usessl, _ := models.Cfg.GetValue("app", "ssl")
	if usessl == "true" {
		tlsCfg, _ := xweb.SimpleTLSConfig("cert.pem", "key.pem")
		xweb.RunTLS(fmt.Sprintf(":%v", port), tlsCfg)
	} else {
		xweb.Run(fmt.Sprintf(":%v", port))
	}
}
Example #3
0
func main() {
	app1 := xweb.NewApp("/")
	app1.AddAction(&MainAction{})
	xweb.AddApp(app1)

	app2 := xweb.NewApp("/user/")
	app2.AddAction(&MainAction{})
	xweb.AddApp(app2)

	xweb.Run("0.0.0.0:9999")
}
Example #4
0
func main() {
	f, err := os.Create("server.log")
	if err != nil {
		println(err.Error())
		return
	}
	logger := log.New(f, "", log.Ldate|log.Ltime)

	xweb.AddAction(&MainAction{})
	xweb.SetLogger(logger)
	xweb.Run("0.0.0.0:9999")
}
Example #5
0
func main() {
	xweb.AddAction(&MainAction{})

	app := xweb.MainServer().RootApp
	filter := xweb.NewLoginFilter(app, "userId", "/login")
	filter.AddAnonymousUrls("/", "/login", "/logout")
	app.AddFilter(filter)
	//app.AppConfig.StaticFileVersion = false

	f, err := os.Create("simple.log")
	if err != nil {
		println(err.Error())
		return
	}
	logger := log.New(f, "", log.Ldate|log.Ltime)
	xweb.SetLogger(logger)
	xweb.Run("0.0.0.0:8080")
}
Example #6
0
File: main.go Project: gr4y/website
func main() {
	models.InitModels()

	mode, _ := models.Cfg.GetValue("app", "run_mode")
	var isPro bool = true
	if mode == "dev" {
		log.SetOutputLevel(log.Ldebug)
		isPro = false
	}
	log.Info("run in " + mode + " mode")
	f, err := os.Create("./website.log")
	if err != nil {
		fmt.Println(err)
		return
	}

	log.SetOutput(io.MultiWriter(f, os.Stdout))
	xweb.SetLogger(log.Std)

	actions.InitApp()

	// Register routers.
	xweb.AddAction(&actions.HomeAction{})
	xweb.AutoAction(&actions.DocsAction{}, &actions.LinkAction{})
	xweb.AddTmplVars(&xweb.T{
		"i18n":    i18n.Tr,
		"IsPro":   isPro,
		"AppVer":  APP_VER,
		"XwebVer": xweb.Version,
		"GoVer":   strings.Trim(runtime.Version(), "go"),
	})
	port, _ := models.Cfg.GetValue("app", "http_port")
	usessl, _ := models.Cfg.GetValue("app", "ssl")
	if usessl == "true" {
		tlsCfg, _ := xweb.SimpleTLSConfig("cert.pem", "key.pem")
		xweb.RunTLS(fmt.Sprintf(":%v", port), tlsCfg)
	} else {
		xweb.Run(fmt.Sprintf(":%v", port))
	}
}
Example #7
0
func main() {
	xweb.RootApp().AppConfig.SessionOn = false
	xweb.AddRouter("/", &MainAction{})
	xweb.Run("0.0.0.0:9999")
}
Example #8
0
func main() {
	xweb.AddAction(&MainAction{})
	xweb.Run("0.0.0.0:9999")
}
Example #9
0
func main() {
	xweb.AutoAction(&MainAction{})
	xweb.Run("0.0.0.0:9999")
	//visit http://localhost:9999/main/world
}
Example #10
0
func main() {
	xweb.AddRouter("/", &MainAction{})
	xweb.Run("0.0.0.0:9999")
}
Example #11
0
func main() {
	xweb.AddAction(&CookieAction{})
	xweb.Run("0.0.0.0:9999")
}