Пример #1
0
func main() {
	goweb.MapFunc("/test/{func}/respond", func(c *goweb.Context) {
		fmt.Fprintf(c.ResponseWriter, "You called me with %s!", c.PathParams["func"])
	})

	goweb.ListenAndServe(":8080")
}
Пример #2
0
func main() {

	if toris.ShowModules {
		log.Println("Installed modules", toris.Context.ModuleList())
		os.Exit(0)
	}

	c := toris.Context.ConfigFile

	serverPort, _ := c.GetInt("server", "port")

	// Add default result formatter (JSON)
	goweb.ConfigureDefaultFormatters()

	// start the modules
	for name, _ := range toris.Context.ModuleList() {
		log.Println("Starting module " + name)
		err := toris.Context.Start(name)
		if err != nil {
			log.Println("[ERROR]", "An exception was raised", err)
		} else {
			log.Println("OK")
		}
	}

	serverUrl := fmt.Sprintf(":%d", serverPort)
	log.Println("Starting server on: " + serverUrl)
	log.Fatal(goweb.ListenAndServe(serverUrl))

}
Пример #3
0
func main() {

	handler := func(c *goweb.Context) {
		name := c.PathParams["name"]
		animal := c.PathParams["animal"]
		fmt.Fprintf(c.ResponseWriter, "Hey %s, your favorite animal is a %s", name, animal)
	}

	goweb.MapFunc("/people/{name}/animals/{animal}", handler)
	goweb.ListenAndServe(":8080")
}
Пример #4
0
func main() {
	controller := new(MyController)
	goweb.MapRest("/api", controller)
	goweb.ListenAndServe(":8080")
}