Exemplo n.º 1
0
func main() {
	githubAccessToken := os.Getenv("GITHUB_ACCESS_TOKEN")
	if githubAccessToken == "" {
		fmt.Println("Create new tokens via https://github.com/settings/applications 'Personal Access Tokens' section")
		log.Fatalln("Please set environment variable $GITHUB_ACCESS_TOKEN")
	}
	t := &oauth.Transport{
		Token: &oauth.Token{AccessToken: githubAccessToken},
	}

	client = github.NewClient(t.Client())

	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/github/:org/:repo/pull/(?P<pull_id>\\d+).(?P<badge_type>(svg|png|json))", prBadgeHandler)
	m.Get("/github/:org/:repo/pull/:pull_id", prRedirectHandler)
	m.Get("/github/:org/:repo/issues/(?P<issue_id>\\d+).(?P<badge_type>(svg|png|json))", issueBadgeHandler)
	m.Get("/github/:org/:repo/issues/:issue_id", issueRedirectHandler)

	// Redirect to blog post for any other route (e.g. root route) until some human website implemented
	m.NotFound(func(render render.Render) {
		render.Redirect("https://blog.starkandwayne.com/2014/12/30/live-github-pr-status-in-your-blogs-docs/")
	})
	m.Run()
}
Exemplo n.º 2
0
func main() {

	siteMap = NewDefaultSiteMap()

	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "master",
	}))

	m.Get("/favicon.ico", func() {})
	m.Get("/:lang/contact", contactHandler)
	m.Get("/:lang/search", searchHandler)
	// handler for atom and rss feeds.
	m.Get("/:lang/feed/:feed/**.xml", feedHandler)

	m.Get("/", markdownHandler)
	m.Get("/:lang", markdownHandler)
	m.Get("/:lang/**", markdownHandler)

	m.Post("", siteWebhookHandler)

	go RebuildSearchIndex(siteMap.GetPages())
	// RunEditor(siteMap, "3001")
	m.Run()
}
Exemplo n.º 3
0
func InitServer() *martini.ClassicMartini {
	envFileName := martini.Env + ".env"
	err := godotenv.Load(envFileName)
	if err != nil {
		log.Fatalf("Error loading: %s", envFileName)
	}

	m := martini.Classic()
	m.Map(db.Connect())

	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", func(r render.Render) {
		r.HTML(200, "home", "")
	})
	m.Get("/api/projects", controllers.ProjectIndex)
	m.Get("/api/projects/new", controllers.ProjectNew)
	m.Get("/api/projects/:id", controllers.ProjectGet)
	m.Post("/api/projects", binding.Bind(models.Project{}), controllers.ProjectCreate)
	m.Put("/api/projects/:id", binding.Bind(models.Project{}), controllers.ProjectUpdate)
	m.Delete("/api/projects/:id", controllers.ProjectDelete)

	return m
}
Exemplo n.º 4
0
func main() {
	fmt.Println("fmt included for debug. remove for production.")
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Directory:  "template",
		Layout:     "layout",
		Extensions: []string{".html"},
	}))

	m.Get("/", func(r render.Render) {
		random_string := RandomString(10, 30)
		r.HTML(200, "main", "/d/"+random_string)
	})

	/* Main route handles incoming ** from user */
	m.Get("/d/**", func(params martini.Params, r render.Render) {
		/* Execute ruby script to parse the command */
		cmd := exec.Command("ruby", "./interpreter/parser.rb", string(params["_1"]))
		translation, _ := cmd.Output()
		data := struct {
			URL_string string
			JS_string  string
		}{
			params["_1"],
			string(translation),
		}
		r.HTML(200, "d", data)
	})

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

	// render middleware
	// https://github.com/codegangsta/martini-contrib/tree/master/render
	m.Use(render.Renderer(render.Options{
		Directory: ".",
	}))

	// This will set the Content-Type header to "text/html; charset=UTF-8"
	m.Get("/wishes", func(r render.Render) {
		r.HTML(200, "martini-02", nil)
	})

	// This will set the Content-Type header to "text/html; charset=UTF-8"
	m.Get("/text", func(r render.Render) {
		r.HTML(200, "hello", "world")
	})

	// This will set the Content-Type header to "application/json; charset=UTF-8"
	m.Get("/json", func(r render.Render) {
		r.JSON(200, map[string]interface{}{"hello": "world"})
	})

	m.Run()
}
Exemplo n.º 6
0
Arquivo: main.go Projeto: matm/gobuild
func init() {
	cfg := new(config)
	in, err := ioutil.ReadFile("config.yaml")
	if err != nil {
		log.Fatal(err)
	}
	err = goyaml.Unmarshal(in, cfg)
	if err != nil {
		log.Fatal(err)
	}

	flag.Parse()
	log.SetOutputLevel(log.Ldebug)

	if *environment == "development" {
		opts = &cfg.Development
	} else {
		opts = &cfg.Production
	}

	fmt.Println("== environment:", *environment, "==")
	utils.Dump(opts)

	conf.ACCESS_KEY = opts.AccessKey
	conf.SECRET_KEY = opts.SecretKey

	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	InitRouter()
}
Exemplo n.º 7
0
func Route(m *martini.ClassicMartini) {
	m.Use(render.Renderer())

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

	//post handlers
	Signup(m)
	Signin(m)

	m.Get("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Get("/add", func() string {
		return "Hello add!"
	})

	m.Post("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Post("/add", func() string {
		return "Hello add!"
	})
}
Exemplo n.º 8
0
func main() {
	var port int
	flag.IntVar(&port, "port", 3001, "server port")
	flag.Parse()
	fmt.Println("Port: ", port)

	endpoint := "unix:///var/run/docker.sock"
	var err error
	client, err = docker.NewClient(endpoint)
	if err != nil {
		panic(err)
	}

	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.JSON(http.StatusOK, getSystemMonitorSample())
	})

	m.Get("/:name", func(args martini.Params, r render.Render) {
		name := args["name"]
		sample, err := getContainerMonitorSample(name)
		if err == nil {
			r.JSON(http.StatusOK, sample)
		} else {
			r.JSON(http.StatusBadRequest, err)
		}
	})

	http.Handle("/", m)
	http.ListenAndServe(":"+strconv.Itoa(port), nil)
}
Exemplo n.º 9
0
func main() {

	m := martini.Classic()
	// specify the layout to use when rendering HTML
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	// use the Mongo middleware
	m.Use(DB())

	// list of all cribs
	m.Get("/", func(r render.Render, db *mgo.Database) {
		r.HTML(200, "list", All(db))
	})

	/*
	   create a new crib the form submission. Contains some martini magic. The call
	   to binding.Form(Crib{}) parses out form data when the request comes in.
	   It binds the data to the struct, maps it to the request context  and
	   injects into our next handler function to insert into Mongodb.
	*/
	m.Post("/", binding.Form(Crib{}), func(crib Crib, r render.Render, db *mgo.Database) {
		db.C("cribs").Insert(crib)
		r.HTML(200, "list", All(db))
	})

	// display the crib for a specific user
	m.Get("/:handle", func(params martini.Params, r render.Render, db *mgo.Database) {
		r.HTML(200, "display", Fetch(db, params["handle"]))
	})

	http.ListenAndServe(":8080", m)

}
Exemplo n.º 10
0
func main() {
	m := martini.Classic()
	dbMap := initDb()
	m.Map(dbMap)
	store := sessions.NewCookieStore([]byte("nonotestetstsst"))
	m.Use(sessions.Sessions("gogonki", store))
	m.Use(render.Renderer())
	m.Get("/", Index)

	m.Get("/coords", Coords)
	m.Get("/move/:x/:y", Move) // ToDo: make this post request
	m.Get("/state", GetState)
	m.Get("/profile", ShowProfile)
	m.Get("/login", LoginForm)
	m.Post("/login", Login)
	m.Get("/logout", Logout)
	m.Post("/create", binding.Bind(User{}), CreateUser)
	m.Get("/signup", SignupForm)
	m.Post("/signup", Signup)
	m.Post("/create-room", CreateRoom)
	m.Post("/list-rooms", ListRooms)

	//m.Use(Auth)
	m.Run()
}
Exemplo n.º 11
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.º 12
0
func main() {
	m := martini.Classic()

	m.Use(render.Renderer(render.Options{
		Directory:  "templates",
		Layout:     "layout",
		Extensions: []string{".html"},
		Delims:     render.Delims{"{[{", "}]}"},
		Funcs: []template.FuncMap{
			{
				"formatTime": func(args ...interface{}) string {
					t1 := time.Unix(args[0].(int64), 0)
					return t1.Format(time.Stamp)
				},
				"unescaped": func(args ...interface{}) template.HTML {
					return template.HTML(args[0].(string))
				},
			},
		},
	}))

	newmap := map[string]interface{}{}

	m.Use(martini.Static("assets"))
	m.Get("/", func(args martini.Params, r render.Render) string {
		r.HTML(200, "index", newmap)
		return ""
	})

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

	m.Use(render.Renderer(render.Options{
		Directory: "templates",
		Layout:    "layout",
		Funcs: []template.FuncMap{
			{
				"formatTime": func(args ...interface{}) string {
					t1 := time.Unix(args[0].(int64), 0)
					return t1.Format(time.Stamp)
				},
				"unescaped": func(args ...interface{}) template.HTML {
					return template.HTML(args[0].(string))
				},
			},
		},
	}))

	m.Get("/", func(r render.Render) {
		d := map[string]interface{}{"title": "Main", "message": "SUCCESS!"}
		r.HTML(200, "main", d)
	})

	m.Run()
}
Exemplo n.º 14
0
func main() {
	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "Welcome home."
		data["title"] = "Home"
		r.HTML(200, "main", data)
	})
	m.Get("/about", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "About us."
		data["title"] = "About"
		r.HTML(200, "main", data)
	})
	m.Get("/contact", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "Contact us."
		data["title"] = "Contact"
		r.HTML(200, "main", data)
	})

	m.Run()
}
Exemplo n.º 15
0
func main() {
	//go ServeWebsocket()
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	m.Use(martini.Static("assets"))

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "index")
	})
	// api group
	m.Group("/api", func(r martini.Router) {
		r.Post("/log", binding.Bind(Log{}), NewLog)
		r.Get("/log/:appname", func(args martini.Params, r render.Render) {
			logs, err := GetLogForApp(args["appname"])
			if err != nil {
				r.JSON(200, map[string]interface{}{})
			}
			r.JSON(200, logs)
		})
	})

	//websocket
	m.Get("/sock/:appname", socketHandler)
	m.Run()
}
Exemplo n.º 16
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.º 17
0
func Request(method string, route string, handler martini.Handler) {
	m := martini.Classic()
	m.Get(route, handler)
	m.Use(render.Renderer())
	request, _ := http.NewRequest(method, route, nil)
	response = httptest.NewRecorder()
	m.ServeHTTP(response, request)
}
Exemplo n.º 18
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.º 19
0
func main() {
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", GetRoot)
	m.Run()
}
Exemplo n.º 20
0
func main() {
	defer session.Close()

	// HTTP init & routes
	m := martini.Classic()
	m.Use(render.Renderer())
	m.Get("/", HelloWorld)
	m.Get("/v1/creatives/:id", GetCreativeById)
	m.Run()
}
Exemplo n.º 21
0
func main() {
	m := martini.Classic()
	m.Use(render.Renderer())

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

	m.Run()
}
Exemplo n.º 22
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.º 23
0
Arquivo: server.go Projeto: judg3/blog
func main() {
	m := martini.Classic()

	m.Use(render.Renderer())

	m.Get("/post/:id", controllers.GetPost)
	m.Get("/posts", controllers.ListPosts)
	m.Post("/post", binding.Form(forms.Post{}), controllers.CreatePost)

	m.Run()
}
Exemplo n.º 24
0
func Main() {
	// Read in any environment variables we care about
	readEnv()

	var err error

	AWS_AUTH, err = aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	// Open database connection
	db, err := models.OpenDB("postgres", IRLMOJI_DBURI)
	if err != nil {
		log.Fatalf("Error opening database connection: %v", err.Error())
		return
	}
	if err = createAllTables(db); err != nil {
		log.Fatalf("Error creating database table: %v", err.Error())
	}

	// Start setting up martini
	m := martini.Classic()

	// Set up the middleware
	m.Use(gzip.All())
	m.Use(render.Renderer())
	m.Use(BackchannelAuth(IRLMOJI_API_BASIC_USER))

	// Inject the database
	m.Map(db)

	// Map the URL routes
	m.Get("/", HandleIndex)

	// User routes (see handlers_user.go)
	m.Get("/api/v1/users/current.json", HandleGetCurrentUser)
	m.Post("/api/v1/users/twitter.json", binding.Json(models.UserForm{}), HandleCreateUserByTwitter)

	// IRLMoji routes (see handlers_irlmoji.go)
	m.Get("/api/v1/timelines/home.json", binding.Form(Limit{}), HandleGetHomeTimeline)
	m.Get("/api/v1/timelines/user/username/:username.json", binding.Form(Limit{}), HandleGetUserTimeline)
	m.Get("/api/v1/timelines/emoji/:emoji.json", binding.Form(Limit{}), HandleGetEmojiTimeline)
	m.Get("/api/v1/irlmoji/id/:irlmojiId.json", binding.Form(Limit{}), HandleGetIRLMoji)
	m.Delete("/api/v1/irlmoji/id/:irlmojiId.json", HandleDeleteIRLMoji)
	m.Post("/api/v1/irlmoji.json", binding.Json(models.IRLMoji{}), HandleCreateIRLMoji)
	m.Post("/api/v1/irlmoji/id/:irlmojiId/heart.json", binding.Json(models.Heart{}), HandleToggleHeart)

	m.Post("/upload", HandleUpload)

	m.NotFound(HandleNotFound)

	m.Run()
}
Exemplo n.º 25
0
func main() {
	m := martini.Classic()
	renderOptions := render.Options{
		Directory:  "public/templates",
		Extensions: []string{".tmpl", ".html"},
	}
	m.Use(render.Renderer(renderOptions))
	m.Get("/tutorials/:id", renderTutorial)
	m.Get("/tutorials", renderTutorialIndex)
	m.Run()
}
Exemplo n.º 26
0
func main() {
	db, err := sql.Open("mysql", "root:abc123@tcp(127.0.0.1:3306)/martini_api")

	if err != nil {
		fmt.Println(err)
	}
	defer db.Close()

	m := martini.Classic()
	m.Use(render.Renderer())

	m.Use(func(res http.ResponseWriter, req *http.Request, r render.Render) {
		api_key := ""
		api_key = req.URL.Query().Get("key")
		if api_key == "" {
			r.JSON(404, map[string]interface{}{"status": "Fail", "error_message": "Need api key"})
		} else {
			// r.JSON(200, map[string]interface{}{"key": api_key})
			current_company, company_id := GetCompany(db, api_key)
			if company_id < 0 {
				r.JSON(404, map[string]interface{}{"status": "Fail", "error_message": "Bad api key"})
			} else {
				m.Map(current_company)
			}
		}
	})

	m.Get("/", func() string {
		return "Hello world!"
	})

	m.Get("/projects", func(current_company Company, r render.Render) {
		projects := GetProjects(db, current_company.Id)
		r.JSON(200, map[string]interface{}{"status": "Success", "data": projects})
	})

	m.Get("/projects/:id", func(current_company Company, params martini.Params, r render.Render) {
		paramId, err := strconv.Atoi(params["id"])
		if err != nil {
			r.JSON(404, map[string]interface{}{"status": "Fail", "error_message": err.Error()})
			return
		}
		project, id := GetProject(db, current_company.Id, paramId)
		if id > 0 {
			r.JSON(200, map[string]interface{}{"status": "Success", "data": project})
		} else {
			r.JSON(404, map[string]interface{}{"status": "Fail", "error_message": "Project not found"})
		}
	})

	// m.Run()
	http.ListenAndServe(":8080", m)
}
Exemplo n.º 27
0
func init() {
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	AccountHandlers(m)
	AdministationHandlers(m)

	m.Get("/", indexHandler)

	http.Handle("/", m)
}
Exemplo n.º 28
0
func main() {
	fmt.Printf("Hello world!")
	db := DB()

	m := martini.Classic()
	m.Use(db)
	m.Use(render.Renderer())

	m.Get("/", Root)
	m.Get("/json", Json)

	m.Run()
}
Exemplo n.º 29
0
func main() {
	store := sessions.NewCookieStore([]byte("secret123"))
	dbmap = initDb()

	m := martini.Classic()
	m.Use(render.Renderer())
	m.Use(sessions.Sessions("my_session", store))
	m.Use(sessionauth.SessionUser(GenerateAnonymousUser))
	sessionauth.RedirectUrl = "/new-login"
	sessionauth.RedirectParam = "new-next"

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

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

	m.Post("/new-login", binding.Bind(MyUserModel{}), func(session sessions.Session, postedUser MyUserModel, r render.Render, req *http.Request) {
		// You should verify credentials against a database or some other mechanism at this point.
		// Then you can authenticate this session.
		user := MyUserModel{}
		err := dbmap.SelectOne(&user, "SELECT * FROM users WHERE username = $1 and password = $2", postedUser.Username, postedUser.Password)
		if err != nil {
			r.Redirect(sessionauth.RedirectUrl)
			return
		} else {
			err := sessionauth.AuthenticateSession(session, &user)
			if err != nil {
				r.JSON(500, err)
			}

			params := req.URL.Query()
			redirect := params.Get(sessionauth.RedirectParam)
			r.Redirect(redirect)
			return
		}
	})

	m.Get("/private", sessionauth.LoginRequired, func(r render.Render, user sessionauth.User) {
		r.HTML(200, "private", user.(*MyUserModel))
	})

	m.Get("/logout", sessionauth.LoginRequired, func(session sessions.Session, user sessionauth.User, r render.Render) {
		sessionauth.Logout(session, user)
		r.Redirect("/")
	})

	m.Run()
}
func main() {
	m := martini.Classic()
	m.Use(Mongo())
	// add middle ware here for rendering the html
	m.Use(render.Renderer())

	m.Get("/attributes/:resource", getAttributes)
	m.Post("/attributes/:resource", binding.Json(attribute{}), addAttribute)

	service := utils.ServiceDescription{"attributes", "http://localhost:3000", "Service that manages the attributes available for each resource type"}
	fmt.Println(config.RegisterService(service))

	m.Run()
}