Exemplo n.º 1
0
func main() {

	autoUpdate()

	m := martini.Classic()
	m.Use(martini.Static("static"))
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "content", []interface{}{getPage(1)})
	})

	m.Get("/api/:id", func(params martini.Params, r render.Render) {
		s := strings.Trim(params["id"], " .)(")
		id := atoi(s)
		r.JSON(200, getPage(id))
	})

	m.Get("/page/:id", func(params martini.Params, r render.Render) {
		s := strings.Trim(params["id"], " .)(")
		id := atoi(s)
		r.HTML(200, "content", []interface{}{getPage(id)})
	})

	http.ListenAndServe("0.0.0.0:8000", m)
	m.Run()
}
Exemplo n.º 2
0
func main() {
	m := martini.Classic()
	if os.Getenv("MARTINI_ENV") == "production" {
		g.devMode = false
	}

	if g.IsDevMode() {
		m.Use(runnerMiddleware)
	}
	g.InitDb()

	m.Use(martini.Static("public/app"))
	m.Use(func(resp http.ResponseWriter, req *http.Request) {
		if strings.HasPrefix(req.URL.Path, "/api/") {
			token := req.Header.Get("AuthToken")
			if token != "" {
				n, err := g.Db().SelectInt(`select count(*) from users where token=$1`, token)
				if err != nil && err != sql.ErrNoRows {
					log.Fatalf(err.Error())
				}
				if n > 0 {
					return
				}
			}

			resp.WriteHeader(http.StatusUnauthorized)
			resp.Write([]byte("You're not allowed to do this, sorry."))
		}
	})

	m.Get("/", func(r http.ResponseWriter) {
		t, err := template.ParseFiles("public/app/index.html")
		if err != nil {
			panic(err.Error())
		}
		t.Execute(r, nil)
	})

	m.Get("/auth", func(r http.ResponseWriter) {
		username, token := makeRandomUserToken()
		user := &biz.User{
			Username: username,
			Token:    token,
			Role:     biz.RoleUser,
		}
		checkErr(g.Db().Insert(user))
		resp, err := json.Marshal(map[string]interface{}{
			"username": user.Username,
			"token":    user.Token,
		})
		checkErr(err)
		r.Write(resp)
	})

	m.Get("/api/test", func(r http.ResponseWriter) {
		r.Write([]byte("CLGT"))
	})

	m.Run()
}
Exemplo n.º 3
0
func main() {
	m := martini.Classic()

	// log before and after a request
	m.Use(func(c martini.Context, log *log.Logger) {
		log.Println("before a request")

		c.Next()

		log.Println("after a request")
	})
	sublime.Route(m)

	store := sessions.NewCookieStore([]byte("secret_words_key_xxx"))
	m.Use(sessions.Sessions("weiyan_session", store))

	m.Get("/set", func(session sessions.Session) string {
		session.Set("hello", "world")
		return "OK"
	})

	m.Get("/get", func(session sessions.Session) string {
		v := session.Get("hello")
		if v == nil {
			return ""
		}
		return v.(string)
	})

	//m.Use("/admin", auth.Basic("username", "secretpassword"))
	m.Use(martini.Static("assets"))
	m.Run()
}
Exemplo n.º 4
0
func main() {
	m := martini.Classic()
	m.Map(SetupDB())
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	m.Use(martini.Static("assets"))

	m.Get("/", func(ren render.Render, r *http.Request, db *sql.DB) {
		rows, err := db.Query("SELECT * from videos")
		PanicIf(err)
		defer rows.Close()

		videos := []Video{}
		for rows.Next() {
			v := Video{}
			err := rows.Scan(&v.Id, &v.Title)
			PanicIf(err)
			videos = append(videos, v)
			// fmt.Fprintf(rw, "Title: %s", title)
		}

		ren.HTML(200, "videos", videos)
	})

	m.Run()
}
Exemplo n.º 5
0
func main() {
	// Get the configuration
	//
	if *configFile == "" {
		*configFile = "./nightcrawler.ini"
	}
	opts := globalconf.Options{Filename: *configFile, EnvPrefix: "NC_"}
	conf, _ := globalconf.NewWithOptions(&opts)
	conf.ParseAll()

	// Static assets should be served by nginx in production
	//
	println(martini.Env)
	m := martini.Classic()
	if martini.Env != "production" {
		m.Use(martini.Static("assets"))
	}

	//  This is just a temp route in development mode
	//
	if martini.Env == "development" {
		m.Get("/", UserRendererMiddleware(), func(r render.Render) {
			r.HTML(200, "root", nil)
		})
	}

	// Top level of app
	// This section is everything outside of authentication
	//
	m.Group("/app", func(r martini.Router) {
		r.Get("/sign_in", controllers.SignIn)
		r.Post("/sign_in", csrf.Validate, controllers.SignIn)
		r.Get("/sign_up", controllers.SignUp)
		r.Post("/sign_up", csrf.Validate, controllers.CreateSignUp)
		r.Get("/sign_out", controllers.SignOut)
		r.NotFound(func(x render.Render) {
			x.HTML(404, "404", nil)
		})
	},
		CookieStore(*userCookieSecret, *userSessionName),
		UserSessionAuth(),
		CSRFMiddleware(*userSessionSecret, *userSessionKey),
		UserRendererMiddleware(),
	)

	// Admin interface
	m.Group("/app/admin", func(r martini.Router) {
		r.Get("/sign_in", controllers.AdminSignIn)
		r.NotFound(func(x render.Render) {
			x.HTML(404, "404_admin", nil)
		})
	},
		CookieStore("admin123", "nightcrawler_admin"),
		AdminSessionAuth(),
		CSRFMiddleware("admin123", "adminId"),
		AdminRendererMiddleware(),
	)

	m.Run()
}
Exemplo n.º 6
0
func main() {
	fs, err := filestore.New("s3")
	if err != nil {
		log.Fatal(err)
	}

	port := os.Getenv("PORT")
	m := martini.Classic()
	m.Map(fs)
	m.Use(martini.Static("../web/public"))
	m.Use(render.Renderer(render.Options{
		Directory: "../web/templates",
		Layout:    "layout",
	}))
	m.Get("/", func(fs *filestore.S3, r render.Render) {
		files, err := fs.List("builds")
		sort.Sort(ByTime(files))
		if err != nil {
			log.Fatal(err)
		}

		r.HTML(200, "home", files)
	})

	log.Printf("starting server at %s", port)
	err = http.ListenAndServe(":"+port, m)
	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 7
0
func (s *Server) Start() error {
	m := martini.Classic()
	m.Use(martini.Static("public"))
	m.Get("/jq", handleJQ)

	return http.ListenAndServe(":"+s.Port, m)
}
Exemplo n.º 8
0
func martiniInit() {
	m := martini.New()
	r := martini.NewRouter()

	m.Map(db)
	//m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
	//m.Use(oauth2.Github(&oauth2.Options{
	// 	ClientId:	  "64a641523f31dd5bfe4b",
	// 	ClientSecret: "4fe3fbbca262835c424ca6a80aec6c6cb4228037",
	// 	RedirectURL:  "http://localhost:2714/github_callback",
	// 	Scopes:		  []string{"user:email"},
	//}))

	//r.Get("/", index)
	r.Get("/comments/:forum/:page", GetAllCommentsResource)
	r.Post("/comment", PostCommentHandler)
	//r.Get("/github_redirect", RedirectUrl)
	//r.Get("/github_callback", func(request *http.Request) string {
	// 	request.ParseForm()
	// 	return fmt.Sprintf("%+v", request)
	//})

	m.Use(martini.Static("ui"))
	m.Action(r.Handle)

	fmt.Println("Running on port " + viper.GetString("port"))

	sio.Handle("/", m)
	//http.Handle("/", m)
	//http.ListenAndServe(":"+viper.GetString("port"), m)
}
Exemplo n.º 9
0
func main() {
	//	fmt.Println("Hello World!")
	rand.Seed(time.Now().UTC().UnixNano())
	/*	database := models.GetDB()
		database.Drop(tiedotmartini2.BAND_COL)
		database.Drop(tiedotmartini2.LOCATION_COL)
		database.Drop(tiedotmartini2.GENRE_COL)
		database.Create(tiedotmartini2.BAND_COL, 1)
		database.Create(tiedotmartini2.LOCATION_COL, 1)
		database.Create(tiedotmartini2.GENRE_COL, 1)
		col := database.Use(tiedotmartini2.BAND_COL)
		col.Index([]string{"albums", "genre_id"})
		database.Close()
	*/
	m := martini.Classic()
	m.Get("/", controllers.HomeIndex)
	m.Get("/home/index", controllers.HomeIndex)
	m.Get("/band/add", controllers.BandAdd)
	m.Post("/band/verify", controllers.BandVerify)
	m.Get("/album/index/:id", controllers.AlbumIndex)
	m.Get("/album/add/:id", controllers.AlbumAdd)
	m.Post("/album/verify/:id", controllers.AlbumVerify)
	m.Get("/home/genrelist", controllers.HomeGenreList)
	m.Get("/home/bygenre/:id", controllers.HomeByGenre)
	m.Use(martini.Static("assets"))
	m.Run()
}
Exemplo n.º 10
0
func main() {

	m := martini.Classic()

	m.Use(martini.Static("static"))
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(201, "index", nil)
	})

	// Authenticate user
	m.Post("/auth", binding.Bind(User{}), func(user User, r render.Render) {

		if user.UserId == ValidUser && user.Password == ValidPass {

			// Create JWT token
			token := jwt.New(jwt.GetSigningMethod("HS256"))
			token.Claims["userid"] = user.UserId
			// Expire in 5 mins
			token.Claims["exp"] = time.Now().Add(time.Minute * 5).Unix()
			tokenString, err := token.SignedString([]byte(SecretKey))
			if err != nil {
				r.HTML(201, "error", nil)
				return
			}

			data := map[string]string{

				"token": tokenString,
			}

			r.HTML(201, "success", data)
		} else {
			r.HTML(201, "error", nil)
		}

	})

	// Check Key is ok
	m.Get("/debug/:token", func(params martini.Params, r render.Render) string {
		token, err := jwt.Parse(params["token"], func(token *jwt.Token) ([]byte, error) {
			return []byte(SecretKey), nil
		})
		if err == nil && token.Valid {
			return "User id: " + token.Claims["userid"].(string)
		} else {
			return "Invalid"
		}
	})

	// Only accesible if authenticated
	m.Post("/secret", func() {

	})

	m.Run()
}
Exemplo n.º 11
0
func main() {
	m := martini.Classic()
	m.Get("/", func() string {
		return "Hello world!"
	})
	m.Use(auth.Basic("username", "secretpassword"))
	m.Use(martini.Static("./"))
	m.Run()
}
Exemplo n.º 12
0
func newMartini() *martini.ClassicMartini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(middleware.Logger())
	m.Use(martini.Recovery())
	m.Use(martini.Static("public"))
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &martini.ClassicMartini{m, r}
}
Exemplo n.º 13
0
/**
* Martini application configuration.
 */
