Esempio n. 1
0
func main() {
	// Pull in command line options or defaults if none given
	flag.Parse()

	f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err == nil {
		defer f.Close()
		log.SetOutput(f)
	}

	skylib.Setup(sName)

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	rpc.HandleHTTP()

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	stack := new(mango.Stack)
	stack.Address = portString

	routes := make(map[string]mango.App)
	routes["/"] = homeHandler
	routes["/new"] = submitHandler
	stack.Middleware(mango.Routing(routes))
	stack.Run(nil)
}
Esempio n. 2
0
func main() {
	stack := new(mango.Stack)
	stack.Address = ":3300"

	// Route all requests for /goodbye to the Goodbye handler
	routes := map[string]mango.App{"/goodbye(.*)": Goodbye}
	stack.Middleware(mango.Routing(routes))
	stack.Middleware(mango.ShowErrors("ERROR!!"))

	//stack.Run(Hello)
	fmt.Println("type of stack: ", reflect.TypeOf(stack))
	//fmt.Println("type of m: ", reflect.TypeOf(m))
	fmt.Println("type of hello: ", reflect.TypeOf(Hello))

	var x float64 = 3.4
	v := reflect.ValueOf(x)
	fmt.Println("type:", v.Type())
	fmt.Println("kind is float64:", v.Kind() == reflect.Float64)
	fmt.Println("value:", v.Float())

	type T struct {
		A int
		B string
	}
	t := T{23, "skidoo"}
	s := reflect.ValueOf(&t).Elem()
	typeOfT := s.Type()
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		fmt.Printf("%d: %s %s = %v\n", i,
			typeOfT.Field(i).Name, f.Type(), f.Interface())
	}
}
Esempio n. 3
0
func main() {
	stack := new(mango.Stack)
	stack.Address = ":" + os.Getenv("PORT")

	// Route all requests for /goodbye to the Goodbye handler
	routes := map[string]mango.App{"/goodbye(.*)": Goodbye}
	stack.Middleware(mango.Routing(routes))

	// Hello handles all requests not sent to Goodbye
	stack.Run(Hello)
}
Esempio n. 4
0
func StartServer() {
	routes := make(map[string]mango.App)
	routes["/hello"] = new(mango.Stack).Compile(hello)
	routes["/bye"] = new(mango.Stack).Compile(bye)

	testServer := new(mango.Stack)
	testServer.Middleware(mango.ShowErrors("<html><body>{Error|html}</body></html>"), mango.Routing(routes))
	testServer.Address = "localhost:" + Configuration.Server_Port
	testServer.Run(routeNotFound)
	fmt.Printf("Running server on: %s\n", testServer.Address)
}
Esempio n. 5
0
func main() {
	// Pull in command line options or defaults if none given
	flag.Parse()

	skylib.NewAgent().Start()

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	stack := new(mango.Stack)
	stack.Address = portString

	routes := make(map[string]mango.App)
	routes["/"] = homeHandler
	routes["/new"] = submitHandler
	stack.Middleware(mango.Routing(routes))
	stack.Run(nil)
}
Esempio n. 6
0
func main() {
	// Load config with webconf on first available port
	appConfig := Config{}
	for p := 50000; ; p++ {
		c := webconf.New(&appConfig, "config.json", ":"+strconv.Itoa(p), nil)
		if c != nil {
			if err := c.Load(); err == nil {
				break // Config loaded
			}
		}
	}

	// Connect to DB
	db, err := sql.Open("postgres", appConfig.DbConnection)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// Intialize DB schema if necessary
	err = initDatabase(db)
	if err != nil {
		log.Fatal(err)
	}

	// Configure Mango
	stack := &mango.Stack{}
	stack.Address = appConfig.BindAddress

	cookieOptions := mango.CookieOptions{
		strings.Split(appConfig.BindAddress, ":")[0],
		"/",
		86400, // One day expiration
		true,
		true,
	}

	// Setup routes
	routes := make(map[string]mango.App)

	routes["/login"] = stack.Compile(login)
	routes["/edit/event"] = stack.Compile(editEvent)
	routes["/edit/event/([0-9]+)"] = stack.Compile(editEvent)
	routes["/edit/asset"] = stack.Compile(editAsset)
	routes["/edit/asset/([0-9]+)"] = stack.Compile(editAsset)
	routes["/asset/([0-9]+)"] = stack.Compile(displayAsset)
	routes["/user/([0-9]+)"] = stack.Compile(displayUser)
	routes["/asset"] = stack.Compile(listAssets)
	routes["/user"] = stack.Compile(listUsers)
	routes["/"] = stack.Compile(listAssets)

	stack.Middleware(
		mango.ShowErrors(""),
		mango.Sessions(appConfig.SessionSecret, "asset-tracker", &cookieOptions),
		AssetTracker(db, initTemplates()),
		mango.Static("static"),
		mango.Routing(routes),
	)

	stack.Run(defaultHandler)

	for {
	}
}