func configuration(app *martini.ClassicMartini) {
	app.Use(martini.Static("public"))
	app.Use(render.Renderer(render.Options{
		Directory:  "templets",
		Layout:     "layout",
		Extensions: []string{".tmpl", ".html"},
		Charset:    "UTF-8",
		IndentJSON: true,
	}))
}
Exemplo n.º 14
0
func main() {
	m := martini.Classic()
	m.Use(martini.Static("static"))
	m.Get("/api/feed", FetchFeeds)
	m.Post("/api/feed", AddFeed)
	m.Delete("/api/feed", DeleteFeed)
	m.Post("/api/feed/read", MarkUnread)

	http.ListenAndServe(":"+os.Getenv("PORT"), m)
}
Exemplo n.º 15
0
func main() {
	m := martini.Classic()
	m.Use(martini.Static("views"))

	m.Get("/tasks", GetTasks)
	m.Post("/task", CreateTask)
	m.Get("/task/:id", FindTask, GetTask)
	m.Put("/task/:id", FindTask, UpdateTask)

	m.Run()
}
Exemplo n.º 16
0
func main() {
	m := martini.Classic()
	m.Use(func(r http.ResponseWriter) {
		r.Header().Set("Access-Control-Allow-Origin", "*")
	})
	m.Use(martini.Static("xrepo.manager/"))
	m.Post("/xRepo/index.php/AuthenticationService/Login", mockApi)
	m.Post("/xRepo/index.php/EventService/GetEventList", mockApi)
	m.Post("/xRepo/index.php/EventService/GetEventDetails", mockApi)
	log.Fatal(http.ListenAndServe(":8080", m))
}
Exemplo n.º 17
0
func NewWebServer(car Car) *WebServer {
	var ws WebServer

	ws.m = martini.Classic()
	ws.m.Handlers(martini.Static("public"))
	ws.car = car

	ws.registerHandlers()

	return &ws
}
Exemplo n.º 18
0
func main() {
	devKey = "?api_key=349258f8-e96e-45f9-a89a-249dee4c607b"
	m := martini.Classic()
	m.Use(func(r http.ResponseWriter) {
		r.Header().Set("Access-Control-Allow-Origin", "*")
	})
	m.Use(martini.Static("whosthefeeder/"))
	m.Get("/summonerNames", getSummonerNames)
	m.Post("/latestMatches", getLatestMatches)
	log.Fatal(http.ListenAndServe(":8080", m))
}
Exemplo n.º 19
0
func Start(DB *Connection, config *Config) {
	// Create a new cookie store
	store := sessions.NewCookieStore([]byte(config.SecretKey))

	m := martini.Classic()

	// It will be available to all handlers as *sessions.CookieStore
	m.Map(store)

	// It will be available to all handlers as *connection *Connection
	m.Map(DB)

	// It will be available to all handlers as *Config
	m.Map(config)

	// public folder will serve the static content
	m.Use(martini.Static("public"))

	// Tag-related routes
	m.Get("/tag/:tag/:page", AuthRequired, GetTagHandler)

	// Bookmark-related routes
	m.Get("/bookmarks/:page", AuthRequired, GetBookmarksHandler)
	m.Post("/bookmark/new", AuthRequired, NewBookmarkHandler)
	m.Post("/bookmark/update/:bookmark", AuthRequired, EditBookmarkHandler)
	m.Delete("/bookmark/delete/:bookmark", AuthRequired, DeleteBookmarkHandler)

	// Search
	m.Post("/search/:page", AuthRequired, SearchHandler)

	// User-related routes
	m.Post("/login", LoginPostHandler)
	m.Get("/logout", AuthRequired, LogoutHandler)
	m.Post("/signup", SignUpHandler)
	m.Post("/new_token", AuthRequired, RequestNewToken)

	// Test
	m.Get("/test", TestHandler)

	// Home
	m.Get("/", func(cs *sessions.CookieStore, req *http.Request, w http.ResponseWriter, connection *Connection) {
		if GetUserID(cs, req, connection) == "" {
			LoginHandler(req, w)
		}
	}, IndexHandler)

	csrfHandler := nosurf.New(m)
	csrfHandler.SetFailureHandler(http.HandlerFunc(CsrfFailHandler))

	http.ListenAndServe(config.Port, csrfHandler)
}
Exemplo n.º 20
0
Arquivo: main.go Projeto: valm0unt/me
func main() {
	m := martini.Classic()

	m.Get("/", app.GetThoughts)
	m.Get("/about", app.GetAbout)
	m.Get("/thoughts", app.GetThoughts)
	m.Get("/thoughts/:artile_name", app.GetArticle)
	m.Use(martini.Static(os.Getenv("GOPATH") + "/src/github.com/bom-d-van/me/thoughts"))

	println("Serving Me on Port", configs.Port)
	for {
		http.ListenAndServe(configs.Port, m)
	}
}
Exemplo n.º 21
0
func main() {
	m := martini.Classic()
	m.Use(render.Renderer())
	m.Use(martini.Static("scripts"))

	collection := monitor.New()

	collection.AddMonitor(&monitor.Monitor{Name: "Motherbrain", HttpAddress: "10.10.8.81:80", MonitorType: "web"})
	collection.AddMonitor(&monitor.Monitor{Name: "AQR Web 1", HttpAddress: "10.10.11.144:80", MonitorType: "web", ActiveRedirect: true})
	collection.AddMonitor(&monitor.Monitor{Name: "AQR Web 2", HttpAddress: "10.10.9.8:80", MonitorType: "web"})
	collection.AddMonitor(&monitor.Monitor{Name: "AQR Web 3", HttpAddress: "10.10.9.247:80", MonitorType: "web"})
	collection.AddMonitor(&monitor.Monitor{Name: "AQR Web 4", HttpAddress: "10.10.8.32:80", MonitorType: "web"})

	go collection.Run()

	m.Get("/", func(w http.ResponseWriter, r *http.Request) {
		if redirectAddress, err := collection.FetchActiveRedirect(); err == nil {
			http.Redirect(w, r, "http://"+redirectAddress, http.StatusMovedPermanently)
		}

	})

	m.Get("/dashboard", func(r render.Render) {
		r.HTML(200, "master", nil)
	})

	m.Get("/api/getMonitors", func() string {
		data, _ := json.Marshal(collection)
		return string(data)
	})

	m.Post("/api/addMonitor", binding.Form(monitor.Monitor{}), func(monitor monitor.Monitor) {
		collection.AddMonitor(&monitor)
	})

	m.Post("/api/removeMonitor", func(w http.ResponseWriter, r *http.Request) {
		name := r.FormValue("removeName")
		collection.Remove(name)
		http.Redirect(w, r, "/dashboard", http.StatusFound)
	})

	m.Post("/api/activateMonitor", func(w http.ResponseWriter, r *http.Request) {
		name := r.FormValue("activateName")
		collection.ActivateMonitor(name)
		http.Redirect(w, r, "/dashboard", http.StatusFound)
	})

	m.Run()
}
func main() {
	m := martini.Classic()

	m.Use(martini.Static("app"))

	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", nil)
	})

	m.Post("/upload", upload)

	m.Run()
}
Exemplo n.º 23
0
func NewMartiniServer() *martini.ClassicMartini {
	conf := GetConfig()

	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	m.Use(martini.Static("root"))
	m.Map(conf.Servers)

	for _, t := range conf.Templates {
		setupTemplate(m, t)
	}

	return m
}
func init() {
	m = martini.New()
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("X-Frame-Options", "DENY")
		w.Header().Set("Strict-Transport-Security", "max-age=60000")
	})
	m.Use(martini.Static("public"))
	m.Use(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
	})
	r := martini.NewRouter()
	r.Put("/candidates", mainHandler)
	m.Action(r.Handle)
	http.Handle("/", m)
}
Exemplo n.º 25
0
func main() {
	fmt.Printf("Using config %s\n", conf.Path)
	fmt.Printf("Using models:\n")
	for _, m := range db.Models {
		t := reflect.TypeOf(m)
		fmt.Printf("    %s\n", fmt.Sprintf("%s", t)[1:])
	}

	// Establish session with mongodb
	db.Connect(conf.Config.DbHostString(), conf.Config.DbName)
	db.RegisterAllIndexes()

	m := martini.Classic()

	m.Use(martini.Static("static"))
	m.Use(DB(conf.Config.DbName))

	m.Use(render.Renderer(render.Options{
		Directory: "templates",
		Layout:    "layout", // Specify a layout template
		Charset:   "UTF-8",  // Sets encoding for json and html content-types. Default is "UTF-8".
		//IndentJSON: true, // Output human readable JSON
	}))

	m.NotFound(NotFoundHandler)
	m.Get("/", HomeHandler)
	m.Get("/events", event.EventListHandler)
	m.Get("/events/past", event.EventPastHandler)
	m.Get("/events/next", event.EventNextHandler)
	m.Get("/organise", event.OrganiseHandler)
	m.Get("/event/add", event.EventAddHandler)

	// Facebook related features
	// one-off link that allows event owner to grab group-specific events set with group-only perms
	m.Get("/facebook/login", FacebookLoginHandler)
	m.Get("/channel.html", FacebookChannelHandler)
	m.Get("/events/grab", event.EventGrabHandler)
	m.Post("/events/import", event.EventImportHandler)

	m.Post("/events/register", binding.Bind(event.Attendee{}), event.RegisterEventAttendeeHandler)

	m.Get("/event/:eid", event.ShowEventAttendees)

	m.Run()

}
Exemplo n.º 26
0
func main() {
	m := martini.Classic()
	unescapeFuncMap := template.FuncMap{"unescape": utils.Unescape}
	m.Use(render.Renderer(render.Options{
		Directory:  "html",
		Layout:     "layout",
		Funcs:      []template.FuncMap{unescapeFuncMap},
		Extensions: []string{".html"},
		Charset:    "utf-8",
	}))
	options := martini.StaticOptions{Prefix: "resources"}
	m.Use(martini.Static("resources", options))
	m.Get("/pdfte", indexHandler)
	m.Post("/pdfte", extractHandler)
	m.Get("/pdfte/download/:id", downloadHandler)
	m.Get("/pdfte/example", exampleHandler)
	m.Run()
}
Exemplo n.º 27
0
Arquivo: main.go Projeto: border/notes
func main() {
	m := martini.Classic()

	m.Use(martini.Static("public"))

	// render html templates from templates directory
	//m.Use(render.Renderer())
	m.Use(render.Renderer(render.Options{
		Directory:  "templates",                        // specify what path to load the templates from
		Extensions: []string{".tpl", ".tmpl", ".html"}, // Specify extensions to load for templates
	}))

	m.Get("/", RegIndex)
	m.Post("/signup", RegSignup)
	m.Get("/config", RegConfig)
	m.Post("/config", RegConfig)

	m.Get("/hello", func(r render.Render, req *http.Request) {
		reqParams := req.URL.Query()
		var str string = ""
		log.Printf("req: %v", reqParams)
		for k, _ := range reqParams {
			str += k + " "
		}
		r.HTML(200, "hello", str)
	})

	m.Get("/name/:name", func(params martini.Params, r render.Render, req *http.Request) {
		reqParams := req.URL.Query()
		log.Printf("params: %v", params)
		log.Printf("req: %v", reqParams)
		r.HTML(200, "hello", params["name"])
	})

	/*
		m.Get("/hello/**", func(params martini.Params, r render.Render) {
			r.HTML(200, "hello", params["_1"])
		})
	*/

	//m.Run()
	log.Println("Listen on", ListenPort)
	http.ListenAndServe(ListenPort, m)
}
Exemplo n.º 28
0
func main() {
	fmt.Println("Listening on port :3000")

	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}

	db := session.DB("blog")

	m := martini.Classic()

	unescapeFuncMap := template.FuncMap{"unescape": unescape}

	m.Map(db)

	m.Use(s.Middleware)

	m.Use(render.Renderer(render.Options{
		Directory:  "templates",                         // Specify what path to load the templates from.
		Layout:     "layout",                            // Specify a layout template. Layouts can call {{ yield }} to render the current template.
		Extensions: []string{".tmpl", ".html"},          // Specify extensions to load for templates.
		Funcs:      []template.FuncMap{unescapeFuncMap}, // Specify helper function maps for templates to access.
		Charset:    "UTF-8",                             // Sets encoding for json and html content-types. Default is "UTF-8".
		IndentJSON: true,                                // Output human readable JSON
	}))

	staticOptions := martini.StaticOptions{Prefix: "assets"}
	m.Use(martini.Static("assets", staticOptions))

	m.Get("/", routes.IndexHandler)
	m.Get("/login", routes.GetLoginHandler)
	m.Get("/logout", routes.LogoutHandler)
	m.Post("/login", routes.PostLoginHandler)
	m.Get("/write", routes.WriteHandler)
	m.Get("/edit/:id", routes.EditHandler)
	m.Get("/view/:id", routes.ViewHandler)
	m.Get("/delete/:id", routes.DeleteHandler)
	m.Post("/SavePost", routes.SavePostHandler)
	m.Post("/gethtml", routes.GetHtmlHandler)

	m.Run()
}
Exemplo n.º 29
0
func main() {
	m := martini.Classic()

	postsController := new(controllers.PostsController)

	m.Use(render.Renderer(render.Options{
		Directory: "templates",
		Layout:    "layout",
	}))
	m.Use(PopulateAppContext)
	m.Use(CloseDatabase)
	m.Use(martini.Static("public"))

	m.Get("/", postsController.Index)
	m.Get("/posts/new", postsController.New)
	m.Post("/posts/new", binding.Form(models.Post{}), postsController.Create)

	log.Fatal(http.ListenAndServe("192.168.1.60:8080", m))
}
Exemplo n.º 30
0
func main() {
	_, err := flags.ParseArgs(&opts, os.Args)
	PanicIf(err)

	m := martini.Classic()
	m.Map(SetupDB())

	// Serve static files from "static" directory.
	StaticOptions := martini.StaticOptions{Prefix: "static"}
	m.Use(martini.Static(opts.StaticDir, StaticOptions))

	// Render html templates from "templates" directory.
	m.Use(render.Renderer(render.Options{Directory: opts.TemplatesDir}))

	m.Get("/", IndexHandler)
	m.Post("/subscribe/", binding.Form(Subscription{}), SubscribeHandler)

	m.Run()
}